[llvm] 76e889d - [InstCombine] Avoid use of ConstantExpr::getShl()

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


Author: Nikita Popov
Date: 2024-06-18T16:29:40+02:00
New Revision: 76e889d3b024c187880187b1a14fe9ab0ea7aa36

URL: https://github.com/llvm/llvm-project/commit/76e889d3b024c187880187b1a14fe9ab0ea7aa36
DIFF: https://github.com/llvm/llvm-project/commit/76e889d3b024c187880187b1a14fe9ab0ea7aa36.diff

LOG: [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.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
index ca1b1921404d8..8fcb3544f682a 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
@@ -223,11 +223,13 @@ Instruction *InstCombinerImpl::visitMul(BinaryOperator &I) {
     Value *NewOp;
     Constant *C1, *C2;
     const APInt *IVal;
-    if (match(&I, m_Mul(m_Shl(m_Value(NewOp), m_Constant(C2)),
-                        m_Constant(C1))) &&
+    if (match(&I, m_Mul(m_Shl(m_Value(NewOp), m_ImmConstant(C2)),
+                        m_ImmConstant(C1))) &&
         match(C1, m_APInt(IVal))) {
       // ((X << C2)*C1) == (X * (C1 << C2))
-      Constant *Shl = ConstantExpr::getShl(C1, C2);
+      Constant *Shl =
+          ConstantFoldBinaryOpOperands(Instruction::Shl, C1, C2, DL);
+      assert(Shl && "Constant folding of immediate constants failed");
       BinaryOperator *Mul = cast<BinaryOperator>(I.getOperand(0));
       BinaryOperator *BO = BinaryOperator::CreateMul(NewOp, Shl);
       if (HasNUW && Mul->hasNoUnsignedWrap())


        


More information about the llvm-commits mailing list