This patch simplifies the function tanh (x) * cosh (x) -> sinh (x).
This rule is derived from the relationship between hyperbolic
functions.
I ran the tests and gfortran.dg/pr79966.f90 failed, but this failure
is unrelated to the patch (see
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88711 for more
information). My architecture is x86_64.
gcc/ChangeLog:
2019-01-30 Bárbara Fernandes <[email protected]>
* match.pd (tanh (x) * cosh (x)): New simplification rule.
gcc/testsuite/ChangeLog:
2019-01-30 Bárbara Fernandes <[email protected]>
* tanhtimescosh.c: New test.
Index: gcc/match.pd
===================================================================
--- gcc/match.pd (revision 268384)
+++ gcc/match.pd (working copy)
@@ -4545,6 +4545,11 @@
&& ! HONOR_INFINITIES (@0))
(rdiv { build_one_cst (type); } (COS @0))))
+ /* Simplify tanh (x) * cosh (x) -> sinh (x). */
+ (simplify
+ (mult:c (TANH:s @0) (COSH:s @0))
+ (SINH @0))
+
/* Simplify pow(x,y) * pow(x,z) -> pow(x,y+z). */
(simplify
(mult (POW:s @0 @1) (POW:s @0 @2))
Index: gcc/testsuite/gcc.dg/tanhtimescosh.c
===================================================================
--- gcc/testsuite/gcc.dg/tanhtimescosh.c (nonexistent)
+++ gcc/testsuite/gcc.dg/tanhtimescosh.c (working copy)
@@ -0,0 +1,38 @@
+/* { dg-do compile } */
+/* { dg-options "-Ofast -fdump-tree-optimized" } */
+
+extern float coshf (float);
+extern float tanhf (float);
+extern double cosh (double);
+extern double tanh (double);
+extern long double coshl (long double);
+extern long double tanhl (long double);
+
+double __attribute__ ((noinline))
+sinh_ (double x)
+{
+ return tanh (x) * cosh (x);
+}
+
+float __attribute__ ((noinline))
+sinhf_(float x)
+{
+ return tanhf (x) * coshf (x);
+}
+
+long double __attribute__ ((noinline))
+sinhl_ (long double x)
+{
+ return tanhl (x) * coshl (x);
+}
+
+/* There must be no calls to cosh, or tanh */
+/* {dg-final { scan-tree-dump-not "cosh " "optimized" } } */
+/* {dg-final { scan-tree-dump-not "tanh " "optimized" }} */
+/* {dg-final { scan-tree-dump-not "coshf " "optimized" } } */
+/* {dg-final { scan-tree-dump-not "tanhf " "optimized" }} */
+/* {dg-final { scan-tree-dump-not "coshl " "optimized" } } */
+/* {dg-final { scan-tree-dump-not "tanhl " "optimized" }} */
+/* {dg-final { scan-tree-dump-times "sinh " "1" "optimized" }} */
+/* {dg-final { scan-tree-dump-times "sinhf " "1" "optimized" }} */
+/* {dg-final { scan-tree-dump-times "sinhl " "1" "optimized" }} */