Skip to content

Commit ae3f0d2

Browse files
nikicAlexisPerry
authored andcommitted
[InstCombine] Avoid use of ConstantExpr::getShl()
Use the constant folding API instead. Use ImmConstant to ensure folding succeeds.
1 parent 6e1751c commit ae3f0d2

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -642,9 +642,11 @@ getBinOpsForFactorization(Instruction::BinaryOps TopOpcode, BinaryOperator *Op,
642642
RHS = Op->getOperand(1);
643643
if (TopOpcode == Instruction::Add || TopOpcode == Instruction::Sub) {
644644
Constant *C;
645-
if (match(Op, m_Shl(m_Value(), m_Constant(C)))) {
645+
if (match(Op, m_Shl(m_Value(), m_ImmConstant(C)))) {
646646
// X << C --> X * (1 << C)
647-
RHS = ConstantExpr::getShl(ConstantInt::get(Op->getType(), 1), C);
647+
RHS = ConstantFoldBinaryInstruction(
648+
Instruction::Shl, ConstantInt::get(Op->getType(), 1), C);
649+
assert(RHS && "Constant folding of immediate constants failed");
648650
return Instruction::Mul;
649651
}
650652
// TODO: We can add other conversions e.g. shr => div etc.

0 commit comments

Comments
 (0)