[llvm] e408f70 - [LSR] Avoid use of ConstantExpr::getCast() (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 2 01:48:14 PDT 2023


Author: Nikita Popov
Date: 2023-11-02T09:48:04+01:00
New Revision: e408f705240096b3310836fc623256b78709a05f

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

LOG: [LSR] Avoid use of ConstantExpr::getCast() (NFC)

Use the constant folding API instead, which must succeed as we're
working on a ConstantInt.

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
index 9549a9f41fa11ed..6e04f54e13da547 100644
--- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -5546,10 +5546,12 @@ Value *LSRInstance::Expand(const LSRUse &LU, const LSRFixup &LF,
              "a scale at the same time!");
       Constant *C = ConstantInt::getSigned(SE.getEffectiveSCEVType(OpTy),
                                            -(uint64_t)Offset);
-      if (C->getType() != OpTy)
-        C = ConstantExpr::getCast(CastInst::getCastOpcode(C, false,
-                                                          OpTy, false),
-                                  C, OpTy);
+      if (C->getType() != OpTy) {
+        C = ConstantFoldCastOperand(
+            CastInst::getCastOpcode(C, false, OpTy, false), C, OpTy,
+            CI->getModule()->getDataLayout());
+        assert(C && "Cast of ConstantInt should have folded");
+      }
 
       CI->setOperand(1, C);
     }


        


More information about the llvm-commits mailing list