summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2024-05-21 15:18:17 +0200
committerNikita Popov <npopov@redhat.com>2024-05-21 15:21:31 +0200
commitecd269e8305330c185bbedbd5a59e887122333ba (patch)
treeb25017ca2a1ebd5573abc387c61bedf1cecdda7b
parent557a0be3af798cf55b1ef54fc98a84fa5a4ade42 (diff)
[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.
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp10
-rw-r--r--llvm/test/Transforms/InstCombine/vec_shuffle.ll8
2 files changed, 7 insertions, 11 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
index 745ccbfe9dc7..ac062fe55ce4 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
@@ -2214,19 +2214,19 @@ static Instruction *canonicalizeInsertSplat(ShuffleVectorInst &Shuf,
uint64_t IndexC;
// Match a shuffle that is a splat to a non-zero element.
- if (!match(Op0, m_OneUse(m_InsertElt(m_Undef(), m_Value(X),
+ if (!match(Op0, m_OneUse(m_InsertElt(m_Poison(), m_Value(X),
m_ConstantInt(IndexC)))) ||
- !match(Op1, m_Undef()) || match(Mask, m_ZeroMask()) || IndexC == 0)
+ !match(Op1, m_Poison()) || match(Mask, m_ZeroMask()) || IndexC == 0)
return nullptr;
// Insert into element 0 of a poison vector.
PoisonValue *PoisonVec = PoisonValue::get(Shuf.getType());
Value *NewIns = Builder.CreateInsertElement(PoisonVec, X, (uint64_t)0);
- // Splat from element 0. Any mask element that is undefined remains undefined.
+ // Splat from element 0. Any mask element that is poison remains poison.
// For example:
- // shuf (inselt undef, X, 2), _, <2,2,undef>
- // --> shuf (inselt undef, X, 0), poison, <0,0,undef>
+ // shuf (inselt poison, X, 2), _, <2,2,undef>
+ // --> shuf (inselt poison, X, 0), poison, <0,0,undef>
unsigned NumMaskElts =
cast<FixedVectorType>(Shuf.getType())->getNumElements();
SmallVector<int, 16> NewMask(NumMaskElts, 0);
diff --git a/llvm/test/Transforms/InstCombine/vec_shuffle.ll b/llvm/test/Transforms/InstCombine/vec_shuffle.ll
index 7428f7a93d64..7217e1ac4aa9 100644
--- a/llvm/test/Transforms/InstCombine/vec_shuffle.ll
+++ b/llvm/test/Transforms/InstCombine/vec_shuffle.ll
@@ -2346,11 +2346,9 @@ define i16 @pr92887(<2 x i16> %v) {
ret i16 %extract
}
-; FIXME: This is a miscompile.
define <2 x i32> @not_splat_shuffle1(i32 %x) {
; CHECK-LABEL: @not_splat_shuffle1(
-; CHECK-NEXT: [[TMP1:%.*]] = insertelement <2 x i32> poison, i32 [[X:%.*]], i64 0
-; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <2 x i32> [[TMP1]], <2 x i32> poison, <2 x i32> zeroinitializer
+; CHECK-NEXT: [[SHUF:%.*]] = insertelement <2 x i32> <i32 poison, i32 undef>, i32 [[X:%.*]], i64 0
; CHECK-NEXT: ret <2 x i32> [[SHUF]]
;
%vec = insertelement <2 x i32> undef, i32 %x, i32 1
@@ -2358,11 +2356,9 @@ define <2 x i32> @not_splat_shuffle1(i32 %x) {
ret <2 x i32> %shuf
}
-; FIXME: This is a miscompile.
define <2 x i32> @not_splat_shuffle2(i32 %x) {
; CHECK-LABEL: @not_splat_shuffle2(
-; CHECK-NEXT: [[TMP1:%.*]] = insertelement <2 x i32> poison, i32 [[X:%.*]], i64 0
-; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <2 x i32> [[TMP1]], <2 x i32> poison, <2 x i32> zeroinitializer
+; CHECK-NEXT: [[SHUF:%.*]] = insertelement <2 x i32> <i32 poison, i32 undef>, i32 [[X:%.*]], i64 0
; CHECK-NEXT: ret <2 x i32> [[SHUF]]
;
%vec = insertelement <2 x i32> poison, i32 %x, i32 1