Skip to content

Commit 8391f40

Browse files
committed
[InstCombine] Avoid uses of ConstantExpr::getLShr()
Use the constant folding API instead.
1 parent eb5199e commit 8391f40

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2132,9 +2132,12 @@ static bool collectInsertionElements(Value *V, unsigned Shift,
21322132
Type *ElementIntTy = IntegerType::get(C->getContext(), ElementSize);
21332133

21342134
for (unsigned i = 0; i != NumElts; ++i) {
2135-
unsigned ShiftI = Shift+i*ElementSize;
2136-
Constant *Piece = ConstantExpr::getLShr(C, ConstantInt::get(C->getType(),
2137-
ShiftI));
2135+
unsigned ShiftI = Shift + i * ElementSize;
2136+
Constant *Piece = ConstantFoldBinaryInstruction(
2137+
Instruction::LShr, C, ConstantInt::get(C->getType(), ShiftI));
2138+
if (!Piece)
2139+
return false;
2140+
21382141
Piece = ConstantExpr::getTrunc(Piece, ElementIntTy);
21392142
if (!collectInsertionElements(Piece, ShiftI, Elements, VecEltTy,
21402143
isBigEndian))

llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,10 @@ dropRedundantMaskingOfLeftShiftInput(BinaryOperator *OuterShift,
299299

300300
// And compute the mask as usual: (-1 l>> (NumHighBitsToClear))
301301
auto *ExtendedAllOnes = ConstantExpr::getAllOnesValue(ExtendedTy);
302-
NewMask =
303-
ConstantExpr::getLShr(ExtendedAllOnes, ExtendedNumHighBitsToClear);
302+
NewMask = ConstantFoldBinaryOpOperands(Instruction::LShr, ExtendedAllOnes,
303+
ExtendedNumHighBitsToClear, Q.DL);
304+
if (!NewMask)
305+
return nullptr;
304306
} else
305307
return nullptr; // Don't know anything about this pattern.
306308

0 commit comments

Comments
 (0)