public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [COMMITTED] Add default relation_kind to floating point range-op entries.
@ 2022-10-12  6:50 Aldy Hernandez
  2022-10-12  6:50 ` [COMMITTED] Add an frange(type) constructor analogous to the irange version Aldy Hernandez
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Aldy Hernandez @ 2022-10-12  6:50 UTC (permalink / raw)
  To: GCC patches; +Cc: Andrew MacLeod, Aldy Hernandez

The methods from which these derive all have a default relation_kind.
This patch just adds the default, to make it easier to write unit
tests later.

gcc/ChangeLog:

	* range-op-float.cc: Add relation_kind = VREL_VARYING to all
	methods.
---
 gcc/range-op-float.cc | 80 +++++++++++++++++++++----------------------
 1 file changed, 40 insertions(+), 40 deletions(-)

diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc
index 283eb134c78..71cdd112b86 100644
--- a/gcc/range-op-float.cc
+++ b/gcc/range-op-float.cc
@@ -318,14 +318,14 @@ class foperator_identity : public range_operator_float
 public:
   bool fold_range (frange &r, tree type ATTRIBUTE_UNUSED,
 		   const frange &op1, const frange &op2 ATTRIBUTE_UNUSED,
-		   relation_kind) const final override
+		   relation_kind = VREL_VARYING) const final override
   {
     r = op1;
     return true;
   }
   bool op1_range (frange &r, tree type ATTRIBUTE_UNUSED,
 		  const frange &lhs, const frange &op2 ATTRIBUTE_UNUSED,
-		  relation_kind) const final override
+		  relation_kind = VREL_VARYING) const final override
   {
     r = lhs;
     return true;
@@ -341,17 +341,17 @@ class foperator_equal : public range_operator_float
 public:
   bool fold_range (irange &r, tree type,
 		   const frange &op1, const frange &op2,
-		   relation_kind rel) const final override;
+		   relation_kind = VREL_VARYING) const final override;
   relation_kind op1_op2_relation (const irange &lhs) const final override
   {
     return equal_op1_op2_relation (lhs);
   }
   bool op1_range (frange &r, tree type,
 		  const irange &lhs, const frange &op2,
-		  relation_kind rel) const final override;
+		  relation_kind = VREL_VARYING) const final override;
   bool op2_range (frange &r, tree type,
 		  const irange &lhs, const frange &op1,
-		  relation_kind rel) const final override
+		  relation_kind rel = VREL_VARYING) const final override
   {
     return op1_range (r, type, lhs, op1, rel);
   }
@@ -447,14 +447,14 @@ class foperator_not_equal : public range_operator_float
 public:
   bool fold_range (irange &r, tree type,
 		   const frange &op1, const frange &op2,
-		   relation_kind rel) const final override;
+		   relation_kind rel = VREL_VARYING) const final override;
   relation_kind op1_op2_relation (const irange &lhs) const final override
   {
     return not_equal_op1_op2_relation (lhs);
   }
   bool op1_range (frange &r, tree type,
 		  const irange &lhs, const frange &op2,
-		  relation_kind rel) const final override;
+		  relation_kind = VREL_VARYING) const final override;
 } fop_not_equal;
 
 bool
@@ -548,17 +548,17 @@ class foperator_lt : public range_operator_float
 public:
   bool fold_range (irange &r, tree type,
 		   const frange &op1, const frange &op2,
-		   relation_kind rel) const final override;
+		   relation_kind = VREL_VARYING) const final override;
   relation_kind op1_op2_relation (const irange &lhs) const final override
   {
     return lt_op1_op2_relation (lhs);
   }
   bool op1_range (frange &r, tree type,
 		  const irange &lhs, const frange &op2,
-		  relation_kind rel) const final override;
+		  relation_kind = VREL_VARYING) const final override;
   bool op2_range (frange &r, tree type,
 		  const irange &lhs, const frange &op1,
-		  relation_kind rel) const final override;
+		  relation_kind = VREL_VARYING) const final override;
 } fop_lt;
 
 bool
@@ -663,17 +663,17 @@ class foperator_le : public range_operator_float
 public:
   bool fold_range (irange &r, tree type,
 		   const frange &op1, const frange &op2,
-		   relation_kind rel) const final override;
+		   relation_kind rel = VREL_VARYING) const final override;
   relation_kind op1_op2_relation (const irange &lhs) const final override
   {
     return le_op1_op2_relation (lhs);
   }
   bool op1_range (frange &r, tree type,
 		  const irange &lhs, const frange &op2,
-		  relation_kind rel) const final override;
+		  relation_kind rel = VREL_VARYING) const final override;
   bool op2_range (frange &r, tree type,
 		  const irange &lhs, const frange &op1,
-		  relation_kind rel) const final override;
+		  relation_kind rel = VREL_VARYING) const final override;
 } fop_le;
 
 bool
@@ -770,17 +770,17 @@ class foperator_gt : public range_operator_float
 public:
   bool fold_range (irange &r, tree type,
 		   const frange &op1, const frange &op2,
-		   relation_kind rel) const final override;
+		   relation_kind = VREL_VARYING) const final override;
   relation_kind op1_op2_relation (const irange &lhs) const final override
   {
     return gt_op1_op2_relation (lhs);
   }
   bool op1_range (frange &r, tree type,
 		  const irange &lhs, const frange &op2,
-		  relation_kind rel) const final override;
+		  relation_kind = VREL_VARYING) const final override;
   bool op2_range (frange &r, tree type,
 		  const irange &lhs, const frange &op1,
-		  relation_kind rel) const final override;
+		  relation_kind = VREL_VARYING) const final override;
 } fop_gt;
 
 bool
@@ -885,17 +885,17 @@ class foperator_ge : public range_operator_float
 public:
   bool fold_range (irange &r, tree type,
 		   const frange &op1, const frange &op2,
-		   relation_kind rel) const final override;
+		   relation_kind = VREL_VARYING) const final override;
   relation_kind op1_op2_relation (const irange &lhs) const final override
   {
     return ge_op1_op2_relation (lhs);
   }
   bool op1_range (frange &r, tree type,
 		  const irange &lhs, const frange &op2,
-		  relation_kind rel) const final override;
+		  relation_kind = VREL_VARYING) const final override;
   bool op2_range (frange &r, tree type,
 		  const irange &lhs, const frange &op1,
-		  relation_kind rel) const final override;
+		  relation_kind = VREL_VARYING) const final override;
 } fop_ge;
 
 bool
@@ -996,13 +996,13 @@ class foperator_unordered : public range_operator_float
 public:
   bool fold_range (irange &r, tree type,
 		   const frange &op1, const frange &op2,
-		   relation_kind rel) const final override;
+		   relation_kind = VREL_VARYING) const final override;
   bool op1_range (frange &r, tree type,
 		  const irange &lhs, const frange &op2,
-		  relation_kind rel) const final override;
+		  relation_kind = VREL_VARYING) const final override;
   bool op2_range (frange &r, tree type,
 		  const irange &lhs, const frange &op1,
-		  relation_kind rel) const final override
+		  relation_kind rel = VREL_VARYING) const final override
   {
     return op1_range (r, type, lhs, op1, rel);
   }
@@ -1073,13 +1073,13 @@ class foperator_ordered : public range_operator_float
 public:
   bool fold_range (irange &r, tree type,
 		   const frange &op1, const frange &op2,
-		   relation_kind rel) const final override;
+		   relation_kind = VREL_VARYING) const final override;
   bool op1_range (frange &r, tree type,
 		  const irange &lhs, const frange &op2,
-		  relation_kind rel) const final override;
+		  relation_kind = VREL_VARYING) const final override;
   bool op2_range (frange &r, tree type,
 		  const irange &lhs, const frange &op1,
-		  relation_kind rel) const final override
+		  relation_kind rel = VREL_VARYING) const final override
   {
     return op1_range (r, type, lhs, op1, rel);
   }
@@ -1139,10 +1139,10 @@ class foperator_abs : public range_operator_float
 public:
   bool fold_range (frange &r, tree type,
 		   const frange &op1, const frange &,
-		   relation_kind) const final override;
+		   relation_kind = VREL_VARYING) const final override;
   bool op1_range (frange &r, tree type,
 		  const frange &lhs, const frange &op2,
-		  relation_kind rel) const final override;
+		  relation_kind rel = VREL_VARYING) const final override;
 } fop_abs;
 
 bool
@@ -1227,7 +1227,7 @@ class foperator_unordered_lt : public range_operator_float
 public:
   bool fold_range (irange &r, tree type,
 		   const frange &op1, const frange &op2,
-		   relation_kind rel) const final override
+		   relation_kind rel = VREL_VARYING) const final override
   {
     if (op1.known_isnan () || op2.known_isnan ())
       {
@@ -1256,7 +1256,7 @@ class foperator_unordered_le : public range_operator_float
 public:
   bool fold_range (irange &r, tree type,
 		   const frange &op1, const frange &op2,
-		   relation_kind rel) const final override
+		   relation_kind rel = VREL_VARYING) const final override
   {
     if (op1.known_isnan () || op2.known_isnan ())
       {
@@ -1277,10 +1277,10 @@ public:
   }
   bool op1_range (frange &r, tree type,
 		  const irange &lhs, const frange &op2,
-		  relation_kind rel) const final override;
+		  relation_kind = VREL_VARYING) const final override;
   bool op2_range (frange &r, tree type,
 		  const irange &lhs, const frange &op1,
-		  relation_kind rel) const final override;
+		  relation_kind = VREL_VARYING) const final override;
 } fop_unordered_le;
 
 bool
@@ -1337,7 +1337,7 @@ class foperator_unordered_gt : public range_operator_float
 public:
   bool fold_range (irange &r, tree type,
 		   const frange &op1, const frange &op2,
-		   relation_kind rel) const final override
+		   relation_kind rel = VREL_VARYING) const final override
   {
     if (op1.known_isnan () || op2.known_isnan ())
       {
@@ -1358,10 +1358,10 @@ public:
   }
   bool op1_range (frange &r, tree type,
 		  const irange &lhs, const frange &op2,
-		  relation_kind rel) const final override;
+		  relation_kind = VREL_VARYING) const final override;
   bool op2_range (frange &r, tree type,
 		  const irange &lhs, const frange &op1,
-		  relation_kind rel) const final override;
+		  relation_kind = VREL_VARYING) const final override;
 } fop_unordered_gt;
 
 bool
@@ -1420,7 +1420,7 @@ class foperator_unordered_ge : public range_operator_float
 public:
   bool fold_range (irange &r, tree type,
 		   const frange &op1, const frange &op2,
-		   relation_kind rel) const final override
+		   relation_kind rel = VREL_VARYING) const final override
   {
     if (op1.known_isnan () || op2.known_isnan ())
       {
@@ -1441,10 +1441,10 @@ public:
   }
   bool op1_range (frange &r, tree type,
 		  const irange &lhs, const frange &op2,
-		  relation_kind rel) const final override;
+		  relation_kind = VREL_VARYING) const final override;
   bool op2_range (frange &r, tree type,
 		  const irange &lhs, const frange &op1,
-		  relation_kind rel) const final override;
+		  relation_kind = VREL_VARYING) const final override;
 } fop_unordered_ge;
 
 bool
@@ -1502,7 +1502,7 @@ class foperator_unordered_equal : public range_operator_float
 public:
   bool fold_range (irange &r, tree type,
 		   const frange &op1, const frange &op2,
-		   relation_kind rel) const final override
+		   relation_kind rel = VREL_VARYING) const final override
   {
     if (op1.known_isnan () || op2.known_isnan ())
       {
@@ -1523,10 +1523,10 @@ public:
   }
   bool op1_range (frange &r, tree type,
 		  const irange &lhs, const frange &op2,
-		  relation_kind rel) const final override;
+		  relation_kind = VREL_VARYING) const final override;
   bool op2_range (frange &r, tree type,
 		  const irange &lhs, const frange &op1,
-		  relation_kind rel) const final override
+		  relation_kind rel = VREL_VARYING) const final override
   {
     return op1_range (r, type, lhs, op1, rel);
   }
-- 
2.37.3


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [COMMITTED] Add an frange(type) constructor analogous to the irange version.
  2022-10-12  6:50 [COMMITTED] Add default relation_kind to floating point range-op entries Aldy Hernandez
@ 2022-10-12  6:50 ` Aldy Hernandez
  2022-10-12  6:50 ` [COMMITTED] Disable tree to bool conversion in frange::update_nan Aldy Hernandez
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Aldy Hernandez @ 2022-10-12  6:50 UTC (permalink / raw)
  To: GCC patches; +Cc: Andrew MacLeod, Aldy Hernandez

gcc/ChangeLog:

	* value-range.h (frange::frange): Add constructor taking type.
---
 gcc/value-range.h | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/gcc/value-range.h b/gcc/value-range.h
index 07a2067898c..9d630e40f78 100644
--- a/gcc/value-range.h
+++ b/gcc/value-range.h
@@ -281,6 +281,7 @@ public:
   frange ();
   frange (const frange &);
   frange (tree, tree, value_range_kind = VR_RANGE);
+  frange (tree type);
   frange (tree type, const REAL_VALUE_TYPE &min, const REAL_VALUE_TYPE &max,
 	  value_range_kind = VR_RANGE);
   static bool supports_p (const_tree type)
@@ -1059,6 +1060,13 @@ frange::frange (const frange &src)
   *this = src;
 }
 
+inline
+frange::frange (tree type)
+{
+  m_discriminator = VR_FRANGE;
+  set_varying (type);
+}
+
 // frange constructor from REAL_VALUE_TYPE endpoints.
 
 inline
-- 
2.37.3


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [COMMITTED] Disable tree to bool conversion in frange::update_nan.
  2022-10-12  6:50 [COMMITTED] Add default relation_kind to floating point range-op entries Aldy Hernandez
  2022-10-12  6:50 ` [COMMITTED] Add an frange(type) constructor analogous to the irange version Aldy Hernandez
