Skip to content

Commit bf4edb4

Browse files
committed
Overwritten with: 39dbf45 [InstCombine] Remove redundant splats in InstCombineVectorOps
Based on upstream llvm : 669e508 [Driver] Fix -f[no-]unwind-tables -Wunused-command-line-argument after 4388b56 Added AMD modification notices and removed some GPL files.
2 parents a428839 + 39dbf45 commit bf4edb4

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

llvm/lib/Transforms/InstCombine/InstCombineInternal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
// Modifications Copyright (c) 2020 Advanced Micro Devices, Inc. All rights reserved.
7+
// Notified per clause 4(b) of the license.
68
//
79
//===----------------------------------------------------------------------===//
810
//
@@ -167,6 +169,7 @@ class LLVM_LIBRARY_VISIBILITY InstCombinerImpl final
167169
Instruction *visitInsertValueInst(InsertValueInst &IV);
168170
Instruction *visitInsertElementInst(InsertElementInst &IE);
169171
Instruction *visitExtractElementInst(ExtractElementInst &EI);
172+
Instruction *simplifyBinOpSplats(ShuffleVectorInst &SVI);
170173
Instruction *visitShuffleVectorInst(ShuffleVectorInst &SVI);
171174
Instruction *visitExtractValueInst(ExtractValueInst &EV);
172175
Instruction *visitLandingPadInst(LandingPadInst &LI);

llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2530,6 +2530,35 @@ static Instruction *foldIdentityPaddedShuffles(ShuffleVectorInst &Shuf) {
25302530
return new ShuffleVectorInst(X, Y, NewMask);
25312531
}
25322532

2533+
// Splatting the first element of the result of a BinOp, where any of the
2534+
// BinOp's operands are the result of a first element splat can be simplified to
2535+
// splatting the first element of the result of the BinOp
2536+
Instruction *InstCombinerImpl::simplifyBinOpSplats(ShuffleVectorInst &SVI) {
2537+
if (!match(SVI.getOperand(1), m_Undef()) ||
2538+
!match(SVI.getShuffleMask(), m_ZeroMask()))
2539+
return nullptr;
2540+
2541+
Value *Op0 = SVI.getOperand(0);
2542+
Value *X, *Y;
2543+
if (!match(Op0, m_BinOp(m_Shuffle(m_Value(X), m_Undef(), m_ZeroMask()),
2544+
m_Value(Y))) &&
2545+
!match(Op0, m_BinOp(m_Value(X),
2546+
m_Shuffle(m_Value(Y), m_Undef(), m_ZeroMask()))))
2547+
return nullptr;
2548+
if (X->getType() != Y->getType())
2549+
return nullptr;
2550+
2551+
auto *BinOp = cast<BinaryOperator>(Op0);
2552+
if (!isSafeToSpeculativelyExecute(BinOp))
2553+
return nullptr;
2554+
2555+
Value *NewBO = Builder.CreateBinOp(BinOp->getOpcode(), X, Y);
2556+
if (auto NewBOI = dyn_cast<Instruction>(NewBO))
2557+
NewBOI->copyIRFlags(BinOp);
2558+
2559+
return new ShuffleVectorInst(NewBO, SVI.getShuffleMask());
2560+
}
2561+
25332562
Instruction *InstCombinerImpl::visitShuffleVectorInst(ShuffleVectorInst &SVI) {
25342563
Value *LHS = SVI.getOperand(0);
25352564
Value *RHS = SVI.getOperand(1);
@@ -2538,7 +2567,9 @@ Instruction *InstCombinerImpl::visitShuffleVectorInst(ShuffleVectorInst &SVI) {
25382567
SVI.getType(), ShufQuery))
25392568
return replaceInstUsesWith(SVI, V);
25402569

2541-
// Bail out for scalable vectors
2570+
if (Instruction *I = simplifyBinOpSplats(SVI))
2571+
return I;
2572+
25422573
if (isa<ScalableVectorType>(LHS->getType()))
25432574
return nullptr;
25442575

0 commit comments

Comments
 (0)