Skip to content
This repository was archived by the owner on Oct 9, 2019. It is now read-only.
This repository was archived by the owner on Oct 9, 2019. It is now read-only.

spir-v reader generates GEP into vector of i1 #231

Description

@trenouf

I may be on a slightly old and internally modified version of the spir-v reader, but I think nothing has changed in the area I'm looking at here.

The attached spir-v gets one element of a variable that is a vector of bool by doing an OpAccessChain and then an OpLoad of the single bool. It comes out of a recent version of glslang, and, as far as I can see, it is legal spir-v.

The spir-v reader converts that into the obvious way into a GEP into an alloca of a vector of i1, then a load from the GEPped pointer.

I can't find anything in the spec, but it appears that vector of i1 is not well supported in LLVM. See
https://bugs.llvm.org/show_bug.cgi?id=1784

Most code in LLVM assumes that a vector of i1 is packed, but the problem I see with the shader here is that at least GVN and alias analysis cannot cope with a GEP that is not to a byte boundary.

What I propose to try doing, as a local fix at least, is to make OpTypeBool i8 instead of i1, and add conversions when necessary after a cmp and before a select. I believe that standard LLVM optimizations will remove the extra code, the same as it does when a C compiler uses i32 for bool.

Note that we are not using the spirv-llvm tool chain for its full spir-v -> llvm -> spir-v functionality; we are only using the spir-v reader part of it as the front end of an LLVM-based shader compiler. Comments welcome from anyone using the tool chain in any way.
OpIsNan_TestDvec2_ng.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    migrateTo be moved to the new repo

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions