Skip to content

Commit ecd269e

Browse files
committed
[InstCombine] Check for poison instead of undef in splat shuffle fold
We can't canonicalize these to a splat shuffle, as doing so would convert undef -> poison.
1 parent 557a0be commit ecd269e

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2214,19 +2214,19 @@ static Instruction *canonicalizeInsertSplat(ShuffleVectorInst &Shuf,
22142214
uint64_t IndexC;
22152215

22162216
// Match a shuffle that is a splat to a non-zero element.
2217-
if (!match(Op0, m_OneUse(m_InsertElt(m_Undef(), m_Value(X),
2217+
if (!match(Op0, m_OneUse(m_InsertElt(m_Poison(), m_Value(X),
22182218
m_ConstantInt(IndexC)))) ||
2219-
!match(Op1, m_Undef()) || match(Mask, m_ZeroMask()) || IndexC == 0)
2219+
!match(Op1, m_Poison()) || match(Mask, m_ZeroMask()) || IndexC == 0)
22202220
return nullptr;
22212221

22222222
// Insert into element 0 of a poison vector.
22232223
PoisonValue *PoisonVec = PoisonValue::get(Shuf.getType());
22242224
Value *NewIns = Builder.CreateInsertElement(PoisonVec, X, (uint64_t)0);
22252225

2226-
// Splat from element 0. Any mask element that is undefined remains undefined.
2226+
// Splat from element 0. Any mask element that is poison remains poison.
22272227
// For example:
2228-
// shuf (inselt undef, X, 2), _, <2,2,undef>
2229-
// --> shuf (inselt undef, X, 0), poison, <0,0,undef>
2228+
// shuf (inselt poison, X, 2), _, <2,2,undef>
2229+
// --> shuf (inselt poison, X, 0), poison, <0,0,undef>
22302230
unsigned NumMaskElts =
22312231
cast<FixedVectorType>(Shuf.getType())->getNumElements();
22322232
SmallVector<int, 16> NewMask(NumMaskElts, 0);

llvm/test/Transforms/InstCombine/vec_shuffle.ll

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2346,23 +2346,19 @@ define i16 @pr92887(<2 x i16> %v) {
23462346
ret i16 %extract
23472347
}
23482348

2349-
; FIXME: This is a miscompile.
23502349
define <2 x i32> @not_splat_shuffle1(i32 %x) {
23512350
; CHECK-LABEL: @not_splat_shuffle1(
2352-
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <2 x i32> poison, i32 [[X:%.*]], i64 0
2353-
; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <2 x i32> [[TMP1]], <2 x i32> poison, <2 x i32> zeroinitializer
2351+
; CHECK-NEXT: [[SHUF:%.*]] = insertelement <2 x i32> <i32 poison, i32 undef>, i32 [[X:%.*]], i64 0
23542352
; CHECK-NEXT: ret <2 x i32> [[SHUF]]
23552353
;
23562354
%vec = insertelement <2 x i32> undef, i32 %x, i32 1
23572355
%shuf = shufflevector <2 x i32> %vec, <2 x i32> poison, <2 x i32> <i32 1, i32 0>
23582356
ret <2 x i32> %shuf
23592357
}
23602358

2361-
; FIXME: This is a miscompile.
23622359
define <2 x i32> @not_splat_shuffle2(i32 %x) {
23632360
; CHECK-LABEL: @not_splat_shuffle2(
2364-
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <2 x i32> poison, i32 [[X:%.*]], i64 0
2365-
; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <2 x i32> [[TMP1]], <2 x i32> poison, <2 x i32> zeroinitializer
2361+
; CHECK-NEXT: [[SHUF:%.*]] = insertelement <2 x i32> <i32 poison, i32 undef>, i32 [[X:%.*]], i64 0
23662362
; CHECK-NEXT: ret <2 x i32> [[SHUF]]
23672363
;
23682364
%vec = insertelement <2 x i32> poison, i32 %x, i32 1

0 commit comments

Comments
 (0)