match.pd (sinh (x) / cosh (x)): New simplification rule.
authorRafael Tsuha <rafael.tsuha@usp.br>
Fri, 4 Oct 2019 18:34:29 +0000 (18:34 +0000)
committerJeff Law <law@gcc.gnu.org>
Fri, 4 Oct 2019 18:34:29 +0000 (12:34 -0600)
        * match.pd (sinh (x) / cosh (x)): New simplification rule.

        * gcc.dg/sinhovercosh-1.c: New test.

From-SVN: r276595

gcc/ChangeLog
gcc/match.pd
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/sinhovercosh-1.c [new file with mode: 0644]

index a013d86..6da73b6 100644 (file)
@@ -1,3 +1,7 @@
+2019-10-04  Rafael Tsuha  <rafael.tsuha@usp.br>
+
+        * match.pd (sinh (x) / cosh (x)): New simplification rule.
+
 2019-10-04  Martin Jambor  <mjambor@suse.cz>
 
        * tree-ssa-forwprop.c (simplify_builtin_call): Set gimple call
index 23ce376..9bd5f3e 100644 (file)
@@ -4922,6 +4922,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   (rdiv (SIN:s @0) (COS:s @0))
    (TAN @0))
 
+ /* Simplify sinh(x) / cosh(x) -> tanh(x). */
+ (simplify
+  (rdiv (SINH:s @0) (COSH:s @0))
+   (TANH @0))
+
  /* Simplify cos(x) / sin(x) -> 1 / tan(x). */
  (simplify
   (rdiv (COS:s @0) (SIN:s @0))
index 68ca51e..4248c81 100644 (file)
@@ -1,3 +1,7 @@
+2019-10-04  Rafael Tsuha  <rafael.tsuha@usp.br>
+
+        * gcc.dg/sinhovercosh-1.c: New test.
+
 2019-10-04  Joseph Myers  <joseph@codesourcery.com>
 
        * gcc.dg/c11-builtins-1.c, gcc.dg/c2x-builtins-1.c,
diff --git a/gcc/testsuite/gcc.dg/sinhovercosh-1.c b/gcc/testsuite/gcc.dg/sinhovercosh-1.c
new file mode 100644 (file)
index 0000000..7e51072
--- /dev/null
@@ -0,0 +1,45 @@
+/* { dg-do compile } */
+/* { dg-options "-Ofast -fdump-tree-optimized" } */
+
+extern float sinhf (float);
+extern float coshf (float);
+extern float tanhf (float);
+extern float sqrtf (float);
+extern double sinh (double);
+extern double cosh (double);
+extern double sqrt (double);
+extern double tanh (double);
+extern long double sinhl (long double);
+extern long double coshl (long double);
+extern long double tanhl (long double);
+extern long double sqrtl (long double);
+
+double __attribute__ ((noinline))
+sinhovercosh_ (double x)
+{
+  return sinh (x) / cosh (x);
+}
+
+float __attribute__ ((noinline))
+sinhfovercoshf_(float x)
+{
+  return sinhf (x) / coshf (x);
+}
+
+long double __attribute__ ((noinline))
+sinhlovercoshl_ (long double x)
+{
+  return sinhl (x) / coshl (x);
+}
+
+/* There must be no calls to sinh, cosh, or atanh */
+/* {dg-final { scan-tree-dump-not "sinh " "optimized" } } */
+/* {dg-final { scan-tree-dump-not "cosh " "optimized" } } */
+/* {dg-final { scan-tree-dump-not "sinfh " "optimized" } } */
+/* {dg-final { scan-tree-dump-not "cosfh " "optimized" } } */
+/* {dg-final { scan-tree-dump-not "sinlh " "optimized" } } */
+/* {dg-final { scan-tree-dump-not "coslh " "optimized" } } */
+/* {dg-final { scan-tree-dump-times "tanh " "1" "optimized" }} */
+/* {dg-final { scan-tree-dump-times "tanhl " "1" "optimized" }} */
+/* {dg-final { scan-tree-dump-times "tanhf " "1" "optimized" }} */
+