Skip to content

Commit d8b0e61

Browse files
authored
[SPIR-V] Fix OpVectorShuffle operands on load (#135954)
The generated OpVectorShuffle was wrong, as the indices we pass are not to select the vector to sample from, but the position in the vector.
1 parent 4bcc414 commit d8b0e61

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

llvm/lib/Target/SPIRV/SPIRVLegalizePointerCast.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ class SPIRVLegalizePointerCast : public FunctionPass {
8181
LoadInst *NewLoad = B.CreateLoad(SourceType, Source);
8282
buildAssignType(B, SourceType, NewLoad);
8383

84-
SmallVector<int> Mask(/* Size= */ TargetType->getNumElements(),
85-
/* Value= */ 0);
84+
SmallVector<int> Mask(/* Size= */ TargetType->getNumElements());
85+
for (unsigned I = 0; I < TargetType->getNumElements(); ++I)
86+
Mask[I] = I;
8687
Value *Output = B.CreateShuffleVector(NewLoad, NewLoad, Mask);
8788
buildAssignType(B, TargetType, Output);
8889
return Output;

llvm/test/CodeGen/SPIRV/pointers/getelementptr-downcast-vector.ll

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ define internal spir_func <3 x i32> @foo(ptr addrspace(10) %a) {
1919
; partial loading of a vector: v4 -> v3.
2020
%2 = load <3 x i32>, ptr addrspace(10) %1, align 16
2121
; CHECK: %[[#load:]] = OpLoad %[[#v4]] %[[#tmp]] Aligned 16
22-
; CHECK: %[[#val:]] = OpVectorShuffle %[[#v3]] %[[#load]] %[[#load]] 0 0 0
22+
; CHECK: %[[#val:]] = OpVectorShuffle %[[#v3]] %[[#load]] %[[#load]] 0 1 2
2323

2424
ret <3 x i32> %2
2525
; CHECK: OpReturnValue %[[#val]]
@@ -33,7 +33,7 @@ define internal spir_func <3 x i32> @fooDefault(ptr %a) {
3333
; partial loading of a vector: v4 -> v3.
3434
%2 = load <3 x i32>, ptr %1, align 16
3535
; CHECK: %[[#load:]] = OpLoad %[[#v4]] %[[#tmp]] Aligned 16
36-
; CHECK: %[[#val:]] = OpVectorShuffle %[[#v3]] %[[#load]] %[[#load]] 0 0 0
36+
; CHECK: %[[#val:]] = OpVectorShuffle %[[#v3]] %[[#load]] %[[#load]] 0 1 2
3737

3838
ret <3 x i32> %2
3939
; CHECK: OpReturnValue %[[#val]]
@@ -47,7 +47,7 @@ define internal spir_func <3 x i32> @fooBounds(ptr %a) {
4747
; partial loading of a vector: v4 -> v3.
4848
%2 = load <3 x i32>, ptr %1, align 16
4949
; CHECK: %[[#load:]] = OpLoad %[[#v4]] %[[#tmp]] Aligned 16
50-
; CHECK: %[[#val:]] = OpVectorShuffle %[[#v3]] %[[#load]] %[[#load]] 0 0 0
50+
; CHECK: %[[#val:]] = OpVectorShuffle %[[#v3]] %[[#load]] %[[#load]] 0 1 2
5151

5252
ret <3 x i32> %2
5353
; CHECK: OpReturnValue %[[#val]]
@@ -61,7 +61,7 @@ define internal spir_func <2 x i32> @bar(ptr addrspace(10) %a) {
6161
; partial loading of a vector: v4 -> v2.
6262
%2 = load <2 x i32>, ptr addrspace(10) %1, align 16
6363
; CHECK: %[[#load:]] = OpLoad %[[#v4]] %[[#tmp]] Aligned 16
64-
; CHECK: %[[#val:]] = OpVectorShuffle %[[#v2]] %[[#load]] %[[#load]] 0 0
64+
; CHECK: %[[#val:]] = OpVectorShuffle %[[#v2]] %[[#load]] %[[#load]] 0 1
6565

6666
ret <2 x i32> %2
6767
; CHECK: OpReturnValue %[[#val]]

0 commit comments

Comments
 (0)