From: Giuliano Belinassi Date: Thu, 29 Nov 2018 15:32:30 +0000 (+0000) Subject: match.pd (sinh (atanh (x))): New simplification rules. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=4aff6d17446ade686d1746716906e8b32499a619;p=gcc.git match.pd (sinh (atanh (x))): New simplification rules. * match.pd (sinh (atanh (x))): New simplification rules. (cosh (atanh (x))): Likewise. * gcc.dg/sinhatanh-1.c: New test. * gcc.dg/sinhatanh-2.c: New test. * gcc.dg/sinhatanh-3.c: New test. From-SVN: r266625 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 928c37c6b2e..7a98670c60f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2018-11-29 Giuliano Belinassi + + * match.pd (sinh (atanh (x))): New simplification rules. + (cosh (atanh (x))): Likewise. + 2018-11-29 Jakub Jelinek PR target/54700 diff --git a/gcc/match.pd b/gcc/match.pd index 6c267510adf..698d27fe777 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -4370,6 +4370,25 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (rdiv { t_one; } (sqrts (plus (mult @0 @0) { t_one; }))) (copysigns { t_zero; } @0)))))) + (if (!flag_errno_math) + /* Simplify sinh(atanh(x)) -> x / sqrt((1 - x)*(1 + x)). */ + (for sinhs (SINH) + atanhs (ATANH) + sqrts (SQRT) + (simplify + (sinhs (atanhs:s @0)) + (with { tree t_one = build_one_cst (type); } + (rdiv @0 (sqrts (mult (minus { t_one; } @0) (plus { t_one; } @0))))))) + + /* Simplify cosh(atanh(x)) -> 1 / sqrt((1 - x)*(1 + x)) */ + (for coshs (COSH) + atanhs (ATANH) + sqrts (SQRT) + (simplify + (coshs (atanhs:s @0)) + (with { tree t_one = build_one_cst (type); } + (rdiv { t_one; } (sqrts (mult (minus { t_one; } @0) (plus { t_one; } @0)))))))) + /* cabs(x+0i) or cabs(0+xi) -> abs(x). */ (simplify (CABS (complex:C @0 real_zerop@1)) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index abf89361fbe..a1fb6bdd7ec 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2018-11-29 Giuliano Belinassi + + * gcc.dg/sinhatanh-1.c: New test. + * gcc.dg/sinhatanh-2.c: New test. + * gcc.dg/sinhatanh-3.c: New test. + 2018-11-29 Jakub Jelinek PR target/54700 diff --git a/gcc/testsuite/gcc.dg/sinhatanh-1.c b/gcc/testsuite/gcc.dg/sinhatanh-1.c new file mode 100644 index 00000000000..a76e6833101 --- /dev/null +++ b/gcc/testsuite/gcc.dg/sinhatanh-1.c @@ -0,0 +1,62 @@ +/* { dg-do compile } */ +/* { dg-options "-Ofast -fdump-tree-optimized" } */ + +extern float sinhf (float); +extern float coshf (float); +extern float atanhf (float); +extern float sqrtf (float); +extern double sinh (double); +extern double cosh (double); +extern double atanh (double); +extern double sqrt (double); +extern long double sinhl (long double); +extern long double coshl (long double); +extern long double atanhl (long double); +extern long double sqrtl (long double); + +double __attribute__ ((noinline)) +sinhatanh_ (double x) +{ + return sinh (atanh (x)); +} + +double __attribute__ ((noinline)) +coshatanh_ (double x) +{ + return cosh (atanh (x)); +} + +float __attribute__ ((noinline)) +sinhatanhf_(float x) +{ + return sinhf (atanhf (x)); +} + +float __attribute__ ((noinline)) +coshatanhf_(float x) +{ + return coshf (atanhf (x)); +} + +long double __attribute__ ((noinline)) +sinhatanhl_ (long double x) +{ + return sinhl (atanhl (x)); +} + +long double __attribute__ ((noinline)) +coshatanhl_ (long double x) +{ + return coshl (atanhl (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 "atanh " "optimized" }} */ +/* {dg-final { scan-tree-dump-not "sinfh " "optimized" } } */ +/* {dg-final { scan-tree-dump-not "cosfh " "optimized" } } */ +/* {dg-final { scan-tree-dump-not "atanfh " "optimized" }} */ +/* {dg-final { scan-tree-dump-not "sinlh " "optimized" } } */ +/* {dg-final { scan-tree-dump-not "coslh " "optimized" } } */ +/* {dg-final { scan-tree-dump-not "atanlh " "optimized" }} */ diff --git a/gcc/testsuite/gcc.dg/sinhatanh-2.c b/gcc/testsuite/gcc.dg/sinhatanh-2.c new file mode 100644 index 00000000000..40a9b8b4443 --- /dev/null +++ b/gcc/testsuite/gcc.dg/sinhatanh-2.c @@ -0,0 +1,68 @@ +/* { dg-do compile } */ +/* { dg-options "-Ofast -fdump-tree-optimized" } */ + +extern float sinhf (float); +extern float coshf (float); +extern float atanhf (float); +extern float sqrtf (float); +extern double sinh (double); +extern double cosh (double); +extern double atanh (double); +extern double sqrt (double); +extern long double sinhl (long double); +extern long double coshl (long double); +extern long double atanhl (long double); +extern long double sqrtl (long double); + +float __attribute__ ((noinline)) +coshatanhf_(float x) +{ + float atg = atanhf(x); + return coshf(atg) + atg; +} + +double __attribute__ ((noinline)) +cosatan_(double x) +{ + double atg = atanh(x); + return cosh(atg) + atg; +} + +long double __attribute__ ((noinline)) +cosatanl_(long double x) +{ + long double atg = atanhl(x); + return coshl(atg) + atg; +} + +float __attribute__ ((noinline)) +sinatanf_(float x) +{ + float atg = atanhf(x); + return sinhf(atg) + atg; +} + +double __attribute__ ((noinline)) +sinatan_(double x) +{ + double atg = atanh(x); + return sinh(atg) + atg; +} + +long double __attribute__ ((noinline)) +sinatanl_(long double x) +{ + long double atg = atanhl(x); + return sinhl(atg) + atg; +} + +/* There should be calls to sinh, cosh and atanh */ +/* { dg-final { scan-tree-dump "cosh " "optimized" } } */ +/* { dg-final { scan-tree-dump "sinh " "optimized" } } */ +/* { dg-final { scan-tree-dump "atanh " "optimized" } } */ +/* { dg-final { scan-tree-dump "coshf " "optimized" } } */ +/* { dg-final { scan-tree-dump "sinhf " "optimized" } } */ +/* { dg-final { scan-tree-dump "atanhf " "optimized" } } */ +/* { dg-final { scan-tree-dump "coshl " "optimized" } } */ +/* { dg-final { scan-tree-dump "sinhl " "optimized" } } */ +/* { dg-final { scan-tree-dump "atanhl " "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/sinhatanh-3.c b/gcc/testsuite/gcc.dg/sinhatanh-3.c new file mode 100644 index 00000000000..32e2de5a043 --- /dev/null +++ b/gcc/testsuite/gcc.dg/sinhatanh-3.c @@ -0,0 +1,62 @@ +/* { dg-do compile } */ +/* { dg-options "-Ofast -fmath-errno -fdump-tree-optimized" } */ + +extern float sinhf (float); +extern float coshf (float); +extern float atanhf (float); +extern float sqrtf (float); +extern double sinh (double); +extern double cosh (double); +extern double atanh (double); +extern double sqrt (double); +extern long double sinhl (long double); +extern long double coshl (long double); +extern long double atanhl (long double); +extern long double sqrtl (long double); + +double __attribute__ ((noinline)) +sinhatanh_ (double x) +{ + return sinh (atanh (x)); +} + +double __attribute__ ((noinline)) +coshatanh_ (double x) +{ + return cosh (atanh (x)); +} + +float __attribute__ ((noinline)) +sinhatanhf_(float x) +{ + return sinhf (atanhf (x)); +} + +float __attribute__ ((noinline)) +coshatanhf_(float x) +{ + return coshf (atanhf (x)); +} + +long double __attribute__ ((noinline)) +sinhatanhl_ (long double x) +{ + return sinhl (atanhl (x)); +} + +long double __attribute__ ((noinline)) +coshatanhl_ (long double x) +{ + return coshl (atanhl (x)); +} + +/* There should be calls to sinh, cosh and atanh */ +/* { dg-final { scan-tree-dump "cosh " "optimized" } } */ +/* { dg-final { scan-tree-dump "sinh " "optimized" } } */ +/* { dg-final { scan-tree-dump "atanh " "optimized" } } */ +/* { dg-final { scan-tree-dump "coshf " "optimized" } } */ +/* { dg-final { scan-tree-dump "sinhf " "optimized" } } */ +/* { dg-final { scan-tree-dump "atanhf " "optimized" } } */ +/* { dg-final { scan-tree-dump "coshl " "optimized" } } */ +/* { dg-final { scan-tree-dump "sinhl " "optimized" } } */ +/* { dg-final { scan-tree-dump "atanhl " "optimized" } } */