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-3415] A false UNORDERED_<cond> means neither operand can be a NAN.
Date: Thu, 20 Oct 2022 16:46:48 +0000 (GMT)	[thread overview]
Message-ID: <20221020164648.2FEE4384D187@sourceware.org> (raw)

https://gcc.gnu.org/g:3dfdc0d1e1c4e00a77f2afc41d577c1b36cb4702

commit r13-3415-g3dfdc0d1e1c4e00a77f2afc41d577c1b36cb4702
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Wed Oct 19 17:14:02 2022 +0200

    A false UNORDERED_<cond> means neither operand can be a NAN.
    
    The false side of UNORDERED_<cond> means neither operand can be a NAN.
    Adjust all the op[12]_range entries for the UNORDERED operators such
    that a known NAN on one operands means the other operands is
    undefined.
    
    gcc/ChangeLog:
    
            * range-op-float.cc (foperator_unordered_le::op1_range): Adjust
            false side with a NAN operand.
            (foperator_unordered_le::op2_range): Same.
            (foperator_unordered_gt::op1_range): Same.
            (foperator_unordered_gt::op2_range): Same.
            (foperator_unordered_ge::op1_range): Same.
            (foperator_unordered_ge::op2_range): Same.
            (foperator_unordered_equal::op1_range): Same.

Diff:
---
 gcc/range-op-float.cc | 51 +++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 41 insertions(+), 10 deletions(-)

diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc
index a9e74c86877..0cb07c2ec29 100644
--- a/gcc/range-op-float.cc
+++ b/gcc/range-op-float.cc
@@ -1351,7 +1351,11 @@ foperator_unordered_le::op1_range (frange &r, tree type,
       break;
 
     case BRS_FALSE:
-      if (build_gt (r, type, op2))
+      // A false UNORDERED_LE means both operands are !NAN, so it's
+      // impossible for op2 to be a NAN.
+      if (op2.known_isnan ())
+	r.set_undefined ();
+      else if (build_gt (r, type, op2))
 	r.clear_nan ();
       break;
 
@@ -1375,7 +1379,11 @@ foperator_unordered_le::op2_range (frange &r,
       break;
 
     case BRS_FALSE:
-      if (build_lt (r, type, op1))
+      // A false UNORDERED_LE means both operands are !NAN, so it's
+      // impossible for op1 to be a NAN.
+      if (op1.known_isnan ())
+	r.set_undefined ();
+      else if (build_lt (r, type, op1))
 	r.clear_nan ();
       break;
 
@@ -1434,7 +1442,11 @@ foperator_unordered_gt::op1_range (frange &r,
       break;
 
     case BRS_FALSE:
-      if (build_le (r, type, op2))
+      // A false UNORDERED_GT means both operands are !NAN, so it's
+      // impossible for op2 to be a NAN.
+      if (op2.known_isnan ())
+	r.set_undefined ();
+      else if (build_le (r, type, op2))
 	r.clear_nan ();
       break;
 
@@ -1458,7 +1470,11 @@ foperator_unordered_gt::op2_range (frange &r,
       break;
 
     case BRS_FALSE:
-      if (build_ge (r, type, op1))
+      // A false UNORDERED_GT means both operands are !NAN, so it's
+      // impossible for op1 to be a NAN.
+      if (op1.known_isnan ())
+	r.set_undefined ();
+      else if (build_ge (r, type, op1))
 	r.clear_nan ();
       break;
 
@@ -1517,7 +1533,11 @@ foperator_unordered_ge::op1_range (frange &r,
       break;
 
     case BRS_FALSE:
-      if (build_lt (r, type, op2))
+      // A false UNORDERED_GE means both operands are !NAN, so it's
+      // impossible for op2 to be a NAN.
+      if (op2.known_isnan ())
+	r.set_undefined ();
+      else if (build_lt (r, type, op2))
 	r.clear_nan ();
       break;
 
@@ -1540,7 +1560,11 @@ foperator_unordered_ge::op2_range (frange &r, tree type,
       break;
 
     case BRS_FALSE:
-      if (build_gt (r, type, op1))
+      // A false UNORDERED_GE means both operands are !NAN, so it's
+      // impossible for op1 to be a NAN.
+      if (op1.known_isnan ())
+	r.set_undefined ();
+      else if (build_gt (r, type, op1))
 	r.clear_nan ();
       break;
 
@@ -1606,10 +1630,17 @@ foperator_unordered_equal::op1_range (frange &r, tree type,
       break;
 
     case BRS_FALSE:
-      // The false side indictates !NAN and not equal.  We can at least
-      // represent !NAN.
-      r.set_varying (type);
-      r.clear_nan ();
+      // A false UNORDERED_EQ means both operands are !NAN, so it's
+      // impossible for op2 to be a NAN.
+      if (op2.known_isnan ())
+	r.set_undefined ();
+      else
+	{
+	  // The false side indictates !NAN and not equal.  We can at least
+	  // represent !NAN.
+	  r.set_varying (type);
+	  r.clear_nan ();
+	}
       break;
 
     default:

                 reply	other threads:[~2022-10-20 16:46 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=20221020164648.2FEE4384D187@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).