[llvm] [ConstantFolding] Fold expm1/expm1f with constant arguments (PR #196717)

via llvm-commits llvm-commits at lists.llvm.org
Sat May 9 05:23:19 PDT 2026


https://github.com/YogeshFebyani created https://github.com/llvm/llvm-project/pull/196717

Added a fix for  #123761 

>From 2acc1d14a17deac86a0960ab733bd37274a8e9b0 Mon Sep 17 00:00:00 2001
From: Yogesh <cs25mtech12014 at iith.ac.in>
Date: Sat, 9 May 2026 17:46:35 +0530
Subject: [PATCH] added a fix for issue#123761

---
 llvm/lib/Analysis/ConstantFolding.cpp | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index e035cd1bc1ac0..e3c0ef5584847 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -2126,7 +2126,8 @@ bool llvm::canConstantFoldCallTo(const CallBase *Call, const Function *F) {
            Name == "cosh" || Name == "coshf";
   case 'e':
     return Name == "exp" || Name == "expf" || Name == "exp2" ||
-           Name == "exp2f" || Name == "erf" || Name == "erff";
+           Name == "exp2f" || Name == "erf" || Name == "erff" 
+            ||  Name == "expm1" || Name == "expm1f";
   case 'f':
     return Name == "fabs" || Name == "fabsf" ||
            Name == "floor" || Name == "floorf" ||
@@ -3059,6 +3060,11 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
       if (TLI->has(Func))
         return ConstantFoldFP(exp, APF, Ty);
       break;
+    case LibFunc_expm1:
+    case LibFunc_expm1f:
+      if (TLI->has(Func))
+        return ConstantFoldFP(expm1, APF, Ty);
+      break;
     case LibFunc_exp2:
     case LibFunc_exp2f:
     case LibFunc_exp2_finite:
@@ -4789,6 +4795,9 @@ bool llvm::isMathLibCallNoop(const CallBase *Call,
         if (OpC->getType()->isFloatTy())
           return !(Op < APFloat(-149.0f) || Op > APFloat(127.0f));
         break;
+      case LibFunc_expm1:
+      case LibFunc_expm1f:
+        return true;
 
       case LibFunc_sinl:
       case LibFunc_sin:



More information about the llvm-commits mailing list