@@ -257,8 +257,11 @@ dropRedundantMaskingOfLeftShiftInput(BinaryOperator *OuterShift,
257
257
258
258
// And compute the mask as usual: ~(-1 << (SumOfShAmts))
259
259
auto *ExtendedAllOnes = ConstantExpr::getAllOnesValue (ExtendedTy);
260
- auto *ExtendedInvertedMask =
261
- ConstantExpr::getShl (ExtendedAllOnes, ExtendedSumOfShAmts);
260
+ Constant *ExtendedInvertedMask = ConstantFoldBinaryOpOperands (
261
+ Instruction::Shl, ExtendedAllOnes, ExtendedSumOfShAmts, Q.DL );
262
+ if (!ExtendedInvertedMask)
263
+ return nullptr ;
264
+
262
265
NewMask = ConstantExpr::getNot (ExtendedInvertedMask);
263
266
} else if (match (Masked, m_c_And (m_CombineOr (MaskC, MaskD), m_Value (X))) ||
264
267
match (Masked, m_Shr (m_Shl (m_Value (X), m_Value (MaskShAmt)),
@@ -1218,16 +1221,16 @@ Instruction *InstCombinerImpl::visitShl(BinaryOperator &I) {
1218
1221
}
1219
1222
1220
1223
Constant *C1;
1221
- if (match (Op1, m_Constant (C1))) {
1224
+ if (match (Op1, m_ImmConstant (C1))) {
1222
1225
Constant *C2;
1223
1226
Value *X;
1224
1227
// (X * C2) << C1 --> X * (C2 << C1)
1225
- if (match (Op0, m_Mul (m_Value (X), m_Constant (C2))))
1226
- return BinaryOperator::CreateMul (X, ConstantExpr::getShl (C2, C1));
1228
+ if (match (Op0, m_Mul (m_Value (X), m_ImmConstant (C2))))
1229
+ return BinaryOperator::CreateMul (X, Builder. CreateShl (C2, C1));
1227
1230
1228
1231
// shl (zext i1 X), C1 --> select (X, 1 << C1, 0)
1229
1232
if (match (Op0, m_ZExt (m_Value (X))) && X->getType ()->isIntOrIntVectorTy (1 )) {
1230
- auto *NewC = ConstantExpr::getShl (ConstantInt::get (Ty, 1 ), C1);
1233
+ auto *NewC = Builder. CreateShl (ConstantInt::get (Ty, 1 ), C1);
1231
1234
return SelectInst::Create (X, NewC, ConstantInt::getNullValue (Ty));
1232
1235
}
1233
1236
}
0 commit comments