Skip to content

Commit 76e889d

Browse files
committed
[InstCombine] Avoid use of ConstantExpr::getShl()
Use the constant folding API instead (we later call isNotMinSignedValue on it, so we do need the Constant* return type here). Use ImmConstant to guarantee that constant folding succeeds.
1 parent 440af98 commit 76e889d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,13 @@ Instruction *InstCombinerImpl::visitMul(BinaryOperator &I) {
223223
Value *NewOp;
224224
Constant *C1, *C2;
225225
const APInt *IVal;
226-
if (match(&I, m_Mul(m_Shl(m_Value(NewOp), m_Constant(C2)),
227-
m_Constant(C1))) &&
226+
if (match(&I, m_Mul(m_Shl(m_Value(NewOp), m_ImmConstant(C2)),
227+
m_ImmConstant(C1))) &&
228228
match(C1, m_APInt(IVal))) {
229229
// ((X << C2)*C1) == (X * (C1 << C2))
230-
Constant *Shl = ConstantExpr::getShl(C1, C2);
230+
Constant *Shl =
231+
ConstantFoldBinaryOpOperands(Instruction::Shl, C1, C2, DL);
232+
assert(Shl && "Constant folding of immediate constants failed");
231233
BinaryOperator *Mul = cast<BinaryOperator>(I.getOperand(0));
232234
BinaryOperator *BO = BinaryOperator::CreateMul(NewOp, Shl);
233235
if (HasNUW && Mul->hasNoUnsignedWrap())

0 commit comments

Comments
 (0)