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] Pass full range to build_* in range-op-float.cc
Date: Wed, 14 Sep 2022 17:08:51 +0200	[thread overview]
Message-ID: <20220914150852.1244397-4-aldyh@redhat.com> (raw)
In-Reply-To: <20220914150852.1244397-1-aldyh@redhat.com>

The build_<relop> helper functions in range-op-float.cc take the
actual value from the operand's endpoint, but this value could be
deduced from the operand itself therefore cleaning up the call site.
This also reduces the potential of mistakenly passing the wrong bound.

No functional changes.

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

gcc/ChangeLog:

	* range-op-float.cc (build_le): Accept frange instead of number.
	(build_lt): Same.
	(build_ge): Same.
	(build_gt): Same.
	(foperator_lt::op1_range): Pass full range to build_*.
	(foperator_lt::op2_range): Same.
	(foperator_le::op1_range): Same.
	(foperator_le::op2_range): Same.
	(foperator_gt::op1_range): Same.
	(foperator_gt::op2_range): Same.
	(foperator_ge::op1_range): Same.
	(foperator_ge::op2_range): Same.
---
 gcc/range-op-float.cc | 72 +++++++++++++++++++++----------------------
 1 file changed, 36 insertions(+), 36 deletions(-)

diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc
index f979ca597cb..8f3e5241313 100644
--- a/gcc/range-op-float.cc
+++ b/gcc/range-op-float.cc
@@ -208,32 +208,32 @@ frange_drop_ninf (frange &r, tree type)
   r.intersect (tmp);
 }
 
-// (X <= VAL) produces the range of [-INF, VAL].
+// Build a range that is <= VAL and store it in R.
 
 static bool
-build_le (frange &r, tree type, const REAL_VALUE_TYPE &val)
+build_le (frange &r, tree type, const frange &val)
 {
-  if (real_isnan (&val))
+  if (val.known_nan ())
     {
       r.set_undefined ();
       return false;
     }
-  r.set (type, dconstninf, val);
+  r.set (type, dconstninf, val.upper_bound ());
   return true;
 }
 
-// (X < VAL) produces the range of [-INF, VAL).
+// Build a range that is < VAL and store it in R.
 
 static bool
-build_lt (frange &r, tree type, const REAL_VALUE_TYPE &val)
+build_lt (frange &r, tree type, const frange &val)
 {
-  if (real_isnan (&val))
+  if (val.known_nan ())
     {
       r.set_undefined ();
       return false;
     }
   // < -INF is outside the range.
-  if (real_isinf (&val, 1))
+  if (real_isinf (&val.upper_bound (), 1))
     {
       if (HONOR_NANS (type))
 	r.set_nan (type);
@@ -241,37 +241,37 @@ build_lt (frange &r, tree type, const REAL_VALUE_TYPE &val)
 	r.set_undefined ();
       return false;
     }
-  // Hijack LE because we only support closed intervals.
-  build_le (r, type, val);
+  // We only support closed intervals.
+  r.set (type, dconstninf, val.upper_bound ());
   return true;
 }
 
-// (X >= VAL) produces the range of [VAL, +INF].
+// Build a range that is >= VAL and store it in R.
 
 static bool
-build_ge (frange &r, tree type, const REAL_VALUE_TYPE &val)
+build_ge (frange &r, tree type, const frange &val)
 {
-  if (real_isnan (&val))
+  if (val.known_nan ())
     {
       r.set_undefined ();
       return false;
     }
-  r.set (type, val, dconstinf);
+  r.set (type, val.lower_bound (), dconstinf);
   return true;
 }
 
-// (X > VAL) produces the range of (VAL, +INF].
+// Build a range that is > VAL and store it in R.
 
 static bool
-build_gt (frange &r, tree type, const REAL_VALUE_TYPE &val)
+build_gt (frange &r, tree type, const frange &val)
 {
-  if (real_isnan (&val))
+  if (val.known_nan ())
     {
       r.set_undefined ();
       return false;
     }
   // > +INF is outside the range.
-  if (real_isinf (&val, 0))
+  if (real_isinf (&val.lower_bound (), 0))
     {
       if (HONOR_NANS (type))
 	r.set_nan (type);
@@ -280,8 +280,8 @@ build_gt (frange &r, tree type, const REAL_VALUE_TYPE &val)
       return false;
     }
 
-  // Hijack GE because we only support closed intervals.
-  build_ge (r, type, val);
+  // We only support closed intervals.
+  r.set (type, val.lower_bound (), dconstinf);
   return true;
 }
 
