From: Jeff Law <law@redhat.com>
To: Rafael Tsuha <rafael.tsuha@usp.br>
Cc: gcc-patches@gcc.gnu.org,
Mateus Carmo Martins de Freitas Barbosa
<mateus.carmo.barbosa@usp.br>,
Giuliano Augusto Faulin Belinassi <giuliano.belinassi@usp.br>,
Uros Bizjak <ubizjak@gmail.com>
Subject: Re: [PATCH] Simplify sinh (x) / cosh (x)
Date: Mon, 09 Sep 2019 18:44:00 -0000 [thread overview]
Message-ID: <710bbc92-6e5a-643f-9a6c-138a74b2e0e7@redhat.com> (raw)
In-Reply-To: <CAHMCd+XN9o5PqoBKmCv0i5m1r192WU5PtQD6yptV1cpHxg1bSA@mail.gmail.com>
On 9/4/19 12:16 PM, Rafael Tsuha wrote:
> Hi, Jeff
>
> Em seg, 29 de abr de 2019 Ã s 18:22, Jeff Law <law@redhat.com> escreveu:
>>
>> On 1/22/19 12:31 PM, Rafael Tsuha wrote:
>>> This patch simplifies the expression sinh (x) / cosh (x) to tanh (x).
>>> This rule is mathematically valid.
>>>
>>> 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's an indication something has gone wrong.
>>
>> If I'm reading this correctly it sounds like tanh in that range is
>> returning -0? If so, that just seems like the wrong output from tanh
>> since IIUC for a positive input tanh will always have a positive output.
>>
>
> I reverted the patch sent to solve bug 88556 and found out that
> tanhl(0) started returning -0 after this patch.
>
> patch we reverted:
> (https://gcc.gnu.org/viewcvs/gcc/trunk/gcc/config/i386/i386.c?r1=267325&r2=267324&pathrev=267325)
>
> In the line 44480 of this patch, it checks the sign bit of the input
> and if it's false the expression is multiplied by -1. In the way it's
> being calculated, this should be done only if the input is a number
> greater than zero.
>
> If we follow the code starting at line 44468, replacing op1 with 0, we
> can see that e2 equals 0 at line 44482, flags will be false and
> finally the e2 = -e2 operation will be executed generating the -0
> result.
>
> I have implemented a testcase to reproduce the bug:
> https://paste.debian.net/1098800/
> this code was compiled with -Ofast when we tested it.
>
> Should I file a bug about this? And for fixing, Is it a good solution
> to emit an instruction to return zero immediately if the input equals
> zero?
So if I'm understanding Uros's patch correctly, it's supposed to only be
used for -ffast-math where we don't necessarily honor signed zeros.
Are you applying the sinh/cosh -> tanh transformation only with
-ffast-math (it's been so long I simply can't remember).
jeff
next prev parent reply other threads:[~2019-09-09 18:44 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-22 19:31 Rafael Tsuha
2019-04-29 21:23 ` Jeff Law
2019-09-04 18:16 ` Rafael Tsuha
2019-09-09 18:44 ` Jeff Law [this message]
2019-09-10 7:37 ` Uros Bizjak
2019-09-10 15:23 ` Jeff Law
2019-10-02 18:08 ` Rafael Tsuha
2019-10-04 18:31 ` Jeff Law
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=710bbc92-6e5a-643f-9a6c-138a74b2e0e7@redhat.com \
--to=law@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=giuliano.belinassi@usp.br \
--cc=mateus.carmo.barbosa@usp.br \
--cc=rafael.tsuha@usp.br \
--cc=ubizjak@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).