-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[SPIR-V] Fix OpVectorShuffle operands on load #135954
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-backend-spir-v Author: Nathan Gauër (Keenuts) ChangesThe generated OpVectorShuffle was wrong, as the indices we pass are not to select the vector to sample from, but the position in the vector. Full diff: https://github.com/llvm/llvm-project/pull/135954.diff 2 Files Affected:
diff --git a/llvm/lib/Target/SPIRV/SPIRVLegalizePointerCast.cpp b/llvm/lib/Target/SPIRV/SPIRVLegalizePointerCast.cpp
index 5ba4fbb02560d..69051132cacff 100644
--- a/llvm/lib/Target/SPIRV/SPIRVLegalizePointerCast.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVLegalizePointerCast.cpp
@@ -81,8 +81,9 @@ class SPIRVLegalizePointerCast : public FunctionPass {
LoadInst *NewLoad = B.CreateLoad(SourceType, Source);
buildAssignType(B, SourceType, NewLoad);
- SmallVector<int> Mask(/* Size= */ TargetType->getNumElements(),
- /* Value= */ 0);
+ SmallVector<int> Mask(/* Size= */ TargetType->getNumElements());
+ for (unsigned I = 0; I < TargetType->getNumElements(); ++I)
+ Mask[I] = I;
Value *Output = B.CreateShuffleVector(NewLoad, NewLoad, Mask);
buildAssignType(B, TargetType, Output);
return Output;
diff --git a/llvm/test/CodeGen/SPIRV/pointers/getelementptr-downcast-vector.ll b/llvm/test/CodeGen/SPIRV/pointers/getelementptr-downcast-vector.ll
index d4131fa8a2658..1287a512ac96d 100644
--- a/llvm/test/CodeGen/SPIRV/pointers/getelementptr-downcast-vector.ll
+++ b/llvm/test/CodeGen/SPIRV/pointers/getelementptr-downcast-vector.ll
@@ -19,7 +19,7 @@ define internal spir_func <3 x i32> @foo(ptr addrspace(10) %a) {
; partial loading of a vector: v4 -> v3.
%2 = load <3 x i32>, ptr addrspace(10) %1, align 16
; CHECK: %[[#load:]] = OpLoad %[[#v4]] %[[#tmp]] Aligned 16
-; CHECK: %[[#val:]] = OpVectorShuffle %[[#v3]] %[[#load]] %[[#load]] 0 0 0
+; CHECK: %[[#val:]] = OpVectorShuffle %[[#v3]] %[[#load]] %[[#load]] 0 1 2
ret <3 x i32> %2
; CHECK: OpReturnValue %[[#val]]
@@ -33,7 +33,7 @@ define internal spir_func <3 x i32> @fooDefault(ptr %a) {
; partial loading of a vector: v4 -> v3.
%2 = load <3 x i32>, ptr %1, align 16
; CHECK: %[[#load:]] = OpLoad %[[#v4]] %[[#tmp]] Aligned 16
-; CHECK: %[[#val:]] = OpVectorShuffle %[[#v3]] %[[#load]] %[[#load]] 0 0 0
+; CHECK: %[[#val:]] = OpVectorShuffle %[[#v3]] %[[#load]] %[[#load]] 0 1 2
ret <3 x i32> %2
; CHECK: OpReturnValue %[[#val]]
@@ -47,7 +47,7 @@ define internal spir_func <3 x i32> @fooBounds(ptr %a) {
; partial loading of a vector: v4 -> v3.
%2 = load <3 x i32>, ptr %1, align 16
; CHECK: %[[#load:]] = OpLoad %[[#v4]] %[[#tmp]] Aligned 16
-; CHECK: %[[#val:]] = OpVectorShuffle %[[#v3]] %[[#load]] %[[#load]] 0 0 0
+; CHECK: %[[#val:]] = OpVectorShuffle %[[#v3]] %[[#load]] %[[#load]] 0 1 2
ret <3 x i32> %2
; CHECK: OpReturnValue %[[#val]]
@@ -61,7 +61,7 @@ define internal spir_func <2 x i32> @bar(ptr addrspace(10) %a) {
; partial loading of a vector: v4 -> v2.
%2 = load <2 x i32>, ptr addrspace(10) %1, align 16
; CHECK: %[[#load:]] = OpLoad %[[#v4]] %[[#tmp]] Aligned 16
-; CHECK: %[[#val:]] = OpVectorShuffle %[[#v2]] %[[#load]] %[[#load]] 0 0
+; CHECK: %[[#val:]] = OpVectorShuffle %[[#v2]] %[[#load]] %[[#load]] 0 1
ret <2 x i32> %2
; CHECK: OpReturnValue %[[#val]]
|
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.
f28dc6e
to
dbeaab9
Compare
Build failure seems unrelated. We got 2 broken SPIR-V tests: smoothstep & SV_GroupIndex, those are caused by a recently added validation in Vulkan1.3 which disallow the Linkage capability. |
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.