Skip to content

[ConstantFolding] Add support for sinh and cosh intrinsics in constant folding #132671

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 3, 2025

Conversation

el-ev
Copy link
Member

@el-ev el-ev commented Mar 24, 2025

Closes #132503.

@llvmbot llvmbot added the llvm:analysis Includes value tracking, cost tables and constant folding label Mar 24, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 24, 2025

@llvm/pr-subscribers-llvm-transforms

@llvm/pr-subscribers-llvm-analysis

Author: Iris (el-ev)

Changes

Closes #132503.


Full diff: https://github.com/llvm/llvm-project/pull/132671.diff

1 Files Affected:

  • (modified) llvm/lib/Analysis/ConstantFolding.cpp (+6)
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:

@llvmbot llvmbot added llvm:instcombine Covers the InstCombine, InstSimplify and AggressiveInstCombine passes llvm:transforms labels Mar 25, 2025
@dtcxzyw dtcxzyw requested review from arsenm and nikic March 25, 2025 01:44
Copy link

github-actions bot commented Mar 25, 2025

⚠️ undef deprecator found issues in your code. ⚠️

You can test this locally with the following command:
git diff -U0 --pickaxe-regex -S '([^a-zA-Z0-9#_-]undef[^a-zA-Z0-9_-]|UndefValue::get)' 'HEAD~1' HEAD llvm/test/Transforms/InstSimplify/ConstProp/sinh-cosh-intrinsics.ll llvm/lib/Analysis/ConstantFolding.cpp

The following files introduce new uses of undef:

  • llvm/test/Transforms/InstSimplify/ConstProp/sinh-cosh-intrinsics.ll

Undef is now deprecated and should only be used in the rare cases where no replacement is possible. For example, a load of uninitialized memory yields undef. You should use poison values for placeholders instead.

In tests, avoid using undef and having tests that trigger undefined behavior. If you need an operand with some unimportant value, you can add a new argument to the function and use that instead.

For example, this is considered a bad practice:

define void @fn() {
  ...
  br i1 undef, ...
}

Please use the following instead:

define void @fn(i1 %cond) {
  ...
  br i1 %cond, ...
}

Please refer to the Undefined Behavior Manual for more information.

@el-ev el-ev force-pushed the constant_sinh_cosh branch 2 times, most recently from 0e1681e to 6e6cb21 Compare March 25, 2025 07:05
@el-ev el-ev force-pushed the constant_sinh_cosh branch from 6e6cb21 to be4d06c Compare March 25, 2025 07:50
@el-ev el-ev changed the title [ConstantantFolding] Add support for sinh and cosh intrinsics constant folding [ConstantFolding] Add support for sinh and cosh intrinsics in constant folding Mar 26, 2025
@el-ev
Copy link
Member Author

el-ev commented Apr 1, 2025

ping

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nikic nikic merged commit 3295970 into llvm:main Apr 3, 2025
10 of 11 checks passed
@el-ev el-ev deleted the constant_sinh_cosh branch April 3, 2025 06:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
llvm:analysis Includes value tracking, cost tables and constant folding llvm:instcombine Covers the InstCombine, InstSimplify and AggressiveInstCombine passes llvm:transforms
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistency in sinh(const), cosh(const), and tanh(const) optimizations with -ffast-math
4 participants