From: Richard Biener <rguenther@suse.de>
To: Jakub Jelinek <jakub@redhat.com>
Cc: "Joseph S. Myers" <joseph@codesourcery.com>,
Jason Merrill <jason@redhat.com>,
gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] fold-const: Don't consider NaN non-negative [PR97965]
Date: Thu, 26 Nov 2020 09:16:29 +0000 (UTC) [thread overview]
Message-ID: <nycvar.YFH.7.77.849.2011260912160.7048@jbgna.fhfr.qr> (raw)
In-Reply-To: <20201126083155.GN3788@tucnak>
On Thu, 26 Nov 2020, Jakub Jelinek wrote:
> Hi!
>
> The testcase in the PR
> constexpr bool a = __builtin_nan ("") > 0.0;
> constexpr bool b = __builtin_nans ("") > 0.0;
> constexpr bool c = __builtin_nan ("") < 0.0;
> constexpr bool d = __builtin_nans ("") < 0.0;
> constexpr bool e = __builtin_nan ("") >= 0.0;
> constexpr bool f = __builtin_nans ("") >= 0.0;
> constexpr bool g = __builtin_nan ("") <= 0.0;
> constexpr bool h = __builtin_nans ("") <= 0.0;
> has inconsistent behavior, we fold c and d initializers to 0 and don't fold
> any other comparisons to zero.
> Not including the testcase in the testsuite because I really don't know
> if it should be accepted or rejected (it is all accepted with
> -fno-trapping-math).
> The reason we optimize those < 0.0 comparisons to 0 is:
> /* Convert ABS_EXPR<x> < 0 to false. */
> strict_overflow_p = false;
> if (code == LT_EXPR
> && (integer_zerop (arg1) || real_zerop (arg1))
> && tree_expr_nonnegative_warnv_p (arg0, &strict_overflow_p))
> and we return true for __builtin_nan ("") (but not for -__builtin_nan ("").
>
> Now, it just feels wrong to me to say that NaN with sign bit clear is
> non-negative, but other than the above inconsistency I haven't been able to
> construct a miscompiled testcase, only questionable thing is that
> we fold away also comparisons of sNaN < 0.0 - but then while for sNaN >= 0.0
> we don't fold that away during gimple optimizations, we fold it during RTL
> optimizations at least on x86_64.
>
> So, I really don't know if we want this or not, posting it for discussions.
Is copysign (x, NaN) supposed to be well-defined? We'd stop folding
this then, no? I think the ABS_EXPR<x> < 0 to false folding is
simply incomplete and should first check whether the operands are
ordered? That said, NaN is nonnegative but NaN < 0 isn't false(?)
So I don't think the patch is good.
Richard.
> 2020-11-26 Jakub Jelinek <jakub@redhat.com>
>
> PR c++/97965
> * fold-const.c (tree_single_nonnegative_warnv_p): Don't return true
> for NaNs with sign bit clear.
>
> --- gcc/fold-const.c.jj 2020-11-24 09:02:25.330419895 +0100
> +++ gcc/fold-const.c 2020-11-25 15:37:14.426229476 +0100
> @@ -14186,7 +14186,9 @@ tree_single_nonnegative_warnv_p (tree t,
> return tree_int_cst_sgn (t) >= 0;
>
> case REAL_CST:
> - return ! REAL_VALUE_NEGATIVE (TREE_REAL_CST (t));
> + return (! REAL_VALUE_NEGATIVE (TREE_REAL_CST (t))
> + /* Don't consider NaNs non-negative. */
> + && ! REAL_VALUE_ISNAN (TREE_REAL_CST (t)));
>
> case FIXED_CST:
> return ! FIXED_VALUE_NEGATIVE (TREE_FIXED_CST (t));
>
> Jakub
>
>
--
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg,
Germany; GF: Felix Imend
next prev parent reply other threads:[~2020-11-26 9:16 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-26 8:31 Jakub Jelinek
2020-11-26 9:16 ` Richard Biener [this message]
2020-11-26 9:49 ` Jakub Jelinek
2020-11-26 10:03 ` Richard Biener
2020-11-26 13:56 ` Roger Sayle
2020-11-26 14:13 ` Jakub Jelinek
2020-11-26 14:20 ` Jakub Jelinek
2020-11-26 22:43 ` Jakub Jelinek
2020-11-27 10:51 ` Roger Sayle
2020-11-27 10:56 ` Roger Sayle
2020-11-27 20:39 ` Joseph Myers
2020-11-27 20:31 ` Joseph Myers
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=nycvar.YFH.7.77.849.2011260912160.7048@jbgna.fhfr.qr \
--to=rguenther@suse.de \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
--cc=jason@redhat.com \
--cc=joseph@codesourcery.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).