@@ -257,8 +257,11 @@ dropRedundantMaskingOfLeftShiftInput(BinaryOperator *OuterShift,
257257
258258 // And compute the mask as usual: ~(-1 << (SumOfShAmts))
259259 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+
262265 NewMask = ConstantExpr::getNot (ExtendedInvertedMask);
263266 } else if (match (Masked, m_c_And (m_CombineOr (MaskC, MaskD), m_Value (X))) ||
264267 match (Masked, m_Shr (m_Shl (m_Value (X), m_Value (MaskShAmt)),
@@ -1218,16 +1221,16 @@ Instruction *InstCombinerImpl::visitShl(BinaryOperator &I) {
12181221 }
12191222
12201223 Constant *C1;
1221- if (match (Op1, m_Constant (C1))) {
1224+ if (match (Op1, m_ImmConstant (C1))) {
12221225 Constant *C2;
12231226 Value *X;
12241227 // (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));
12271230
12281231 // shl (zext i1 X), C1 --> select (X, 1 << C1, 0)
12291232 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);
12311234 return SelectInst::Create (X, NewC, ConstantInt::getNullValue (Ty));
12321235 }
12331236 }
0 commit comments