aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2024-06-18 16:57:11 +0200
committerNikita Popov <npopov@redhat.com>2024-06-18 16:58:11 +0200
commit534e3ad08b0b9773aceaef82f1282fd5bd8c43e6 (patch)
treeeaaa272e595be66e297437dcf72dff4b176881e0
parentffc31d3221e2ebe1f5b1e5c846dcde27cb326616 (diff)
downloadllvm-534e3ad08b0b9773aceaef82f1282fd5bd8c43e6.zip
llvm-534e3ad08b0b9773aceaef82f1282fd5bd8c43e6.tar.gz
llvm-534e3ad08b0b9773aceaef82f1282fd5bd8c43e6.tar.bz2
[InstCombine] Avoid use of ConstantExpr::getShl()
Use the constant folding API instead. Use ImmConstant to ensure folding succeeds.
-rw-r--r--llvm/lib/Transforms/InstCombine/InstructionCombining.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index 6ec9668..f9c1b72 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -642,9 +642,11 @@ getBinOpsForFactorization(Instruction::BinaryOps TopOpcode, BinaryOperator *Op,
RHS = Op->getOperand(1);
if (TopOpcode == Instruction::Add || TopOpcode == Instruction::Sub) {
Constant *C;
- if (match(Op, m_Shl(m_Value(), m_Constant(C)))) {
+ if (match(Op, m_Shl(m_Value(), m_ImmConstant(C)))) {
// X << C --> X * (1 << C)
- RHS = ConstantExpr::getShl(ConstantInt::get(Op->getType(), 1), C);
+ RHS = ConstantFoldBinaryInstruction(
+ Instruction::Shl, ConstantInt::get(Op->getType(), 1), C);
+ assert(RHS && "Constant folding of immediate constants failed");
return Instruction::Mul;
}
// TODO: We can add other conversions e.g. shr => div etc.