Skip to content

Commit

Permalink
[InstCombine] Avoid some uses of ConstantExpr::getLShr() (NFC)
Browse files Browse the repository at this point in the history
Use the constant folding API instead. As we're working on
ImmConstant, it is guaranteed to succeed.
  • Loading branch information
nikic committed Nov 10, 2023
1 parent d51dd89 commit eb5199e
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,8 +620,10 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
if (DemandedMask.countr_zero() >= ShiftAmt &&
match(I->getOperand(0), m_LShr(m_ImmConstant(C), m_Value(X)))) {
Constant *LeftShiftAmtC = ConstantInt::get(VTy, ShiftAmt);
Constant *NewC = ConstantExpr::getShl(C, LeftShiftAmtC);
if (ConstantExpr::getLShr(NewC, LeftShiftAmtC) == C) {
Constant *NewC = ConstantFoldBinaryOpOperands(Instruction::Shl, C,
LeftShiftAmtC, DL);
if (ConstantFoldBinaryOpOperands(Instruction::LShr, NewC, LeftShiftAmtC,
DL) == C) {
Instruction *Lshr = BinaryOperator::CreateLShr(NewC, X);
return InsertNewInstWith(Lshr, I->getIterator());
}
Expand Down Expand Up @@ -684,8 +686,10 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
Constant *C;
if (match(I->getOperand(0), m_Shl(m_ImmConstant(C), m_Value(X)))) {
Constant *RightShiftAmtC = ConstantInt::get(VTy, ShiftAmt);
Constant *NewC = ConstantExpr::getLShr(C, RightShiftAmtC);
if (ConstantExpr::getShl(NewC, RightShiftAmtC) == C) {
Constant *NewC = ConstantFoldBinaryOpOperands(Instruction::LShr, C,
RightShiftAmtC, DL);
if (ConstantFoldBinaryOpOperands(Instruction::Shl, NewC,
RightShiftAmtC, DL) == C) {
Instruction *Shl = BinaryOperator::CreateShl(NewC, X);
return InsertNewInstWith(Shl, I->getIterator());
}
Expand Down

0 comments on commit eb5199e

Please sign in to comment.