Skip to content

Commit

Permalink
[InstCombine] Check for poison instead of undef in shuffle of unop tr…
Browse files Browse the repository at this point in the history
…ansform

Otherwise this may not actually be a single-source shuffle.
  • Loading branch information
nikic committed May 21, 2024
1 parent b8e3d80 commit 8f1c984
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2462,7 +2462,7 @@ static Instruction *foldShuffleOfUnaryOps(ShuffleVectorInst &Shuf,

// Match 1-input (unary) shuffle.
// shuffle (fneg/fabs X), Mask --> fneg/fabs (shuffle X, Mask)
if (S0->hasOneUse() && match(Shuf.getOperand(1), m_Undef())) {
if (S0->hasOneUse() && match(Shuf.getOperand(1), m_Poison())) {
Value *NewShuf = Builder.CreateShuffleVector(X, Shuf.getShuffleMask());
if (IsFNeg)
return UnaryOperator::CreateFNegFMF(NewShuf, S0);
Expand Down
7 changes: 3 additions & 4 deletions llvm/test/Transforms/InstCombine/vec_shuffle.ll
Original file line number Diff line number Diff line change
Expand Up @@ -1280,12 +1280,11 @@ define <2 x float> @fneg(<2 x float> %x) {
ret <2 x float> %r
}

; FIXME: This is a miscompile.
define <2 x float> @fneg_not_single_source(<2 x float> %x) {
; CHECK-LABEL: @fneg_not_single_source(
; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <2 x float> [[X:%.*]], <2 x float> poison, <2 x i32> <i32 0, i32 poison>
; CHECK-NEXT: [[SPLAT:%.*]] = fneg <2 x float> [[TMP1]]
; CHECK-NEXT: ret <2 x float> [[SPLAT]]
; CHECK-NEXT: [[NEG:%.*]] = fneg <2 x float> [[X:%.*]]
; CHECK-NEXT: [[SPLAT1:%.*]] = insertelement <2 x float> [[NEG]], float undef, i64 1
; CHECK-NEXT: ret <2 x float> [[SPLAT1]]
;
%neg = fneg <2 x float> %x
%splat = shufflevector <2 x float> %neg, <2 x float> undef, <2 x i32> <i32 0, i32 2>
Expand Down

0 comments on commit 8f1c984

Please sign in to comment.