public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Aldy Hernandez <aldyh@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-2390] [PR/middle-end 106819] NANs can never be a singleton
Date: Sat,  3 Sep 2022 15:37:41 +0000 (GMT)	[thread overview]
Message-ID: <20220903153741.13B823858CDB@sourceware.org> (raw)

https://gcc.gnu.org/g:dae8b9e2bbb6017bf90d68c7b720c500125c8295

commit r13-2390-gdae8b9e2bbb6017bf90d68c7b720c500125c8295
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Sat Sep 3 15:41:06 2022 +0200

    [PR/middle-end 106819] NANs can never be a singleton
    
    Possible NANs can never be a singleton, so they will never be
    propagated.  This was the intent, and then the signed zero code crept
    in, and was mistakenly checked before the NAN.
    
            PR/middle-end 106819
    
    gcc/ChangeLog:
    
            * value-range.cc (frange::singleton_p): Move NAN check to the top.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.dg/tree-ssa/pr106819.c: New test.

Diff:
---
 gcc/testsuite/gcc.dg/tree-ssa/pr106819.c | 24 ++++++++++++++++++++++++
 gcc/value-range.cc                       |  9 ++++-----
 2 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr106819.c b/gcc/testsuite/gcc.dg/tree-ssa/pr106819.c
new file mode 100644
index 00000000000..1272d4b5805
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr106819.c
@@ -0,0 +1,24 @@
+// { dg-do compile }
+// { dg-options "-O2 -fdump-tree-evrp-details" }
+
+static int isNaN(double x)
+{
+    return x != x;
+}
+
+static double opCmpProper(int lhs, double rhs)
+{
+  return lhs < rhs ? -1.0
+       : lhs > rhs ? 1.0
+       : lhs == rhs ? 0.0
+       : __builtin_nan("");
+}
+
+int main()
+{
+    if (!isNaN(opCmpProper(41, __builtin_nan(""))))
+      __builtin_abort();
+    return 0;
+}
+
+// { dg-final {scan-tree-dump-not "Folds to: 0.0" "evrp" } }
diff --git a/gcc/value-range.cc b/gcc/value-range.cc
index 6fd6e3b745c..a1c29f7bd0b 100644
--- a/gcc/value-range.cc
+++ b/gcc/value-range.cc
@@ -632,6 +632,10 @@ frange::singleton_p (tree *result) const
 {
   if (m_kind == VR_RANGE && real_identical (&m_min, &m_max))
     {
+      // Return false for any singleton that may be a NAN.
+      if (HONOR_NANS (m_type) && !get_nan ().no_p ())
+	return false;
+
       // Return the appropriate zero if known.
       if (HONOR_SIGNED_ZEROS (m_type) && zero_p ())
 	{
@@ -649,11 +653,6 @@ frange::singleton_p (tree *result) const
 	    }
 	  return false;
 	}
-
-      // Return false for any singleton that may be a NAN.
-      if (HONOR_NANS (m_type) && !get_nan ().no_p ())
-	return false;
-
       if (result)
 	*result = build_real (m_type, m_min);
       return true;

                 reply	other threads:[~2022-09-03 15:37 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220903153741.13B823858CDB@sourceware.org \
    --to=aldyh@gcc.gnu.org \
    --cc=gcc-cvs@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).