Skip to content

Commit faa90ec

Browse files
committed
[InstCombine][NFC] visitShl(): call SimplifyQuery::getWithInstruction() once
llvm-svn: 373249
1 parent 0205be8 commit faa90ec

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ reassociateShiftAmtsOfTwoSameDirectionShifts(BinaryOperator *Sh0,
131131
// c,d,e,f) (ShiftShAmt-MaskShAmt) s>= 0 (i.e. ShiftShAmt u>= MaskShAmt)
132132
static Instruction *
133133
dropRedundantMaskingOfLeftShiftInput(BinaryOperator *OuterShift,
134-
const SimplifyQuery &SQ,
134+
const SimplifyQuery &Q,
135135
InstCombiner::BuilderTy &Builder) {
136136
assert(OuterShift->getOpcode() == Instruction::BinaryOps::Shl &&
137137
"The input must be 'shl'!");
@@ -155,9 +155,8 @@ dropRedundantMaskingOfLeftShiftInput(BinaryOperator *OuterShift,
155155
Constant *NewMask;
156156
if (match(Masked, m_c_And(m_CombineOr(MaskA, MaskB), m_Value(X)))) {
157157
// Can we simplify (MaskShAmt+ShiftShAmt) ?
158-
auto *SumOfShAmts = dyn_cast_or_null<Constant>(
159-
SimplifyAddInst(MaskShAmt, ShiftShAmt, /*IsNSW=*/false, /*IsNUW=*/false,
160-
SQ.getWithInstruction(OuterShift)));
158+
auto *SumOfShAmts = dyn_cast_or_null<Constant>(SimplifyAddInst(
159+
MaskShAmt, ShiftShAmt, /*IsNSW=*/false, /*IsNUW=*/false, Q));
161160
if (!SumOfShAmts)
162161
return nullptr; // Did not simplify.
163162
Type *Ty = X->getType();
@@ -189,9 +188,8 @@ dropRedundantMaskingOfLeftShiftInput(BinaryOperator *OuterShift,
189188
match(Masked, m_Shr(m_Shl(m_Value(X), m_Value(MaskShAmt)),
190189
m_Deferred(MaskShAmt)))) {
191190
// Can we simplify (ShiftShAmt-MaskShAmt) ?
192-
auto *ShAmtsDiff = dyn_cast_or_null<Constant>(
193-
SimplifySubInst(ShiftShAmt, MaskShAmt, /*IsNSW=*/false, /*IsNUW=*/false,
194-
SQ.getWithInstruction(OuterShift)));
191+
auto *ShAmtsDiff = dyn_cast_or_null<Constant>(SimplifySubInst(
192+
ShiftShAmt, MaskShAmt, /*IsNSW=*/false, /*IsNUW=*/false, Q));
195193
if (!ShAmtsDiff)
196194
return nullptr; // Did not simplify.
197195
// In this pattern ShAmtsDiff correlates with the number of high bits that
@@ -797,9 +795,10 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, Constant *Op1,
797795
}
798796

799797
Instruction *InstCombiner::visitShl(BinaryOperator &I) {
798+
const SimplifyQuery Q = SQ.getWithInstruction(&I);
799+
800800
if (Value *V = SimplifyShlInst(I.getOperand(0), I.getOperand(1),
801-
I.hasNoSignedWrap(), I.hasNoUnsignedWrap(),
802-
SQ.getWithInstruction(&I)))
801+
I.hasNoSignedWrap(), I.hasNoUnsignedWrap(), Q))
803802
return replaceInstUsesWith(I, V);
804803

805804
if (Instruction *X = foldVectorBinop(I))
@@ -808,7 +807,7 @@ Instruction *InstCombiner::visitShl(BinaryOperator &I) {
808807
if (Instruction *V = commonShiftTransforms(I))
809808
return V;
810809

811-
if (Instruction *V = dropRedundantMaskingOfLeftShiftInput(&I, SQ, Builder))
810+
if (Instruction *V = dropRedundantMaskingOfLeftShiftInput(&I, Q, Builder))
812811
return V;
813812

814813
Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);

0 commit comments

Comments
 (0)