public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/autopar_devel] optimize tanh(x) / sinh (x) to 1/ cosh (x)
@ 2020-08-22 21:57 Giuliano Belinassi
  0 siblings, 0 replies; only message in thread
From: Giuliano Belinassi @ 2020-08-22 21:57 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:601c68c6112d49fe615872a2cba5cb8c3eff0bc5

commit 601c68c6112d49fe615872a2cba5cb8c3eff0bc5
Author: Vitor Guidi <vitor.guidi@usp.br>
Date:   Wed Jun 3 17:01:21 2020 -0600

    optimize tanh(x) / sinh (x) to 1/ cosh (x)
    
    gcc/
            * match.pd (tanh/sinh -> 1/cosh): New simplification.
    
    gcc/testsuite
    
            * gcc.dg/tanhbysinh.c: New testcase.

Diff:
---
 gcc/match.pd                      |  5 +++++
 gcc/testsuite/gcc.dg/tanhbysinh.c | 40 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+)

diff --git a/gcc/match.pd b/gcc/match.pd
index 33ee1a920bf..2b8c37e690e 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -5229,6 +5229,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   (rdiv (SINH:s @0) (COSH:s @0))
    (TANH @0))
 
+ /* Simplify tanh (x) / sinh (x) -> 1.0 / cosh (x). */
+ (simplify
+   (rdiv (TANH:s @0) (SINH:s @0))
+   (rdiv {build_one_cst (type);} (COSH @0)))
+
  /* Simplify cos(x) / sin(x) -> 1 / tan(x). */
  (simplify
   (rdiv (COS:s @0) (SIN:s @0))
diff --git a/gcc/testsuite/gcc.dg/tanhbysinh.c b/gcc/testsuite/gcc.dg/tanhbysinh.c
new file mode 100644
index 00000000000..fde72c2f93b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tanhbysinh.c
@@ -0,0 +1,40 @@
+/* { dg-do compile } */
+/* { dg-options "-Ofast -fdump-tree-optimized" } */
+
+extern float sinhf (float);
+extern float tanhf (float);
+extern double sinh (double);
+extern double tanh (double);
+extern long double sinhl (long double);
+extern long double tanhl (long double);
+
+double __attribute__ ((noinline))
+tanhbysinh_ (double x)
+{
+    return tanh (x) / sinh (x);
+}
+
+float __attribute__ ((noinline))
+tanhbysinhf_ (float x)
+{
+    return tanhf (x) / sinhf (x);
+}
+
+long double __attribute__ ((noinline))
+tanhbysinhl_ (long double x)
+{
+    return tanhl (x) / sinhl (x);
+}
+
+
+/* There must be no calls to sinh or atanh */
+/* There must be calls to cosh */
+/* {dg-final { scan-tree-dump-not "sinh " "optimized" } } */
+/* {dg-final { scan-tree-dump-not "tanh " "optimized" }} */
+/* {dg-final { scan-tree-dump-not "sinhf " "optimized" } } */
+/* {dg-final { scan-tree-dump-not "tanhf " "optimized" }} */
+/* {dg-final { scan-tree-dump-not "sinhl " "optimized" } } */
+/* {dg-final { scan-tree-dump-not "tanhl " "optimized" }} */
+/* { dg-final { scan-tree-dump "cosh " "optimized" } } */
+/* { dg-final { scan-tree-dump "coshf " "optimized" } } */
+/* { dg-final { scan-tree-dump "coshl " "optimized" } } */
\ No newline at end of file


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-08-22 21:57 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-22 21:57 [gcc/devel/autopar_devel] optimize tanh(x) / sinh (x) to 1/ cosh (x) Giuliano Belinassi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).