Skip to content

Commit d0e0205

Browse files
committed
[InstCombine] Check for poison instead of undef in single shuffle fold
Otherwise we'll convert undef to poison. Alive2 was already flagging the existing test8 test as a miscompile.
1 parent a15b685 commit d0e0205

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ static bool collectSingleShuffleElements(Value *V, Value *LHS, Value *RHS,
619619
"Invalid CollectSingleShuffleElements");
620620
unsigned NumElts = cast<FixedVectorType>(V->getType())->getNumElements();
621621

622-
if (match(V, m_Undef())) {
622+
if (match(V, m_Poison())) {
623623
Mask.assign(NumElts, -1);
624624
return true;
625625
}

llvm/test/CodeGen/PowerPC/vec_shuffle.ll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ entry:
3232
%tmp15 = extractelement <16 x i8> %tmp2.upgrd.2, i32 2 ; <i8> [#uses=1]
3333
%tmp16 = extractelement <16 x i8> %tmp2.upgrd.2, i32 3 ; <i8> [#uses=1]
3434
%tmp17 = extractelement <16 x i8> %tmp2.upgrd.2, i32 4 ; <i8> [#uses=1]
35-
%tmp18 = insertelement <16 x i8> undef, i8 %tmp.upgrd.3, i32 0 ; <<16 x i8>> [#uses=1]
35+
%tmp18 = insertelement <16 x i8> poison, i8 %tmp.upgrd.3, i32 0 ; <<16 x i8>> [#uses=1]
3636
%tmp19 = insertelement <16 x i8> %tmp18, i8 %tmp3, i32 1 ; <<16 x i8>> [#uses=1]
3737
%tmp20 = insertelement <16 x i8> %tmp19, i8 %tmp4, i32 2 ; <<16 x i8>> [#uses=1]
3838
%tmp21 = insertelement <16 x i8> %tmp20, i8 %tmp5, i32 3 ; <<16 x i8>> [#uses=1]
@@ -80,7 +80,7 @@ define void @VSLDOI_xx(ptr %A, ptr %B) {
8080
%tmp15 = extractelement <16 x i8> %tmp2.upgrd.6, i32 2 ; <i8> [#uses=1]
8181
%tmp16 = extractelement <16 x i8> %tmp2.upgrd.6, i32 3 ; <i8> [#uses=1]
8282
%tmp17 = extractelement <16 x i8> %tmp2.upgrd.6, i32 4 ; <i8> [#uses=1]
83-
%tmp18 = insertelement <16 x i8> undef, i8 %tmp.upgrd.7, i32 0 ; <<16 x i8>> [#uses=1]
83+
%tmp18 = insertelement <16 x i8> poison, i8 %tmp.upgrd.7, i32 0 ; <<16 x i8>> [#uses=1]
8484
%tmp19 = insertelement <16 x i8> %tmp18, i8 %tmp3, i32 1 ; <<16 x i8>> [#uses=1]
8585
%tmp20 = insertelement <16 x i8> %tmp19, i8 %tmp4, i32 2 ; <<16 x i8>> [#uses=1]
8686
%tmp21 = insertelement <16 x i8> %tmp20, i8 %tmp5, i32 3 ; <<16 x i8>> [#uses=1]
@@ -150,7 +150,7 @@ entry:
150150
%tmp15 = extractelement <16 x i8> %tmp2, i32 14 ; <i8> [#uses=1]
151151
%tmp16 = extractelement <16 x i8> %tmp, i32 15 ; <i8> [#uses=1]
152152
%tmp17 = extractelement <16 x i8> %tmp2, i32 15 ; <i8> [#uses=1]
153-
%tmp18 = insertelement <16 x i8> undef, i8 %tmp.upgrd.12, i32 0 ; <<16 x i8>> [#uses=1]
153+
%tmp18 = insertelement <16 x i8> poison, i8 %tmp.upgrd.12, i32 0 ; <<16 x i8>> [#uses=1]
154154
%tmp19 = insertelement <16 x i8> %tmp18, i8 %tmp3, i32 1 ; <<16 x i8>> [#uses=1]
155155
%tmp20 = insertelement <16 x i8> %tmp19, i8 %tmp4, i32 2 ; <<16 x i8>> [#uses=1]
156156
%tmp21 = insertelement <16 x i8> %tmp20, i8 %tmp5, i32 3 ; <<16 x i8>> [#uses=1]
@@ -189,7 +189,7 @@ entry:
189189
%tmp7 = extractelement <8 x i16> %tmp2, i32 6 ; <i16> [#uses=1]
190190
%tmp8 = extractelement <8 x i16> %tmp, i32 7 ; <i16> [#uses=1]
191191
%tmp9 = extractelement <8 x i16> %tmp2, i32 7 ; <i16> [#uses=1]
192-
%tmp10 = insertelement <8 x i16> undef, i16 %tmp.upgrd.13, i32 0 ; <<8 x i16>> [#uses=1]
192+
%tmp10 = insertelement <8 x i16> poison, i16 %tmp.upgrd.13, i32 0 ; <<8 x i16>> [#uses=1]
193193
%tmp11 = insertelement <8 x i16> %tmp10, i16 %tmp3, i32 1 ; <<8 x i16>> [#uses=1]
194194
%tmp12 = insertelement <8 x i16> %tmp11, i16 %tmp4, i32 2 ; <<8 x i16>> [#uses=1]
195195
%tmp13 = insertelement <8 x i16> %tmp12, i16 %tmp5, i32 3 ; <<8 x i16>> [#uses=1]
@@ -216,7 +216,7 @@ entry:
216216
%tmp3 = extractelement <4 x i32> %tmp2, i32 2 ; <i32> [#uses=1]
217217
%tmp4 = extractelement <4 x i32> %tmp, i32 3 ; <i32> [#uses=1]
218218
%tmp5 = extractelement <4 x i32> %tmp2, i32 3 ; <i32> [#uses=1]
219-
%tmp6 = insertelement <4 x i32> undef, i32 %tmp.upgrd.14, i32 0 ; <<4 x i32>> [#uses=1]
219+
%tmp6 = insertelement <4 x i32> poison, i32 %tmp.upgrd.14, i32 0 ; <<4 x i32>> [#uses=1]
220220
%tmp7 = insertelement <4 x i32> %tmp6, i32 %tmp3, i32 1 ; <<4 x i32>> [#uses=1]
221221
%tmp8 = insertelement <4 x i32> %tmp7, i32 %tmp4, i32 2 ; <<4 x i32>> [#uses=1]
222222
%tmp9 = insertelement <4 x i32> %tmp8, i32 %tmp5, i32 3 ; <<4 x i32>> [#uses=1]

llvm/test/Transforms/InstCombine/vec_shuffle-inseltpoison.ll

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,23 @@ define <4 x float> @test8(<4 x float> %x, <4 x float> %y) {
8787
; CHECK-LABEL: @test8(
8888
; CHECK-NEXT: [[T134:%.*]] = shufflevector <4 x float> [[X:%.*]], <4 x float> [[Y:%.*]], <4 x i32> <i32 1, i32 poison, i32 3, i32 4>
8989
; CHECK-NEXT: ret <4 x float> [[T134]]
90+
;
91+
%t4 = extractelement <4 x float> %x, i32 1
92+
%t2 = extractelement <4 x float> %x, i32 3
93+
%t1 = extractelement <4 x float> %y, i32 0
94+
%t128 = insertelement <4 x float> poison, float %t4, i32 0
95+
%t130 = insertelement <4 x float> %t128, float poison, i32 1
96+
%t132 = insertelement <4 x float> %t130, float %t2, i32 2
97+
%t134 = insertelement <4 x float> %t132, float %t1, i32 3
98+
ret <4 x float> %t134
99+
}
100+
101+
; This shouldn't turn into a single shuffle
102+
define <4 x float> @test8_undef(<4 x float> %x, <4 x float> %y) {
103+
; CHECK-LABEL: @test8_undef(
104+
; CHECK-NEXT: [[T132:%.*]] = shufflevector <4 x float> [[X:%.*]], <4 x float> <float poison, float undef, float poison, float poison>, <4 x i32> <i32 1, i32 5, i32 3, i32 poison>
105+
; CHECK-NEXT: [[T134:%.*]] = shufflevector <4 x float> [[T132]], <4 x float> [[Y:%.*]], <4 x i32> <i32 0, i32 1, i32 2, i32 4>
106+
; CHECK-NEXT: ret <4 x float> [[T134]]
90107
;
91108
%t4 = extractelement <4 x float> %x, i32 1
92109
%t2 = extractelement <4 x float> %x, i32 3

llvm/test/Transforms/InstCombine/vec_shuffle.ll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,11 @@ define <4 x float> @test7(<4 x float> %x) {
8888
ret <4 x float> %r
8989
}
9090

91-
; This should turn into a single shuffle.
91+
; This should not turn into a single shuffle.
9292
define <4 x float> @test8(<4 x float> %x, <4 x float> %y) {
9393
; CHECK-LABEL: @test8(
94-
; CHECK-NEXT: [[T134:%.*]] = shufflevector <4 x float> [[X:%.*]], <4 x float> [[Y:%.*]], <4 x i32> <i32 1, i32 poison, i32 3, i32 4>
94+
; CHECK-NEXT: [[T132:%.*]] = shufflevector <4 x float> [[X:%.*]], <4 x float> <float poison, float undef, float poison, float poison>, <4 x i32> <i32 1, i32 5, i32 3, i32 poison>
95+
; CHECK-NEXT: [[T134:%.*]] = shufflevector <4 x float> [[T132]], <4 x float> [[Y:%.*]], <4 x i32> <i32 0, i32 1, i32 2, i32 4>
9596
; CHECK-NEXT: ret <4 x float> [[T134]]
9697
;
9798
%t4 = extractelement <4 x float> %x, i32 1

0 commit comments

Comments
 (0)