-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[GISel] Fix ShuffleVector assert #139769
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
[GISel] Fix ShuffleVector assert #139769
Conversation
f98edcf to
1704d82
Compare
|
@llvm/pr-subscribers-llvm-globalisel @llvm/pr-subscribers-backend-amdgpu Author: Alan Li (lialan) ChangesFixes issue: #139752 When G_SHUFFLE_VECTOR has only 1 element then it is possible the vector is decayed into a scalar. Full diff: https://github.com/llvm/llvm-project/pull/139769.diff 2 Files Affected:
diff --git a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
index 5191360c7718a..3abed4d062bfa 100644
--- a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
@@ -420,8 +420,12 @@ void CombinerHelper::applyCombineShuffleToBuildVector(MachineInstr &MI) const {
else
Extracts.push_back(Unmerge2.getReg(Val - Width));
}
-
- Builder.buildBuildVector(MI.getOperand(0).getReg(), Extracts);
+ assert(Extracts.size() > 0 && "Expected at least one element in the shuffle");
+ if (Extracts.size() == 1) {
+ Builder.buildCopy(MI.getOperand(0).getReg(), Extracts[0]);
+ } else {
+ Builder.buildBuildVector(MI.getOperand(0).getReg(), Extracts);
+ }
MI.eraseFromParent();
}
diff --git a/llvm/test/CodeGen/AMDGPU/GlobalISel/prelegalizer-combiner-shuffle.mir b/llvm/test/CodeGen/AMDGPU/GlobalISel/prelegalizer-combiner-shuffle.mir
index bba608cceee19..e500cfe085110 100644
--- a/llvm/test/CodeGen/AMDGPU/GlobalISel/prelegalizer-combiner-shuffle.mir
+++ b/llvm/test/CodeGen/AMDGPU/GlobalISel/prelegalizer-combiner-shuffle.mir
@@ -135,3 +135,27 @@ body: |
SI_RETURN
...
+
+---
+name: shuffle_vector_to_copy
+tracksRegLiveness: true
+body: |
+ bb.0:
+ liveins: $vgpr0, $vgpr1
+ ; CHECK-LABEL: name: shuffle_vector_to_copy
+ ; CHECK: liveins: $vgpr0, $vgpr1
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(p3) = COPY $vgpr0
+ ; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(p3) = COPY $vgpr1
+ ; CHECK-NEXT: [[LOAD:%[0-9]+]]:_(<8 x s16>) = G_LOAD [[COPY]](p3) :: (load (<8 x s16>), align 8, addrspace 3)
+ ; CHECK-NEXT: [[UV:%[0-9]+]]:_(s16), [[UV1:%[0-9]+]]:_(s16), [[UV2:%[0-9]+]]:_(s16), [[UV3:%[0-9]+]]:_(s16), [[UV4:%[0-9]+]]:_(s16), [[UV5:%[0-9]+]]:_(s16), [[UV6:%[0-9]+]]:_(s16), [[UV7:%[0-9]+]]:_(s16) = G_UNMERGE_VALUES [[LOAD]](<8 x s16>)
+ ; CHECK-NEXT: G_STORE [[UV4]](s16), [[COPY1]](p3) :: (store (s16), addrspace 3)
+ ; CHECK-NEXT: SI_RETURN
+ %0:_(p3) = COPY $vgpr0
+ %1:_(p3) = COPY $vgpr1
+ %12:_(<8 x s16>) = G_IMPLICIT_DEF
+ %10:_(<8 x s16>) = G_LOAD %0(p3) :: (load (<8 x s16>), align 8, addrspace 3)
+ %11:_(s16) = G_SHUFFLE_VECTOR %10(<8 x s16>), %12, shufflemask(4)
+ G_STORE %11(s16), %1(p3) :: (store (s16), addrspace 3)
+ SI_RETURN
+...
|
arsenm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should also include end to end IR test
llvm/test/CodeGen/AMDGPU/GlobalISel/prelegalizer-combiner-shuffle.mir
Outdated
Show resolved
Hide resolved
| %1:_(p3) = COPY $vgpr1 | ||
| %12:_(<8 x s16>) = G_IMPLICIT_DEF | ||
| %10:_(<8 x s16>) = G_LOAD %0(p3) :: (load (<8 x s16>), align 8, addrspace 3) | ||
| %11:_(s16) = G_SHUFFLE_VECTOR %10(<8 x s16>), %12, shufflemask(4) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we even permit this in the MIR verifier? What produced this shuffle?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is actually emitted by this GIsel rule: combine_shuffle_disjoint_mask.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that should probably directly turn this into an extract element
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if (Extracts.size() == 1) { | |
| Builder.buildCopy(MI.getOperand(0).getReg(), Extracts[0]); | |
| } else { | |
| Builder.buildBuildVector(MI.getOperand(0).getReg(), Extracts); | |
| } | |
| if (Extracts.size() == 1) | |
| Builder.buildCopy(MI.getOperand(0).getReg(), Extracts[0]); | |
| else | |
| Builder.buildBuildVector(MI.getOperand(0).getReg(), Extracts); |
krzysz00
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems reasonable to me, though I can't definitively say this is fine
Fixes issue: llvm#139752 When G_SHUFFLE_VECTOR has only 1 element then it is possible the vector is decayed into a scalar.
3ed3648 to
3fbc4e5
Compare
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/88/builds/11852 Here is the relevant piece of the build log for the reference |
Fixes issue: #139752
When G_SHUFFLE_VECTOR has only 1 element then it is possible the vector is decayed into a scalar.