Skip to content

Commit

Permalink
[InstCombine] Avoid uses of ConstantExpr::getLShr()
Browse files Browse the repository at this point in the history
Use the constant folding API instead.
  • Loading branch information
nikic committed Nov 10, 2023
1 parent eb5199e commit 8391f40
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 6 additions & 3 deletions llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2132,9 +2132,12 @@ static bool collectInsertionElements(Value *V, unsigned Shift,
Type *ElementIntTy = IntegerType::get(C->getContext(), ElementSize);

for (unsigned i = 0; i != NumElts; ++i) {
unsigned ShiftI = Shift+i*ElementSize;
Constant *Piece = ConstantExpr::getLShr(C, ConstantInt::get(C->getType(),
ShiftI));
unsigned ShiftI = Shift + i * ElementSize;
Constant *Piece = ConstantFoldBinaryInstruction(
Instruction::LShr, C, ConstantInt::get(C->getType(), ShiftI));
if (!Piece)
return false;

Piece = ConstantExpr::getTrunc(Piece, ElementIntTy);
if (!collectInsertionElements(Piece, ShiftI, Elements, VecEltTy,
isBigEndian))
Expand Down
6 changes: 4 additions & 2 deletions llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,10 @@ dropRedundantMaskingOfLeftShiftInput(BinaryOperator *OuterShift,

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

Expand Down

0 comments on commit 8391f40

Please sign in to comment.