Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@kshitijvp
Copy link
Contributor

Fixes #173706

@llvmbot llvmbot added llvm:instcombine Covers the InstCombine, InstSimplify and AggressiveInstCombine passes llvm:transforms labels Dec 27, 2025
@llvmbot
Copy link
Member

llvmbot commented Dec 27, 2025

@llvm/pr-subscribers-llvm-transforms

Author: Kshitij Paranjape (kshitijvp)

Changes

Fixes llvm/llvm-project#173706


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

1 Files Affected:

  • (added) llvm/test/Transforms/InstCombine/hyperbolic-functions.ll (+84)
diff --git a/llvm/test/Transforms/InstCombine/hyperbolic-functions.ll b/llvm/test/Transforms/InstCombine/hyperbolic-functions.ll
new file mode 100644
index 0000000000000..0d5631152057f
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/hyperbolic-functions.ll
@@ -0,0 +1,84 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -passes=instcombine -S | FileCheck %s
+
+define double @src_cosh(double noundef %x) {
+; CHECK-LABEL: @src_cosh(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[FNEG:%.*]] = fneg double [[X:%.*]]
+; CHECK-NEXT:    [[TMP0:%.*]] = tail call double @llvm.cosh.f64(double [[FNEG]])
+; CHECK-NEXT:    ret double [[TMP0]]
+;
+entry:
+  %fneg = fneg double %x
+  %1 = tail call double @llvm.cosh.f64(double %fneg)
+  ret double %1
+}
+
+define double @tgt_cosh(double noundef %x) {
+; CHECK-LABEL: @tgt_cosh(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[TMP0:%.*]] = tail call double @llvm.cosh.f64(double [[X:%.*]])
+; CHECK-NEXT:    ret double [[TMP0]]
+;
+entry:
+  %1 = tail call double @llvm.cosh.f64(double %x)
+  ret double %1
+}
+
+declare double @llvm.cosh.f64(double)
+
+define double @src_tanh(double noundef %x) {
+; CHECK-LABEL: @src_tanh(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[FNEG:%.*]] = fneg double [[X:%.*]]
+; CHECK-NEXT:    [[TMP0:%.*]] = tail call double @llvm.tanh.f64(double [[FNEG]])
+; CHECK-NEXT:    [[FNEG1:%.*]] = fneg double [[TMP0]]
+; CHECK-NEXT:    ret double [[FNEG1]]
+;
+entry:
+  %fneg = fneg double %x
+  %0 = tail call double @llvm.tanh.f64(double %fneg)
+  %fneg1 = fneg double %0
+  ret double %fneg1
+}
+
+define double @tgt_tanh(double noundef %x) {
+; CHECK-LABEL: @tgt_tanh(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[TMP0:%.*]] = tail call double @llvm.tanh.f64(double [[X:%.*]])
+; CHECK-NEXT:    ret double [[TMP0]]
+;
+entry:
+  %0 = tail call double @llvm.tanh.f64(double %x)
+  ret double %0
+}
+
+declare double @llvm.tanh.f64(double)
+
+define double @src_sinh(double noundef %x) {
+; CHECK-LABEL: @src_sinh(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[FNEG:%.*]] = fneg double [[X:%.*]]
+; CHECK-NEXT:    [[TMP0:%.*]] = tail call double @llvm.sinh.f64(double [[FNEG]])
+; CHECK-NEXT:    [[FNEG1:%.*]] = fneg double [[TMP0]]
+; CHECK-NEXT:    ret double [[FNEG1]]
+;
+entry:
+  %fneg = fneg double %x
+  %0 = tail call double @llvm.sinh.f64(double %fneg)
+  %fneg1 = fneg double %0
+  ret double %fneg1
+}
+
+declare double @llvm.sinh.f64(double)
+
+define double @tgt_sinh(double noundef %x) {
+; CHECK-LABEL: @tgt_sinh(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[TMP0:%.*]] = tail call double @llvm.sinh.f64(double [[X:%.*]])
+; CHECK-NEXT:    ret double [[TMP0]]
+;
+entry:
+  %0 = tail call double @llvm.sinh.f64(double %x)
+  ret double %0
+}

@kshitijvp kshitijvp changed the title Precommit Tests Add support for Instruction combining of hyperbolic functions Dec 27, 2025
Added pattern matching for all hyperbolic functions
with the argument '-x' and to replace it with the
equivalent hyperbolic function with argument x.
@kshitijvp kshitijvp requested a review from nikic as a code owner December 27, 2025 16:54
@nikic nikic added the floating-point Floating-point math label Dec 27, 2025
@nikic nikic requested review from arsenm and dtcxzyw December 27, 2025 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

floating-point Floating-point math llvm:instcombine Covers the InstCombine, InstSimplify and AggressiveInstCombine passes llvm:transforms

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handle f(-x)=f(x) for cosh and f(-x)=-f(x) for sinh and tanh

3 participants