[DirectX] swizzle on buffer load causes assertion in directx backend.
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
I just came across a bug in the DXIL backend. When assertions are enabled, the follow sample fails (https://godbolt.org/z/v3G51ccPG):
```hlsl
// t.hlsl
Buffer X : register(t0);
RWStructuredBuffer Out : register(u1);
[numthreads(1,1,1)]
void main() {
int Result;
Result = X.Load(0).x;
Out[0] = Result;
}
```
It seems to be related to doing a swizzle in the vector returned from the buffer load.
The compile command is:
```
clang-dxc t.hlsl -T cs_6_8
```
The stack trace is:
```
clang: warning: argument unused during compilation: '-Qembed_debug' [-Wunused-command-line-argument]
clang: /root/llvm-project/llvm/lib/IR/Value.cpp:522: void llvm::Value::doRAUW(llvm::Value*, llvm::Value::ReplaceMetadataUses): Assertion `New->getType() == getType() && "replaceAllUses of value with new value of different type!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0. Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang --driver-mode=dxc -Zi -Qembed_debug -Fc /app/output.s -fcolor-diagnostics -fno-crash-diagnostics -T cs_6_8
1. parser at end of file
2. Code generation
3. Running pass 'Function Pass Manager' on module ''.
4. Running pass 'DXIL Resource Access' on function '@main'
#0 0x00000000044cee28 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x44cee28)
#1 0x00000000044cbc54 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x44cbc54)
#2 0x00000000044cc274 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x44cc274)
#3 0x000000000440a3d8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#4 0x000078b2cc042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#5 0x000078b2cc0969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#6 0x000078b2cc042476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#7 0x000078b2cc0287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#8 0x000078b2cc02871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#9 0x000078b2cc039e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#10 0x0000000003e2f6c2 (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3e2f6c2)
#11 0x000000000312be81 replaceAccess(llvm::IntrinsicInst*, llvm::dxil::ResourceTypeInfo&) DXILResourceAccess.cpp:0:0
#12 0x000000000312ddde transformResourcePointers(llvm::Function&, llvm::DXILResourceTypeMap&) DXILResourceAccess.cpp:0:0
#13 0x000000000313229b (anonymous namespace)::DXILResourceAccessLegacy::runOnFunction(llvm::Function&) DXILResourceAccess.cpp:0:0
#14 0x0000000003da8f76 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3da8f76)
...
clang: error: clang frontend command failed due to signal (use -v to see invocation)
Compiler returned: 134
```
Contributor guide
Research direction
Reproduce the failure with clang-dxc t.hlsl -T cs_6_8 using the Godbolt sample, then inspect the DXIL Resource Access pass and its replaceAccess path shown in DXILResourceAccess.cpp. The fix is complete when the swizzled buffer load compiles without the Value::doRAUW assertion and the sample's output assignment remains valid.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100