public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Aldy Hernandez <aldyh@redhat.com>
To: GCC patches <gcc-patches@gcc.gnu.org>
Cc: Andrew MacLeod <amacleod@redhat.com>, Aldy Hernandez <aldyh@redhat.com>
Subject: [COMMITTED] frange: add both zeros to ranges when there's the possiblity of equality.
Date: Wed, 14 Sep 2022 17:08:52 +0200	[thread overview]
Message-ID: <20220914150852.1244397-5-aldyh@redhat.com> (raw)
In-Reply-To: <20220914150852.1244397-1-aldyh@redhat.com>

Every time there's equality at play, we must be careful that any
equality with zero matches both -0.0 and +0.0 when honoring signed
zeros.

We were doing this correctly for the == and != op1_range operators
(albeit inefficiently), but aren't doing it at all when building >=
and <=.  This fixes the oversight.

There is change in functionality here for the build_* functions.

This is the last "simple" patch I submit before overhauling NAN and
sign tracking.  And that will likely be after Cauldron because it will need
further testing (lapack, ppc64le, -ffinite-math-only, etc).

Regstrapped on x86-64 Linux, plus I ran selftests for
-ffinite-math-only.

gcc/ChangeLog:

	* range-op-float.cc (frange_add_zeros): New.
	(build_le): Call frange_add_zeros.
	(build_ge): Same.
	(foperator_equal::op1_range): Same.
	(foperator_not_equal::op1_range): Same.
---
 gcc/range-op-float.cc | 31 +++++++++++++++++++++++++------
 1 file changed, 25 insertions(+), 6 deletions(-)

diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc
index 8f3e5241313..fbc14a730ad 100644
--- a/gcc/range-op-float.cc
+++ b/gcc/range-op-float.cc
@@ -208,6 +208,19 @@ frange_drop_ninf (frange &r, tree type)
   r.intersect (tmp);
 }
 
+// If zero is in R, make sure both -0.0 and +0.0 are in the range.
+
+static inline void
+frange_add_zeros (frange &r, tree type)
+{
+  if (r.undefined_p () || r.known_nan ())
+    return;
+
+  if (HONOR_SIGNED_ZEROS (type)
+      && (real_iszero (&r.lower_bound ()) || real_iszero (&r.upper_bound ())))
+    r.set_signbit (fp_prop::VARYING);
+}
+
 // Build a range that is <= VAL and store it in R.
 
 static bool
@@ -219,6 +232,10 @@ build_le (frange &r, tree type, const frange &val)
       return false;
     }
   r.set (type, dconstninf, val.upper_bound ());
+
+  // Add both zeros if there's the possibility of zero equality.
+  frange_add_zeros (r, type);
+
   return true;
 }
 
@@ -257,6 +274,10 @@ build_ge (frange &r, tree type, const frange &val)
       return false;
     }
   r.set (type, val.lower_bound (), dconstinf);
+
+  // Add both zeros if there's the possibility of zero equality.
+  frange_add_zeros (r, type);
+
   return true;
 }
 
@@ -376,9 +397,8 @@ foperator_equal::op1_range (frange &r, tree type,
     case BRS_TRUE:
       // If it's true, the result is the same as OP2.
       r = op2;
-      // Make sure we don't copy the sign bit if we may have a zero.
-      if (HONOR_SIGNED_ZEROS (type) && r.contains_p (build_zero_cst (type)))
-	r.set_signbit (fp_prop::VARYING);
+      // Add both zeros if there's the possibility of zero equality.
+      frange_add_zeros (r, type);
       // The TRUE side of op1 == op2 implies op1 is !NAN.
       r.clear_nan ();
       break;
@@ -480,9 +500,8 @@ foperator_not_equal::op1_range (frange &r, tree type,
     case BRS_FALSE:
       // If it's false, the result is the same as OP2.
       r = op2;
-      // Make sure we don't copy the sign bit if we may have a zero.
-      if (HONOR_SIGNED_ZEROS (type) && r.contains_p (build_zero_cst (type)))
-	r.set_signbit (fp_prop::VARYING);
+      // Add both zeros if there's the possibility of zero equality.
+      frange_add_zeros (r, type);
       // The FALSE side of op1 != op2 implies op1 is !NAN.
       r.clear_nan ();
       break;
-- 
2.37.1


      parent reply	other threads:[~2022-09-14 15:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-14 15:08 [COMMITTED] Minor fixes to frange Aldy Hernandez
2022-09-14 15:08 ` [COMMITTED] Provide cleaner set_nan(), clear_nan(), and update_nan() methods Aldy Hernandez
2022-09-14 15:08 ` [COMMITTED] Use frange::set_nan() from the generic frange::set() Aldy Hernandez
2022-09-14 15:08 ` [COMMITTED] Pass full range to build_* in range-op-float.cc Aldy Hernandez
2022-09-14 15:08 ` Aldy Hernandez [this message]

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=20220914150852.1244397-5-aldyh@redhat.com \
    --to=aldyh@redhat.com \
    --cc=amacleod@redhat.com \
    --cc=gcc-patches@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).