Skip to content

Commit 8f1c984

Browse files
committed
[InstCombine] Check for poison instead of undef in shuffle of unop transform
Otherwise this may not actually be a single-source shuffle.
1 parent b8e3d80 commit 8f1c984

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2462,7 +2462,7 @@ static Instruction *foldShuffleOfUnaryOps(ShuffleVectorInst &Shuf,
24622462

24632463
// Match 1-input (unary) shuffle.
24642464
// shuffle (fneg/fabs X), Mask --> fneg/fabs (shuffle X, Mask)
2465-
if (S0->hasOneUse() && match(Shuf.getOperand(1), m_Undef())) {
2465+
if (S0->hasOneUse() && match(Shuf.getOperand(1), m_Poison())) {
24662466
Value *NewShuf = Builder.CreateShuffleVector(X, Shuf.getShuffleMask());
24672467
if (IsFNeg)
24682468
return UnaryOperator::CreateFNegFMF(NewShuf, S0);

llvm/test/Transforms/InstCombine/vec_shuffle.ll

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,12 +1280,11 @@ define <2 x float> @fneg(<2 x float> %x) {
12801280
ret <2 x float> %r
12811281
}
12821282

1283-
; FIXME: This is a miscompile.
12841283
define <2 x float> @fneg_not_single_source(<2 x float> %x) {
12851284
; CHECK-LABEL: @fneg_not_single_source(
1286-
; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <2 x float> [[X:%.*]], <2 x float> poison, <2 x i32> <i32 0, i32 poison>
1287-
; CHECK-NEXT: [[SPLAT:%.*]] = fneg <2 x float> [[TMP1]]
1288-
; CHECK-NEXT: ret <2 x float> [[SPLAT]]
1285+
; CHECK-NEXT: [[NEG:%.*]] = fneg <2 x float> [[X:%.*]]
1286+
; CHECK-NEXT: [[SPLAT1:%.*]] = insertelement <2 x float> [[NEG]], float undef, i64 1
1287+
; CHECK-NEXT: ret <2 x float> [[SPLAT1]]
12891288
;
12901289
%neg = fneg <2 x float> %x
12911290
%splat = shufflevector <2 x float> %neg, <2 x float> undef, <2 x i32> <i32 0, i32 2>

0 commit comments

Comments
 (0)