[llvm] 534e3ad - [InstCombine] Avoid use of ConstantExpr::getShl()

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 18 07:58:18 PDT 2024


Author: Nikita Popov
Date: 2024-06-18T16:58:11+02:00
New Revision: 534e3ad08b0b9773aceaef82f1282fd5bd8c43e6

URL: https://github.com/llvm/llvm-project/commit/534e3ad08b0b9773aceaef82f1282fd5bd8c43e6
DIFF: https://github.com/llvm/llvm-project/commit/534e3ad08b0b9773aceaef82f1282fd5bd8c43e6.diff

LOG: [InstCombine] Avoid use of ConstantExpr::getShl()

Use the constant folding API instead. Use ImmConstant to ensure
folding succeeds.

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index 6ec9668b2bb3a..f9c1b72e5ef73 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.


        


More information about the llvm-commits mailing list