@ 2022-10-12  6:50 ` Aldy Hernandez
  2022-10-12  6:50 ` [COMMITTED] Add method to query the sign of a NAN Aldy Hernandez
  2022-10-12  6:50 ` [COMMITTED] Add stubs for floating point range-op tests Aldy Hernandez
  3 siblings, 0 replies; 5+ messages in thread
From: Aldy Hernandez @ 2022-10-12  6:50 UTC (permalink / raw)
  To: GCC patches; +Cc: Andrew MacLeod, Aldy Hernandez

We have a set_nan(type) method which can be confused with
update_nan(bool) because of the silent conversion of pointers to bool.
Currently, if you call update_nan(tree), you'll set the possibility of
NAN with a sign of true if tree is non-null.  This is prone to error
and this patch disallows this behavior.

gcc/ChangeLog:

	* value-range.cc (frange::set_nonnegative): Pass bool to
	update_nan.
	* value-range.h: Disallow conversion to bool in update_nan().
---
 gcc/value-range.cc | 2 +-
 gcc/value-range.h  | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/value-range.cc b/gcc/value-range.cc
index e07d2aa9a5b..26a2b782e2c 100644
--- a/gcc/value-range.cc
+++ b/gcc/value-range.cc
@@ -779,7 +779,7 @@ frange::set_nonnegative (tree type)
 
   // Set +NAN as the only possibility.
   if (HONOR_NANS (type))
-    update_nan (/*sign=*/0);
+    update_nan (/*sign=*/false);
 }
 
 // Here we copy between any two irange's.  The ranges can be legacy or
diff --git a/gcc/value-range.h b/gcc/value-range.h
index 9d630e40f78..cb5e9d0522c 100644
--- a/gcc/value-range.h
+++ b/gcc/value-range.h
@@ -317,6 +317,7 @@ public:
   const REAL_VALUE_TYPE &upper_bound () const;
   void update_nan ();
   void update_nan (bool sign);
+  void update_nan (tree) = delete; // Disallow silent conversion to bool.
   void clear_nan ();
 
   // fpclassify like API
-- 
2.37.3


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [COMMITTED] Add method to query the sign of a NAN.
  2022-10-12  6:50 [COMMITTED] Add default relation_kind to floating point range-op entries Aldy Hernandez
  2022-10-12  6:50 ` [COMMITTED] Add an frange(type) constructor analogous to the irange version Aldy Hernandez
  2022-10-12  6:50 ` [COMMITTED] Disable tree to bool conversion in frange::update_nan Aldy Hernandez
@ 2022-10-12  6:50 ` Aldy Hernandez
  2022-10-12  6:50 ` [COMMITTED] Add stubs for floating point range-op tests Aldy Hernandez
  3 siblings, 0 replies; 5+ messages in thread
From: Aldy Hernandez @ 2022-10-12  6:50 UTC (permalink / raw)
  To: GCC patches; +Cc: Andrew MacLeod, Aldy Hernandez

In writing some range-op entries I noticed we don't have a way to
query the sign of the NAN in a range, unless the range only contains
NAN, in which case you can just use frange::signbit_p.  This patch
adds a method that returns TRUE if there exists the possiblity of a
NAN and we know its sign.

gcc/ChangeLog:

	* value-range.h (frange::nan_signbit_p): New.
---
 gcc/value-range.h | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/gcc/value-range.h b/gcc/value-range.h
index cb5e9d0522c..60b989b2b50 100644
--- a/gcc/value-range.h
+++ b/gcc/value-range.h
@@ -328,6 +328,7 @@ public:
   bool maybe_isnan (bool sign) const;
   bool maybe_isinf () const;
   bool signbit_p (bool &signbit) const;
+  bool nan_signbit_p (bool &signbit) const;
 private:
   void verify_range ();
   bool normalize_kind ();
@@ -1358,4 +1359,20 @@ frange::signbit_p (bool &signbit) const
   return false;
 }
 
+// If range has a NAN with a known sign, set it in SIGNBIT and return
+// TRUE.
+
+inline bool
+frange::nan_signbit_p (bool &signbit) const
+{
+  if (undefined_p ())
+    return false;
+
+  if (m_pos_nan == m_neg_nan)
+    return false;
+
+  signbit = m_neg_nan;
+  return true;
+}
+
 #endif // GCC_VALUE_RANGE_H
-- 
2.37.3


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [COMMITTED] Add stubs for floating point range-op tests.
  2022-10-12  6:50 [COMMITTED] Add default relation_kind to floating point range-op entries Aldy Hernandez
                   ` (2 preceding siblings ...)
  2022-10-12  6:50 ` [COMMITTED] Add method to query the sign of a NAN Aldy Hernandez
@ 2022-10-12  6:50 ` Aldy Hernandez
  3 siblings, 0 replies; 5+ messages in thread
