diff options
author | Nikita Popov <npopov@redhat.com> | 2024-06-18 16:57:11 +0200 |
---|---|---|
committer | Nikita Popov <npopov@redhat.com> | 2024-06-18 16:58:11 +0200 |
commit | 534e3ad08b0b9773aceaef82f1282fd5bd8c43e6 (patch) | |
tree | eaaa272e595be66e297437dcf72dff4b176881e0 | |
parent | ffc31d3221e2ebe1f5b1e5c846dcde27cb326616 (diff) | |
download | llvm-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.cpp | 6 |
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. |