Skip to content

Commit 7eda63b

Browse files
committed
[InstCombine] Avoid use of ConstantExpr::getZExt() (NFC)
Check the result of constant folding here, as I'm not confident that no constant expressions can make it in here.
1 parent d6d44d6 commit 7eda63b

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,11 @@ dropRedundantMaskingOfLeftShiftInput(BinaryOperator *OuterShift,
245245
SumOfShAmts = Constant::replaceUndefsWith(
246246
SumOfShAmts, ConstantInt::get(SumOfShAmts->getType()->getScalarType(),
247247
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+
249253
// And compute the mask as usual: ~(-1 << (SumOfShAmts))
250254
auto *ExtendedAllOnes = ConstantExpr::getAllOnesValue(ExtendedTy);
251255
auto *ExtendedInvertedMask =
@@ -278,12 +282,16 @@ dropRedundantMaskingOfLeftShiftInput(BinaryOperator *OuterShift,
278282
ShAmtsDiff = Constant::replaceUndefsWith(
279283
ShAmtsDiff, ConstantInt::get(ShAmtsDiff->getType()->getScalarType(),
280284
-WidestTyBitWidth));
281-
auto *ExtendedNumHighBitsToClear = ConstantExpr::getZExt(
285+
auto *ExtendedNumHighBitsToClear = ConstantFoldCastOperand(
286+
Instruction::ZExt,
282287
ConstantExpr::getSub(ConstantInt::get(ShAmtsDiff->getType(),
283288
WidestTyBitWidth,
284289
/*isSigned=*/false),
285290
ShAmtsDiff),
286-
ExtendedTy);
291+
ExtendedTy, Q.DL);
292+
if (!ExtendedNumHighBitsToClear)
293+
return nullptr;
294+
287295
// And compute the mask as usual: (-1 l>> (NumHighBitsToClear))
288296
auto *ExtendedAllOnes = ConstantExpr::getAllOnesValue(ExtendedTy);
289297
NewMask =

0 commit comments

Comments
 (0)