@@ -131,7 +131,7 @@ reassociateShiftAmtsOfTwoSameDirectionShifts(BinaryOperator *Sh0,
131
131
// c,d,e,f) (ShiftShAmt-MaskShAmt) s>= 0 (i.e. ShiftShAmt u>= MaskShAmt)
132
132
static Instruction *
133
133
dropRedundantMaskingOfLeftShiftInput (BinaryOperator *OuterShift,
134
- const SimplifyQuery &SQ ,
134
+ const SimplifyQuery &Q ,
135
135
InstCombiner::BuilderTy &Builder) {
136
136
assert (OuterShift->getOpcode () == Instruction::BinaryOps::Shl &&
137
137
" The input must be 'shl'!" );
@@ -155,9 +155,8 @@ dropRedundantMaskingOfLeftShiftInput(BinaryOperator *OuterShift,
155
155
Constant *NewMask;
156
156
if (match (Masked, m_c_And (m_CombineOr (MaskA, MaskB), m_Value (X)))) {
157
157
// 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));
161
160
if (!SumOfShAmts)
162
161
return nullptr ; // Did not simplify.
163
162
Type *Ty = X->getType ();
@@ -189,9 +188,8 @@ dropRedundantMaskingOfLeftShiftInput(BinaryOperator *OuterShift,
189
188
match (Masked, m_Shr (m_Shl (m_Value (X), m_Value (MaskShAmt)),
190
189
m_Deferred (MaskShAmt)))) {
191
190
// 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));
195
193
if (!ShAmtsDiff)
196
194
return nullptr ; // Did not simplify.
197
195
// In this pattern ShAmtsDiff correlates with the number of high bits that
@@ -797,9 +795,10 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, Constant *Op1,
797
795
}
798
796
799
797
Instruction *InstCombiner::visitShl (BinaryOperator &I) {
798
+ const SimplifyQuery Q = SQ.getWithInstruction (&I);
799
+
800
800
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))
803
802
return replaceInstUsesWith (I, V);
804
803
805
804
if (Instruction *X = foldVectorBinop (I))
@@ -808,7 +807,7 @@ Instruction *InstCombiner::visitShl(BinaryOperator &I) {
808
807
if (Instruction *V = commonShiftTransforms (I))
809
808
return V;
810
809
811
- if (Instruction *V = dropRedundantMaskingOfLeftShiftInput (&I, SQ , Builder))
810
+ if (Instruction *V = dropRedundantMaskingOfLeftShiftInput (&I, Q , Builder))
812
811
return V;
813
812
814
813
Value *Op0 = I.getOperand (0 ), *Op1 = I.getOperand (1 );
0 commit comments