[llvm] [ConstantantFolding] Add support for `sinh` and `cosh` intrinsics constant folding (PR #132671)

via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 23 22:06:42 PDT 2025


https://github.com/el-ev created https://github.com/llvm/llvm-project/pull/132671

Closes #132503.

>From f605d85137ca9a0569d12220d64bb1689c1d7f0c Mon Sep 17 00:00:00 2001
From: Iris Shi <0.0 at owo.li>
Date: Mon, 24 Mar 2025 13:00:39 +0800
Subject: [PATCH] [ConstantantFolding] Add support for `sinh` and `cosh`
 intrinsics in constant folding

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

diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index b0ba25c3c16ac..dc905ab03e861 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -1651,6 +1651,8 @@ bool llvm::canConstantFoldCallTo(const CallBase *Call, const Function *F) {
   case Intrinsic::sin:
   case Intrinsic::cos:
   case Intrinsic::sincos:
+  case Intrinsic::sinh:
+  case Intrinsic::cosh:
   case Intrinsic::pow:
   case Intrinsic::powi:
   case Intrinsic::ldexp:
@@ -2513,6 +2515,10 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
         return ConstantFoldFP(sin, APF, Ty);
       case Intrinsic::cos:
         return ConstantFoldFP(cos, APF, Ty);
+      case Intrinsic::sinh:
+        return ConstantFoldFP(sinh, APF, Ty);
+      case Intrinsic::cosh:
+        return ConstantFoldFP(cosh, APF, Ty);
       case Intrinsic::sqrt:
         return ConstantFoldFP(sqrt, APF, Ty);
       case Intrinsic::amdgcn_cos:



More information about the llvm-commits mailing list