From: Richard Biener <richard.guenther@gmail.com>
To: "Kewen.Lin" <linkw@linux.ibm.com>,
"Joseph S. Myers" <joseph@codesourcery.com>
Cc: HAO CHEN GUI <guihaoc@linux.ibm.com>,
Peter Bergner <bergner@linux.ibm.com>,
gcc-patches <gcc-patches@gcc.gnu.org>,
Segher Boessenkool <segher@kernel.crashing.org>,
David <dje.gcc@gmail.com>
Subject: Re: [PATCH] Skip constant folding for fmin/max when either argument is sNaN [PR105414]
Date: Thu, 5 May 2022 10:35:47 +0200 [thread overview]
Message-ID: <CAFiYyc3kEJcaU-BDEwydks18E1=KwcZ=h5Mw4J_5pP5cxL-+4A@mail.gmail.com> (raw)
In-Reply-To: <f39cf89a-1365-dc98-656e-c10a991a56dd@linux.ibm.com>
On Thu, May 5, 2022 at 10:30 AM Kewen.Lin <linkw@linux.ibm.com> wrote:
>
> on 2022/5/5 16:09, Richard Biener via Gcc-patches wrote:
> > On Thu, May 5, 2022 at 10:07 AM HAO CHEN GUI via Gcc-patches
> > <gcc-patches@gcc.gnu.org> wrote:
> >>
> >> Hi,
> >> This patch skips constant folding for fmin/max when either argument
> >> is sNaN. According to C standard,
> >> fmin(sNaN, sNaN)= qNaN, fmin(sNaN, NaN) = qNaN
> >> So signaling NaN should be tested and skipped for fmin/max in match.pd.
> >>
> >> Bootstrapped and tested on ppc64 Linux BE and LE with no regressions.
> >> Is this okay for trunk? Any recommendations? Thanks a lot.
> >
> > OK.
> >
> > Thanks,
> > Richard.
> >
> >> ChangeLog
> >>
> >> 2022-05-05 Haochen Gui <guihaoc@linux.ibm.com>
> >>
> >> gcc/
> >> PR target/105414
> >> * match.pd (minmax): Skip constant folding for fmin/fmax when both
> >> arguments are sNaN or one is sNaN and another is NaN.
> >>
> >> gcc/testsuite/
> >> PR target/105414
> >> * gcc.dg/pr105414.c: New.
> >>
> >> patch.diff
> >>
> >> diff --git a/gcc/match.pd b/gcc/match.pd
> >> index cad61848daa..f256bcbb483 100644
> >> --- a/gcc/match.pd
> >> +++ b/gcc/match.pd
> >> @@ -3093,7 +3093,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
> >> (for minmax (min max FMIN_ALL FMAX_ALL)
> >> (simplify
> >> (minmax @0 @0)
> >> - @0))
> >> + /* if both are sNaN, it should return qNaN. */
> >> + (if (!tree_expr_maybe_signaling_nan_p (@0))
> >> + @0)))
>
> Sorry for chiming in.
>
> IIUC this patch is mainly for libc function fmin/fmax and the iterator here
> covers min/max and fmin/fmax. I wonder if it's intent to make this change
> for min/max as well?
>
> As tree.def, "if either operand is NaN, then it is unspecified", the optimization
> for min/max seems still acceptable?
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?
Richard.
>
> BR,
> Kewen
next prev parent reply other threads:[~2022-05-05 8:35 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 [this message]
2022-05-05 17:11 ` Joseph Myers
2022-05-06 6:17 ` Richard Biener
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='CAFiYyc3kEJcaU-BDEwydks18E1=KwcZ=h5Mw4J_5pP5cxL-+4A@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=guihaoc@linux.ibm.com \
--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).