public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: Joseph Myers <joseph@codesourcery.com>
Cc: "Kewen.Lin" <linkw@linux.ibm.com>,
	gcc-patches <gcc-patches@gcc.gnu.org>,
	 Peter Bergner <bergner@linux.ibm.com>, David <dje.gcc@gmail.com>,
	 Segher Boessenkool <segher@kernel.crashing.org>
Subject: Re: [PATCH] Skip constant folding for fmin/max when either argument is sNaN [PR105414]
Date: Fri, 6 May 2022 08:17:48 +0200	[thread overview]
Message-ID: <CAFiYyc20_KT-dY4cH0wDnid-Qj4FcDdm35B4LUq4N8rMEJCZaA@mail.gmail.com> (raw)
In-Reply-To: <alpine.DEB.2.22.394.2205051703100.819159@digraph.polyomino.org.uk>

On Thu, May 5, 2022 at 7:11 PM Joseph Myers <joseph@codesourcery.com> wrote:
>
> On Thu, 5 May 2022, Richard Biener via Gcc-patches wrote:
>
> > MIN/MAX_EXPR shouldn't even appear with -fsignalling-nans for this
> > reason, at least that's what I thought.  But yes, you might have a point
> > here (but maybe it's also not strictly enough specified).  One option would
> > be to do (minmax == MAX_EXPR || minmax == MIN_EXPR || !tree_expr ...)
> >
> > Joseph - are MIN_EXPR and MAX_EXPR supposed to turn sNaN into qNaN
> > and the 'undefinedness' is merely as to which operand is chosen?
>
> I don't know what MIN_EXPR and MAX_EXPR are supposed to do with sNaN
> arguments.  As noted, the fmax and fmin functions should produce a qNaN
> result with the "invalid" exception raised (so with an sNaN argument, it's
> definitely not valid to fold them in the absence of -fno-trapping-math;
> with -fsignaling-nans -fno-trapping-math, if an argument is known to be
> sNaN it would be valid to fold to qNaN, but I doubt there's much use of
> that option combination).
>
> C never attempts to define which qNaN result (choice of payload or sign
> bit) is produced by an operation and I don't think our optimizations
> should be trying to define that (with any command-line options currently
> supported) either (other than for non-computational operations such as
> fabs and copysign, but even there there is scope for
> implementation-defined handling of assignment as a convertFormat operation
> rather than a copy operation).  Note that while some architectures
> propagate NaN payloads from a NaN operand to an instruction, others (e.g.
> RISC-V) do not, and when payloads are propagated there would still be the
> matter of which payload is chosen when there is more than one NaN operand
> (on x86, that is handled differently for SSE and x87 instructions).

Thanks.  So I think the patch as posted is correct on the safe side in
letting the CPU to decide what happens with sNaNs.  As said, the chance
seeing an sNaN and MAX/MIN_EXPR is low.

So I'm defering to the poster if he wants to re-post with treating MIN/MAX_EXPR
special in the optimistic sense.

Richard.


> --
> Joseph S. Myers
> joseph@codesourcery.com

  reply	other threads:[~2022-05-06  6:18 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-05  8:06 HAO CHEN GUI
2022-05-05  8:09 ` Richard Biener
2022-05-05  8:30   ` Kewen.Lin
2022-05-05  8:35     ` Richard Biener
2022-05-05 17:11       ` Joseph Myers
2022-05-06  6:17         ` Richard Biener [this message]
2022-05-05  9:30     ` HAO CHEN GUI
2022-05-05 13:23       ` Segher Boessenkool

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=CAFiYyc20_KT-dY4cH0wDnid-Qj4FcDdm35B4LUq4N8rMEJCZaA@mail.gmail.com \
    --to=richard.guenther@gmail.com \
    --cc=bergner@linux.ibm.com \
    --cc=dje.gcc@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=joseph@codesourcery.com \
    --cc=linkw@linux.ibm.com \
    --cc=segher@kernel.crashing.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).