From 2066f7951cc4f0b23ddff5abfd2ad2ea4ee90fff Mon Sep 17 00:00:00 2001 From: Rafael Tsuha Date: Fri, 4 Oct 2019 18:34:29 +0000 Subject: [PATCH] match.pd (sinh (x) / cosh (x)): New simplification rule. * match.pd (sinh (x) / cosh (x)): New simplification rule. * gcc.dg/sinhovercosh-1.c: New test. From-SVN: r276595 --- gcc/ChangeLog | 4 +++ gcc/match.pd | 5 +++ gcc/testsuite/ChangeLog | 4 +++ gcc/testsuite/gcc.dg/sinhovercosh-1.c | 45 +++++++++++++++++++++++++++ 4 files changed, 58 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/sinhovercosh-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a013d86da07..6da73b6f57e 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,7 @@ +2019-10-04 Rafael Tsuha + + * match.pd (sinh (x) / cosh (x)): New simplification rule. + 2019-10-04 Martin Jambor * tree-ssa-forwprop.c (simplify_builtin_call): Set gimple call diff --git a/gcc/match.pd b/gcc/match.pd index 23ce376802f..9bd5f3e6475 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -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)) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 68ca51e824b..4248c81ad12 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2019-10-04 Rafael Tsuha + + * gcc.dg/sinhovercosh-1.c: New test. + 2019-10-04 Joseph Myers * 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 index 00000000000..7e510727af8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/sinhovercosh-1.c @@ -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" }} */ + -- 2.30.2