microsoft / microsoft/DirectXShaderCompiler
Precise vectors in 6.9+ are not treated as native
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 3.7k
- Forks
- 900
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 44
Description
Description
In a couple ways, vectors marked precise directly or indirectly are not treated as native vectors in 6.9.
- The dx.attribute.precise() temporary function isn't generated with a native vector overload and instead extracts each scalar element and calls on them individually
- More impactfully, when dxil-cond-mem2reg tries to scalarize the precise vectors because it needs to keep them as allocas a little longer to retain their precise indications, if a single element is operated on, there will be a GEP instruction that the code doesn't expect
Steps to Reproduce
Create a local or output vector with the precise qualifier and perform an operation on a single element of it: https://godbolt.org/z/f96jebPW7
Actual Behavior
The first issue is invisible to the output, but viewing the code after dx.attribute.precise() is introduced by scalarrepl-param-hlsl or similar and before the call is eliminated, there are potentially a long list of extractions and scalar calls to the function that could impact compile performance for long vectors.
The second actually results in a crash since it triggers an llvm_unreachable when the GEP is encountered as it is neither a Load nor a Store
Environment
- DXC version 1.9.0.5280
- Host Operating System: MacOs/Windows
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the precise-vector reproducer at https://godbolt.org/z/f96jebPW and inspect lib/Transforms/Scalar/DxilConditionalMem2Reg.cpp around the reported llvm_unreachable. Trace how scalarrepl-param-hlsl introduces dx.attribute.precise() and how precise vector element operations are handled. Done means native vector handling avoids unnecessary scalar calls and the GEP case no longer crashes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100