Message ID  CAEFO=4C+BLJYGHNwuCbjdeY2Xj5KJkBeRRCKmSxqTUqwVokkag@mail.gmail.com 

State  New 
Headers  show 
Series 

Related  show 
> On Aug 7, 2018, at 4:00 PM, Giuliano Augusto Faulin Belinassi <giuliano.belinassi@usp.br> wrote: > > Related with bug 86829, but for hyperbolic trigonometric functions. > This patch adds substitution rules to both sinh(tanh(x)) > x / sqrt(1 >  x*x) and cosh(tanh(x)) > 1 / sqrt(1  x*x). Notice that the both > formulas has division by 0, but it causes no harm because 1/(+0) > > +infinity, thus the math is still safe. What about nonIEEE targets that don't have "infinite" in their float representation? paul
That is a good question because I didn't know that such targets exists. Any suggestion? On Tue, Aug 7, 2018 at 5:29 PM, Paul Koning <paulkoning@comcast.net> wrote: > > >> On Aug 7, 2018, at 4:00 PM, Giuliano Augusto Faulin Belinassi <giuliano.belinassi@usp.br> wrote: >> >> Related with bug 86829, but for hyperbolic trigonometric functions. >> This patch adds substitution rules to both sinh(tanh(x)) > x / sqrt(1 >>  x*x) and cosh(tanh(x)) > 1 / sqrt(1  x*x). Notice that the both >> formulas has division by 0, but it causes no harm because 1/(+0) > >> +infinity, thus the math is still safe. > > What about nonIEEE targets that don't have "infinite" in their float representation? > > paul > >
Now I'm puzzled. I don't see how an infinite would show up in the original expression. I don't know hyperbolic functions, so I just constructed a small test program, and the original vs. the substitution you mention are not at all similar. paul > On Aug 7, 2018, at 4:42 PM, Giuliano Augusto Faulin Belinassi <giuliano.belinassi@usp.br> wrote: > > That is a good question because I didn't know that such targets > exists. Any suggestion? > > > On Tue, Aug 7, 2018 at 5:29 PM, Paul Koning <paulkoning@comcast.net> wrote: >> >> >>> On Aug 7, 2018, at 4:00 PM, Giuliano Augusto Faulin Belinassi <giuliano.belinassi@usp.br> wrote: >>> >>> Related with bug 86829, but for hyperbolic trigonometric functions. >>> This patch adds substitution rules to both sinh(tanh(x)) > x / sqrt(1 >>>  x*x) and cosh(tanh(x)) > 1 / sqrt(1  x*x). Notice that the both >>> formulas has division by 0, but it causes no harm because 1/(+0) > >>> +infinity, thus the math is still safe. >> >> What about nonIEEE targets that don't have "infinite" in their float representation? >> >> paul >> >>
Sorry about that. In the email text field I wrote sinh(tanh(x)) and cosh(tanh(x)) where it was supposed to be sinh(atanh(x)) and cosh(atanh(x)), thus I am talking about the inverse hyperbolic tangent function. The patch code and comments are still correct. On Wed, Aug 8, 2018 at 10:58 AM, Paul Koning <paulkoning@comcast.net> wrote: > Now I'm puzzled. > > I don't see how an infinite would show up in the original expression. I don't know hyperbolic functions, so I just constructed a small test program, and the original vs. the substitution you mention are not at all similar. > > paul > > >> On Aug 7, 2018, at 4:42 PM, Giuliano Augusto Faulin Belinassi <giuliano.belinassi@usp.br> wrote: >> >> That is a good question because I didn't know that such targets >> exists. Any suggestion? >> >> >> On Tue, Aug 7, 2018 at 5:29 PM, Paul Koning <paulkoning@comcast.net> wrote: >>> >>> >>>> On Aug 7, 2018, at 4:00 PM, Giuliano Augusto Faulin Belinassi <giuliano.belinassi@usp.br> wrote: >>>> >>>> Related with bug 86829, but for hyperbolic trigonometric functions. >>>> This patch adds substitution rules to both sinh(tanh(x)) > x / sqrt(1 >>>>  x*x) and cosh(tanh(x)) > 1 / sqrt(1  x*x). Notice that the both >>>> formulas has division by 0, but it causes no harm because 1/(+0) > >>>> +infinity, thus the math is still safe. >>> >>> What about nonIEEE targets that don't have "infinite" in their float representation? >>> >>> paul >>> >>> >
Thanks. Ok, so the expressions you gave are undefined for x==1, which says that substituting something that is also undefined for x==1 is permitted. You can argue from "undefined" rather than relying on IEEE features like NaN or infinite. paul > On Aug 8, 2018, at 2:57 PM, Giuliano Augusto Faulin Belinassi <giuliano.belinassi@usp.br> wrote: > > Sorry about that. In the email text field I wrote sinh(tanh(x)) and > cosh(tanh(x)) where it was supposed to be sinh(atanh(x)) and > cosh(atanh(x)), thus I am talking about the inverse hyperbolic tangent > function. The patch code and comments are still correct. > > On Wed, Aug 8, 2018 at 10:58 AM, Paul Koning <paulkoning@comcast.net> wrote: >> Now I'm puzzled. >> >> I don't see how an infinite would show up in the original expression. I don't know hyperbolic functions, so I just constructed a small test program, and the original vs. the substitution you mention are not at all similar. >> >> paul >> >> >>> On Aug 7, 2018, at 4:42 PM, Giuliano Augusto Faulin Belinassi <giuliano.belinassi@usp.br> wrote: >>> >>> That is a good question because I didn't know that such targets >>> exists. Any suggestion? >>> >>> >>> On Tue, Aug 7, 2018 at 5:29 PM, Paul Koning <paulkoning@comcast.net> wrote: >>>> >>>> >>>>> On Aug 7, 2018, at 4:00 PM, Giuliano Augusto Faulin Belinassi <giuliano.belinassi@usp.br> wrote: >>>>> >>>>> Related with bug 86829, but for hyperbolic trigonometric functions. >>>>> This patch adds substitution rules to both sinh(tanh(x)) > x / sqrt(1 >>>>>  x*x) and cosh(tanh(x)) > 1 / sqrt(1  x*x). Notice that the both >>>>> formulas has division by 0, but it causes no harm because 1/(+0) > >>>>> +infinity, thus the math is still safe. >>>> >>>> What about nonIEEE targets that don't have "infinite" in their float representation? >>>> >>>> paul >>>> >>>> >>
Index: gcc/match.pd ===================================================================  gcc/match.pd (revisão 263359) +++ gcc/match.pd (cópia de trabalho) @@ 4219,6 +4219,25 @@ (mult:c (TAN:s @0) (COS:s @0)) (SIN @0)) + /* Simplify sinh(atanh(x)) > x / sqrt(1  x*x). */ + (for sins (SINH) + atans (ATANH) + sqrts (SQRT) + (simplify + (sins (atans:s @0)) + (rdiv @0 (sqrts (minus {build_one_cst (type);} + (mult @0 @0)))))) + + /* Simplify cosh(atanh(x)) > 1 / sqrt(1  x*x). */ + (for coss (COSH) + atans (ATANH) + sqrts (SQRT) + (simplify + (coss (atans:s @0)) + (rdiv {build_one_cst (type);} + (sqrts (minus {build_one_cst (type);} + (mult @0 @0)))))) + /* Simplify x * pow(x,c) > pow(x,c+1). */ (simplify (mult:c @0 (POW:s @0 REAL_CST@1)) Index: gcc/testsuite/gcc.dg/sinhtanh1.c ===================================================================  gcc/testsuite/gcc.dg/sinhtanh1.c (nonexistent) +++ gcc/testsuite/gcc.dg/sinhtanh1.c (cópia de trabalho) @@ 0,0 +1,15 @@ +/* { dgdo compile } */ +/* { dgoptions "O3 ffastmath fdumptreeoptimized" } */ + +extern double sinh(double x); +extern double atanh(double x); + +double __attribute__ ((noinline)) +sinhatanh_(double x) +{ + return sinh(atanh(x)); +} + +/* There should be no calls to sinh nor atanh */ +/* { dgfinal { scantreedumpnot "sinh " "optimized" } } */ +/* { dgfinal { scantreedumpnot "atanh " "optimized" } } */ Index: gcc/testsuite/gcc.dg/sinhtanh2.c ===================================================================  gcc/testsuite/gcc.dg/sinhtanh2.c (nonexistent) +++ gcc/testsuite/gcc.dg/sinhtanh2.c (cópia de trabalho) @@ 0,0 +1,15 @@ +/* { dgdo compile } */ +/* { dgoptions "O3 ffastmath fdumptreeoptimized" } */ + +extern double cosh(double x); +extern double atanh(double x); + +double __attribute__ ((noinline)) +coshatanh_(double x) +{ + return cosh(atanh(x)); +} + +/* There should be no calls to cosh nor atanh */ +/* { dgfinal { scantreedumpnot "cosh " "optimized" } } */ +/* { dgfinal { scantreedumpnot "atanh " "optimized" } } */ Index: gcc/testsuite/gcc.dg/sinhtanh3.c ===================================================================  gcc/testsuite/gcc.dg/sinhtanh3.c (nonexistent) +++ gcc/testsuite/gcc.dg/sinhtanh3.c (cópia de trabalho) @@ 0,0 +1,16 @@ +/* { dgdo compile } */ +/* { dgoptions "O3 ffastmath fdumptreeoptimized" } */ + +extern double sinh(double x); +extern double atanh(double x); + +double __attribute__ ((noinline)) +sinhatanh_(double x) +{ + double atgh = atanh(x); + return sinh(atgh) + atgh; +} + +/* There should be calls to both sinh and atanh */ +/* { dgfinal { scantreedump "sinh " "optimized" } } */ +/* { dgfinal { scantreedump "atanh " "optimized" } } */ Index: gcc/testsuite/gcc.dg/sinhtanh4.c ===================================================================  gcc/testsuite/gcc.dg/sinhtanh4.c (nonexistent) +++ gcc/testsuite/gcc.dg/sinhtanh4.c (cópia de trabalho) @@ 0,0 +1,16 @@ +/* { dgdo compile } */ +/* { dgoptions "O3 ffastmath fdumptreeoptimized" } */ + +extern double cosh(double x); +extern double atanh(double x); + +double __attribute__ ((noinline)) +coshatanh_(double x) +{ + double atgh = atanh(x); + return cosh(atgh) + atgh; +} + +/* There should be calls to both cosh and atanh */ +/* { dgfinal { scantreedump "cosh " "optimized" } } */ +/* { dgfinal { scantreedump "atanh " "optimized" } } */