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

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


Author: Nikita Popov
Date: 2024-06-18T16:32:49+02:00
New Revision: d314cf241d61410fa4bd925c1c4355e87209da17

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

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

Use IRBuilder instead, as we don't care about the return type
here. Use ImmConstant to ensure that constant folding will
succeed.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp b/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp
index ed2a98ba4ae40..b3426562a4d87 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp
@@ -391,12 +391,12 @@ std::array<Value *, 2> Negator::getSortedOperandsOfBinOp(Instruction *I) {
       return Builder.CreateShl(NegOp0, I->getOperand(1), I->getName() + ".neg",
                                /* HasNUW */ false, IsNSW);
     // Otherwise, `shl %x, C` can be interpreted as `mul %x, 1<<C`.
-    auto *Op1C = dyn_cast<Constant>(I->getOperand(1));
-    if (!Op1C || !IsTrulyNegation)
+    Constant *Op1C;
+    if (!match(I->getOperand(1), m_ImmConstant(Op1C)) || !IsTrulyNegation)
       return nullptr;
     return Builder.CreateMul(
         I->getOperand(0),
-        ConstantExpr::getShl(Constant::getAllOnesValue(Op1C->getType()), Op1C),
+        Builder.CreateShl(Constant::getAllOnesValue(Op1C->getType()), Op1C),
         I->getName() + ".neg", /* HasNUW */ false, IsNSW);
   }
   case Instruction::Or: {


        


More information about the llvm-commits mailing list