[PATCH] Simplify sinh (x) / cosh (x)

Jeff Law law@redhat.com
Fri Oct 4 18:31:00 GMT 2019


On 10/2/19 12:08 PM, Rafael Tsuha wrote:
> Hi Jeff,
> 
> I've just checked and the proposed optimization is under
> -funsafe-math-optimizations and canonicalize_math_p():
>  `(if (flag_unsafe_math_optimizations && canonicalize_math_p ())`
> 
> I'm sorry, but I don't quite understand what you mean with 'using
> those expanders in an unexpected way', should I put the optimization
> in another place and try to deal with the zero sign or is it fine the
> way it is?
So I went back to the original discussion to try and get context.

In that discussion you introduced this pattern for match.pd:

> + /* Simplify sinh(x) / cosh(x) -> tanh(x). */
> + (simplify
> +  (rdiv (SINH:s @0) (COSH:s @0))
> +   (TANH @0))

You indicated that it was giving unexpected results in a particular
interval:

> There's a slight difference in the result when applying this
> optimization with x in the interval 0 < x <= 1e-4951. With the
> optimization, the result using long double is -0 and without the
> optimization, the result is +0.

That was worrisome (and it wasn't clear from the patch that this was
predicated on flag_unsafe_math_optimizations).  So at some point I
speculated there was a deeper problem, perhaps in the tanh support.  I
think I sent you down a rathole -- sorry.

In fact, your pattern is predicated on flag_unsafe_math_optimizations
which, among other things, means that we don't honor signed zeros.  That
also explains how we were able to get into Uros's code which is also
predicated on not honoring signed zeros.

When we are not honoring signed zeros, changes like you observed are
undesirable, but OK.

I'll install your patch momentarily.  THanks for your patience,


Jeff



More information about the Gcc-patches mailing list