Skip to content

Commit eb5199e

Browse files
committed
[InstCombine] Avoid some uses of ConstantExpr::getLShr() (NFC)
Use the constant folding API instead. As we're working on ImmConstant, it is guaranteed to succeed.
1 parent d51dd89 commit eb5199e

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -620,8 +620,10 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
620620
if (DemandedMask.countr_zero() >= ShiftAmt &&
621621
match(I->getOperand(0), m_LShr(m_ImmConstant(C), m_Value(X)))) {
622622
Constant *LeftShiftAmtC = ConstantInt::get(VTy, ShiftAmt);
623-
Constant *NewC = ConstantExpr::getShl(C, LeftShiftAmtC);
624-
if (ConstantExpr::getLShr(NewC, LeftShiftAmtC) == C) {
623+
Constant *NewC = ConstantFoldBinaryOpOperands(Instruction::Shl, C,
624+
LeftShiftAmtC, DL);
625+
if (ConstantFoldBinaryOpOperands(Instruction::LShr, NewC, LeftShiftAmtC,
626+
DL) == C) {
625627
Instruction *Lshr = BinaryOperator::CreateLShr(NewC, X);
626628
return InsertNewInstWith(Lshr, I->getIterator());
627629
}
@@ -684,8 +686,10 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
684686
Constant *C;
685687
if (match(I->getOperand(0), m_Shl(m_ImmConstant(C), m_Value(X)))) {
686688
Constant *RightShiftAmtC = ConstantInt::get(VTy, ShiftAmt);
687-
Constant *NewC = ConstantExpr::getLShr(C, RightShiftAmtC);
688-
if (ConstantExpr::getShl(NewC, RightShiftAmtC) == C) {
689+
Constant *NewC = ConstantFoldBinaryOpOperands(Instruction::LShr, C,
690+
RightShiftAmtC, DL);
691+
if (ConstantFoldBinaryOpOperands(Instruction::Shl, NewC,
692+
RightShiftAmtC, DL) == C) {
689693
Instruction *Shl = BinaryOperator::CreateShl(NewC, X);
690694
return InsertNewInstWith(Shl, I->getIterator());
691695
}

0 commit comments

Comments
 (0)