@@ -245,7 +245,11 @@ dropRedundantMaskingOfLeftShiftInput(BinaryOperator *OuterShift,
245
245
SumOfShAmts = Constant::replaceUndefsWith (
246
246
SumOfShAmts, ConstantInt::get (SumOfShAmts->getType ()->getScalarType (),
247
247
ExtendedTy->getScalarSizeInBits ()));
248
- auto *ExtendedSumOfShAmts = ConstantExpr::getZExt (SumOfShAmts, ExtendedTy);
248
+ auto *ExtendedSumOfShAmts = ConstantFoldCastOperand (
249
+ Instruction::ZExt, SumOfShAmts, ExtendedTy, Q.DL );
250
+ if (!ExtendedSumOfShAmts)
251
+ return nullptr ;
252
+
249
253
// And compute the mask as usual: ~(-1 << (SumOfShAmts))
250
254
auto *ExtendedAllOnes = ConstantExpr::getAllOnesValue (ExtendedTy);
251
255
auto *ExtendedInvertedMask =
@@ -278,12 +282,16 @@ dropRedundantMaskingOfLeftShiftInput(BinaryOperator *OuterShift,
278
282
ShAmtsDiff = Constant::replaceUndefsWith (
279
283
ShAmtsDiff, ConstantInt::get (ShAmtsDiff->getType ()->getScalarType (),
280
284
-WidestTyBitWidth));
281
- auto *ExtendedNumHighBitsToClear = ConstantExpr::getZExt (
285
+ auto *ExtendedNumHighBitsToClear = ConstantFoldCastOperand (
286
+ Instruction::ZExt,
282
287
ConstantExpr::getSub (ConstantInt::get (ShAmtsDiff->getType (),
283
288
WidestTyBitWidth,
284
289
/* isSigned=*/ false ),
285
290
ShAmtsDiff),
286
- ExtendedTy);
291
+ ExtendedTy, Q.DL );
292
+ if (!ExtendedNumHighBitsToClear)
293
+ return nullptr ;
294
+
287
295
// And compute the mask as usual: (-1 l>> (NumHighBitsToClear))
288
296
auto *ExtendedAllOnes = ConstantExpr::getAllOnesValue (ExtendedTy);
289
297
NewMask =
0 commit comments