public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Giuliano Augusto Faulin Belinassi <giuliano.belinassi@usp.br>
To: Wilco.Dijkstra@arm.com
Cc: Richard Biener <richard.guenther@gmail.com>,
	GCC Patches <gcc-patches@gcc.gnu.org>, 	Jeff Law <law@redhat.com>,
	nd@arm.com
Subject: Re: [PATCH v3] Add sinh(atanh(x)) and cosh(atanh(x)) optimizations
Date: Thu, 22 Nov 2018 18:43:00 -0000	[thread overview]
Message-ID: <CAEFO=4Dx=3aY4JCWsTvr3VKtzSkLHNt2BQJsJbXhaj8GkjRQHA@mail.gmail.com> (raw)
In-Reply-To: <DB5PR08MB10303B0FBBC1835FA461C0D483C30@DB5PR08MB1030.eurprd08.prod.outlook.com>

Hi,

Sorry, but I am a little confused.

On Wed, Nov 14, 2018 at 11:28 AM Wilco Dijkstra <Wilco.Dijkstra@arm.com> wrote:
>
> Hi,
>
>
> > Indeed. After plotting the graph of both functions, it is very clear
> > that this check isn't required. Sorry about that.
>
> It wouldn't be clear from the graph, you need to check that +0.0, -0.0,
> out of range values, infinities, NaNs give the same answer before/after
> your transformation. If so, then you don't need anything extra except
> for unsafe-math-optimizations and no-math-errno (given errno handling
> is changed).

I checked it. They are all the same on x86_64:
https://pastebin.com/e63FxDAy
I even forced to call the glibc sinh and atanh, but use the sqrtsd instruction.
But I do agree that there may be an arch that sets an errno for sinh
or cosh but not for sqrt, implying in a unexpected behavior.
Is the no-math-errno really necessary?

>
> > There can be NaNs and Infinities. For NaNs, take any input that is
> > outside the [-1, 1] line.
> > For Infinities, take x = -1, or x = 1. I think these must be 'honored'
> > as to ensure compatibility with the original expression.
>
> The question is whether you get the same answer for these, not whether
> you can end up with an infinity or NaN. The idea is that we optimize based
> on the assumption there are no infinities or NaNs. FP operations can still
> produce infinities or NaNs, the compiler just doesn't need to worry about
> treating them correctly, and it's the programmer's reponsibility to ensure
> they are not generated.
>
> > so I must check for
> > !HONOR_SIGNED_ZEROS (type) && HONOR_NANS (type) && HONOR_INFINITIES (type)
> > that is correct? Also, is it safe to remove the !finite_math_only with
> > this, as now it is stated that the type supports infinity and NaNs?
>
> No that doesn't look quite right. First check whether the transformation
> handles zero/inf/NaN correctly, if so you don't need any of this.
>

It does handle these correctly, as far as I am concerned. At least in IEEE 754.
Richard Biener asked to add !flag_siged_zeros for documentation
reasons but this is already covered by unsafe-math. I also checked the
flags from the optimization page, but only unsafe math seems to be
applicable.
https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html

So maybe just check for unsafe-math?

>
> > However, I am not sure if it is OK to remove unsafe-math-optimizations
> > even if it enables
> > finite_math_only because of the 2 ULP error. As stated in the first
> > iteration, the user can be
> > using a very precise math library that yields 0 ULP.
>
> Well 0 ULP would be an impossibility. Unsafe math seems reasonable since
> it does behave slightly differently (including in terms of exception flags set).
> It's unfortunate GCC doesn't have clear definition of IEEE conformance
> modes like various other compilers.
>
> Wilco
>
>
>

  reply	other threads:[~2018-11-22 18:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-13 21:24 Giuliano Augusto Faulin Belinassi
2018-11-14  9:41 ` Richard Biener
2018-11-14 12:58   ` Giuliano Augusto Faulin Belinassi
2018-11-14 13:28     ` Wilco Dijkstra
2018-11-22 18:43       ` Giuliano Augusto Faulin Belinassi [this message]
2018-11-23 12:40         ` Wilco Dijkstra

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='CAEFO=4Dx=3aY4JCWsTvr3VKtzSkLHNt2BQJsJbXhaj8GkjRQHA@mail.gmail.com' \
    --to=giuliano.belinassi@usp.br \
    --cc=Wilco.Dijkstra@arm.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=law@redhat.com \
    --cc=nd@arm.com \
    --cc=richard.guenther@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).