[llvm] e918127 - [InstSimplify] Avoid ConstantExpr::getIntegerCast() (NFCI)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 1 03:16:07 PDT 2023


Author: Nikita Popov
Date: 2023-11-01T11:15:18+01:00
New Revision: e91812792a106831eb0f3d84cbdeb759e42302d4

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

LOG: [InstSimplify] Avoid ConstantExpr::getIntegerCast() (NFCI)

This always works on a constant integer or integer splat, so the
constant fold here should always succeed.

Added: 
    

Modified: 
    llvm/lib/Analysis/InstructionSimplify.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index f0e60c9a2dac6fd..fe3d7d679129fd5 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -895,7 +895,8 @@ static Value *simplifySubInst(Value *Op0, Value *Op1, bool IsNSW, bool IsNUW,
   // Variations on GEP(base, I, ...) - GEP(base, i, ...) -> GEP(null, I-i, ...).
   if (match(Op0, m_PtrToInt(m_Value(X))) && match(Op1, m_PtrToInt(m_Value(Y))))
     if (Constant *Result = computePointerDifference(Q.DL, X, Y))
-      return ConstantExpr::getIntegerCast(Result, Op0->getType(), true);
+      return ConstantFoldIntegerCast(Result, Op0->getType(), /*IsSigned*/ true,
+                                     Q.DL);
 
   // i1 sub -> xor.
   if (MaxRecurse && Op0->getType()->isIntOrIntVectorTy(1))


        


More information about the llvm-commits mailing list