[llvm] 25af06f - [InstCombine] Avoid use of FP cast constant expressions (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 6 06:22:42 PST 2023


Author: Nikita Popov
Date: 2023-11-06T15:22:33+01:00
New Revision: 25af06fd7a6b2a9def447a90dc10b73424a31600

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

LOG: [InstCombine] Avoid use of FP cast constant expressions (NFC)

Use the constant folding API instead. As we're working on plain
ConstantFP, this should always succeed.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
index 87181650e758729..22fd3edc39acb03 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -1841,10 +1841,11 @@ Instruction *InstCombinerImpl::visitFAdd(BinaryOperator &I) {
     // instcombined.
     if (ConstantFP *CFP = dyn_cast<ConstantFP>(RHS))
       if (IsValidPromotion(FPType, LHSIntVal->getType())) {
-        Constant *CI =
-          ConstantExpr::getFPToSI(CFP, LHSIntVal->getType());
+        Constant *CI = ConstantFoldCastOperand(Instruction::FPToSI, CFP,
+                                               LHSIntVal->getType(), DL);
         if (LHSConv->hasOneUse() &&
-            ConstantExpr::getSIToFP(CI, I.getType()) == CFP &&
+            ConstantFoldCastOperand(Instruction::SIToFP, CI, I.getType(), DL) ==
+                CFP &&
             willNotOverflowSignedAdd(LHSIntVal, CI, I)) {
           // Insert the new integer add.
           Value *NewAdd = Builder.CreateNSWAdd(LHSIntVal, CI, "addconv");


        


More information about the llvm-commits mailing list