From: Aldy Hernandez @ 2022-10-12  6:50 UTC (permalink / raw)
  To: GCC patches; +Cc: Andrew MacLeod, Aldy Hernandez

gcc/ChangeLog:

	* range-op-float.cc (frange_float): New.
	(range_op_float_tests): New.
	* range-op.cc (range_op_tests): Call range_op_float_tests.
---
 gcc/range-op-float.cc | 26 ++++++++++++++++++++++++++
 gcc/range-op.cc       |  3 +++
 2 files changed, 29 insertions(+)

diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc
index 71cdd112b86..22b7418c197 100644
--- a/gcc/range-op-float.cc
+++ b/gcc/range-op-float.cc
@@ -1612,3 +1612,29 @@ floating_op_table::set (enum tree_code code, range_operator_float &op)
   gcc_checking_assert (m_range_tree[code] == NULL);
   m_range_tree[code] = &op;
 }
+
+#if CHECKING_P
+#include "selftest.h"
+
+namespace selftest
+{
+
+// Build an frange from string endpoints.
+
+inline frange
+frange_float (const char *lb, const char *ub, tree type = float_type_node)
+{
+  REAL_VALUE_TYPE min, max;
+  gcc_assert (real_from_string (&min, lb) == 0);
+  gcc_assert (real_from_string (&max, ub) == 0);
+  return frange (type, min, max);
+}
+
+void
+range_op_float_tests ()
+{
+}
+
+} // namespace selftest
+
+#endif // CHECKING_P
diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index 4d5a033dfa5..16fa1f4f46d 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -4829,6 +4829,9 @@ range_op_tests ()
   range_op_bitwise_and_tests ();
   range_op_cast_tests ();
   range_relational_tests ();
+
+  extern void range_op_float_tests ();
+  range_op_float_tests ();
 }
 
 } // namespace selftest
-- 
2.37.3


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-10-12  6:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-12  6:50 [COMMITTED] Add default relation_kind to floating point range-op entries Aldy Hernandez
2022-10-12  6:50 ` [COMMITTED] Add an frange(type) constructor analogous to the irange version Aldy Hernandez
2022-10-12  6:50 ` [COMMITTED] Disable tree to bool conversion in frange::update_nan Aldy Hernandez
2022-10-12  6:50 ` [COMMITTED] Add method to query the sign of a NAN Aldy Hernandez
2022-10-12  6:50 ` [COMMITTED] Add stubs for floating point range-op tests Aldy Hernandez

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