@@ -549,7 +549,7 @@ foperator_lt::op1_range (frange &r,
   switch (get_bool_state (r, lhs, type))
     {
     case BRS_TRUE:
-      if (build_lt (r, type, op2.upper_bound ()))
+      if (build_lt (r, type, op2))
 	{
 	  r.clear_nan ();
 	  // x < y implies x is not +INF.
@@ -558,7 +558,7 @@ foperator_lt::op1_range (frange &r,
       break;
 
     case BRS_FALSE:
-      build_ge (r, type, op2.lower_bound ());
+      build_ge (r, type, op2);
       break;
 
     default:
@@ -577,7 +577,7 @@ foperator_lt::op2_range (frange &r,
   switch (get_bool_state (r, lhs, type))
     {
     case BRS_TRUE:
-      if (build_gt (r, type, op1.lower_bound ()))
+      if (build_gt (r, type, op1))
 	{
 	  r.clear_nan ();
 	  // x < y implies y is not -INF.
@@ -586,7 +586,7 @@ foperator_lt::op2_range (frange &r,
       break;
 
     case BRS_FALSE:
-      build_le (r, type, op1.upper_bound ());
+      build_le (r, type, op1);
       break;
 
     default:
@@ -651,12 +651,12 @@ foperator_le::op1_range (frange &r,
   switch (get_bool_state (r, lhs, type))
     {
     case BRS_TRUE:
-      if (build_le (r, type, op2.upper_bound ()))
+      if (build_le (r, type, op2))
 	r.clear_nan ();
       break;
 
     case BRS_FALSE:
-      build_gt (r, type, op2.lower_bound ());
+      build_gt (r, type, op2);
       break;
 
     default:
@@ -675,12 +675,12 @@ foperator_le::op2_range (frange &r,
   switch (get_bool_state (r, lhs, type))
     {
     case BRS_TRUE:
-      if (build_ge (r, type, op1.lower_bound ()))
+      if (build_ge (r, type, op1))
 	r.clear_nan ();
       break;
 
     case BRS_FALSE:
-      build_lt (r, type, op1.upper_bound ());
+      build_lt (r, type, op1);
       break;
 
     default:
@@ -745,7 +745,7 @@ foperator_gt::op1_range (frange &r,
   switch (get_bool_state (r, lhs, type))
     {
     case BRS_TRUE:
-      if (build_gt (r, type, op2.lower_bound ()))
+      if (build_gt (r, type, op2))
 	{
 	  r.clear_nan ();
 	  // x > y implies x is not -INF.
@@ -754,7 +754,7 @@ foperator_gt::op1_range (frange &r,
       break;
 
     case BRS_FALSE:
-      build_le (r, type, op2.upper_bound ());
+      build_le (r, type, op2);
       break;
 
     default:
@@ -773,7 +773,7 @@ foperator_gt::op2_range (frange &r,
   switch (get_bool_state (r, lhs, type))
     {
     case BRS_TRUE:
-      if (build_lt (r, type, op1.upper_bound ()))
+      if (build_lt (r, type, op1))
 	{
 	  r.clear_nan ();
 	  // x > y implies y is not +INF.
@@ -782,7 +782,7 @@ foperator_gt::op2_range (frange &r,
       break;
 
     case BRS_FALSE:
-      build_ge (r, type, op1.lower_bound ());
+      build_ge (r, type, op1);
       break;
 
     default:
@@ -847,12 +847,12 @@ foperator_ge::op1_range (frange &r,
   switch (get_bool_state (r, lhs, type))
     {
     case BRS_TRUE:
-      build_ge (r, type, op2.lower_bound ());
+      build_ge (r, type, op2);
       r.clear_nan ();
       break;
 
     case BRS_FALSE:
-      build_lt (r, type, op2.upper_bound ());
+      build_lt (r, type, op2);
       break;
 
     default:
@@ -870,11 +870,11 @@ foperator_ge::op2_range (frange &r, tree type,
   switch (get_bool_state (r, lhs, type))
     {
     case BRS_FALSE:
-      build_gt (r, type, op1.lower_bound ());
+      build_gt (r, type, op1);
       break;
 
     case BRS_TRUE:
-      build_le (r, type, op1.upper_bound ());
+      build_le (r, type, op1);
       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 ` Aldy Hernandez [this message]
2022-09-14 15:08 ` [COMMITTED] frange: add both zeros to ranges when there's the possiblity of equality Aldy Hernandez

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-4-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).