| Issue |
174656
|
| Summary |
[DirectX] DXILResourceAccess extracts incorrect value when loading the 2nd element of a 2-element vector located in the latter half of a cbuffer row
|
| Labels |
backend:DirectX
|
| Assignees |
|
| Reporter |
Icohedron
|
When loading the second component of a 2-element vector of a 4-byte data type, and the 2-element vector is located on the latter half of a 16-byte constant buffer row, DXILResourceAccess extracts the wrong element from the constant buffer row.
Reproduction: https://hlsl.godbolt.org/z/6j5559of6
```hlsl
cbuffer Parameters {
int A;
int B;
int2 V;
};
RWStructuredBuffer<int> Output;
[numthreads(1, 1, 1)]
void CSMain() {
Output[0] = V.y;
}
```
Incorrect behavior: Clang loads the value of `B` instead of `V.y`:
```llvm
%CBuffer.Parameters = type { { i32, i32, <2 x i32> } }
%dx.types.Handle = type { ptr }
%dx.types.ResBind = type { i32, i32, i32, i8 }
%dx.types.ResourceProperties = type { i32, i32 }
%dx.types.CBufRet.i32 = type { i32, i32, i32, i32 }
...
%0 = call %dx.types.Handle @dx.op.createHandleFromBinding(i32 217, %dx.types.ResBind { i32 0, i32 0, i32 0, i8 2 }, i32 0, i1 false) #1, !dbg !103
%1 = call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %0, %dx.types.ResourceProperties { i32 13, i32 16 }) #1, !dbg !103
%.load1 = call %dx.types.CBufRet.i32 @dx.op.cbufferLoadLegacy.i32(i32 59, %dx.types.Handle %1, i32 0) #2, !dbg !105
%.extract = extractvalue %dx.types.CBufRet.i32 %.load1, 1, !dbg !105
```
Expected behavior, matching DXC: loads the value `V.y` as expected
```llvm
%dx.types.Handle = type { i8* }
%dx.types.ResBind = type { i32, i32, i32, i8 }
%dx.types.ResourceProperties = type { i32, i32 }
%dx.types.CBufRet.i32 = type { i32, i32, i32, i32 }
%Parameters = type { i32, i32, <2 x i32> }
...
%Parameters_cbuffer = call %dx.types.Handle @dx.op.createHandleFromBinding(i32 217, %dx.types.ResBind { i32 0, i32 0, i32 0, i8 2 }, i32 0, i1 false), !dbg !56 ; line:11 col:5 ; CreateHandleFromBinding(bind,index,nonUniformIndex)
%1 = call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %Parameters_cbuffer, %dx.types.ResourceProperties { i32 13, i32 16 }), !dbg !57 ; line:11 col:17 ; AnnotateHandle(res,props) resource: CBuffer
%2 = call %dx.types.CBufRet.i32 @dx.op.cbufferLoadLegacy.i32(i32 59, %dx.types.Handle %1, i32 0), !dbg !57 ; line:11 col:17 ; CBufferLoadLegacy(handle,regIndex)
%3 = extractvalue %dx.types.CBufRet.i32 %2, 3, !dbg !57 ; line:11 col:17
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs