public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Richard Biener <richard.guenther@gmail.com>
Cc: Aldy Hernandez <aldyh@redhat.com>,
	Richard Henderson <rth@gcc.gnu.org>,
	GCC patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] frange: flush denormals to zero for -funsafe-math-optimizations.
Date: Mon, 19 Sep 2022 10:25:56 +0200	[thread overview]
Message-ID: <YygnlBczg1B1zQ9I@tucnak> (raw)
In-Reply-To: <CAFiYyc3yRBFpn1EyDyC0KuveVPkSyma17OYtivM8=fx2QXtFug@mail.gmail.com>

On Mon, Sep 19, 2022 at 09:37:22AM +0200, Richard Biener wrote:
> On Sat, Sep 17, 2022 at 10:25 AM Aldy Hernandez via Gcc-patches
> <gcc-patches@gcc.gnu.org> wrote:
> >
> > Jakub has mentioned that for -funsafe-math-optimizations we may flush
> > denormals to zero, in which case we need to be careful to extend the
> > ranges to the appropriate zero.  This patch does exactly that.  For a
> > range of [x, -DENORMAL] we flush to [x, -0.0] and for [+DENORMAL, x]
> > we flush to [+0.0, x].
> >
> > It is unclear whether we should do this for Alpha, since I believe
> > flushing to zero is the default, and the port requires -mieee for IEEE
> > sanity.  If so, perhaps we should add a target hook so backends are
> > free to request flushing to zero.
> >
> > Thoughts?
> 
> I'm not sure what the intention of this is - it effectively results in
> more conservative ranges for -funsafe-math-optimizations.  That is,
> if -funsafe-math-optimizations says that denormals don't exist and
> are all zero then doesn't that mean we can instead use the smalles
> non-denormal number less than (or greater than) zero here?

Yes, with -funsafe-math-optimizations we will sometimes have slightly
larger ranges, while when we know or assume we know that denormals
will be honored we can be more precise.
It is similar to the -fno-signed-zeros case, when we are more relaxed
and say we don't care about sign of zeros and optimizations can be
performed to leave the sign of zero in whatever state they like,
we can't have [+0.0, xx] or [xx, -0.0] ranges and need to extend them
to [-0.0, xx] or [xx, +0.0].  The honor denormals case is similar,
if there is the possibility of having denormals flushed to zero,
[+denormal, xx] needs to be extended to [+0.0, xx] and
[xx, -denormal] to [xx, -0.0].  Now, I think we just should add
a separate option whether denormals are honored or not, because
always extending the ranges with denormals on the boundaries might
prevent some useful optimizations.  If we add such an option, it
could default to not honoring them for -funsafe-math-optimizations,
and say on alpha it should default to not honoring them by default
always unless -mieee option is used, but all of this if the user
didn't use the option explicitly, in that case follow what the user
said.  That way if users know they set DTZ flag themselves or use
libraries that do so, they can tell the compiler about it.

> That said, the flushing you do is also "valid" for
> -fno-unsafe-math-optimizations
> in case we don't want to deal with denormals in range boundaries.

It is always valid to extend the range more, but could be harmful to
optimizations.  Say if we have then x > 0.0 test...
Of course, without -ffast-math we won't DCE various floating point
operations because they can raise exceptions, but at least we can DCE
the basic block after it that depends on x > 0.0.

	Jakub


  reply	other threads:[~2022-09-19  8:26 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-17  8:24 Aldy Hernandez
2022-09-19  7:37 ` Richard Biener
2022-09-19  8:25   ` Jakub Jelinek [this message]
2022-09-19 13:04   ` Aldy Hernandez
2022-09-19 13:06     ` Aldy Hernandez
2022-09-19 13:44     ` Richard Biener
2022-09-20  5:22       ` Aldy Hernandez
2022-09-20  8:26         ` Jakub Jelinek

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=YygnlBczg1B1zQ9I@tucnak \
    --to=jakub@redhat.com \
    --cc=aldyh@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=richard.guenther@gmail.com \
    --cc=rth@gcc.gnu.org \
    /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).