public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-2276] Force a [NAN, NAN] range when the definite NAN property is set.
@ 2022-08-30 12:27 Aldy Hernandez
  0 siblings, 0 replies; only message in thread
From: Aldy Hernandez @ 2022-08-30 12:27 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:7e3f18439904bf26eabc658caf843b297a052eb4

commit r13-2276-g7e3f18439904bf26eabc658caf843b297a052eb4
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Tue Aug 30 12:13:31 2022 +0200

    Force a [NAN, NAN] range when the definite NAN property is set.
    
    Setting the definite NAN property should also force a [NAN, NAN]
    range, otherwise we'd have two ways of representing a NAN: with the
    endpoints or with the property.  In the ranger world we avoid at all
    costs having more than one representation for a range.
    
    In doing this, I removed the FRANGE_PROP_ACCESSOR macro, since it
    looks like setting a property may have repercurssions in the range
    itself, so it's best for the client to definte its own setter.
    
    gcc/ChangeLog:
    
            * value-range-storage.cc (frange_storage_slot::get_frange): Use
            frange_nan.
            * value-range.cc (frange::set_nan): New.
            (frange_nan): Move to header file.
            (range_tests_nan): Adjust frange_nan callers to pass type.
            New test.
            * value-range.h (FRANGE_PROP_ACCESSOR): Remove.
            (frange_nan): New.

Diff:
---
 gcc/value-range-storage.cc |  4 +---
 gcc/value-range.cc         | 55 ++++++++++++++++++++++++++++++----------------
 gcc/value-range.h          | 26 ++++++++++++----------
 3 files changed, 51 insertions(+), 34 deletions(-)

diff --git a/gcc/value-range-storage.cc b/gcc/value-range-storage.cc
index adf23c39f0d..494392737ac 100644
--- a/gcc/value-range-storage.cc
+++ b/gcc/value-range-storage.cc
@@ -267,9 +267,7 @@ frange_storage_slot::get_frange (frange &r, tree type) const
   // endpoints.
   if (m_props.get_nan ().yes_p ())
     {
-      REAL_VALUE_TYPE rv;
-      real_nan (&rv, "", 1, TYPE_MODE (type));
-      r.set (type, rv, rv);
+      r = frange_nan (type);
       return;
     }
 
diff --git a/gcc/value-range.cc b/gcc/value-range.cc
index bcc6651701b..b6d6c62c06c 100644
--- a/gcc/value-range.cc
+++ b/gcc/value-range.cc
@@ -267,6 +267,29 @@ tree_compare (tree_code code, tree op1, tree op2)
   return !integer_zerop (fold_build2 (code, integer_type_node, op1, op2));
 }
 
+// Set the NAN property.  Adjust the range if appopriate.
+
+void
+frange::set_nan (fp_prop::kind k)
+{
+  if (k == fp_prop::YES)
+    {
+      gcc_checking_assert (!undefined_p ());
+      *this = frange_nan (m_type);
+      return;
+    }
+
+  // Setting NO on an obviously NAN range is nonsensical.
+  gcc_checking_assert (k != fp_prop::NO || !real_isnan (&m_min));
+
+  // Setting VARYING on an obviously NAN range is a no-op.
+  if (k == fp_prop::VARYING && real_isnan (&m_min))
+    return;
+
+  m_props.set_nan (k);
+  normalize_kind ();
+}
+
 // Setter for franges.
 
 void
@@ -3493,17 +3516,6 @@ frange_float (const char *lb, const char *ub, tree type = float_type_node)
   return frange (type, min, max);
 }
 
-// Build a NAN of type TYPE.
-
-static inline frange
-frange_nan (tree type = float_type_node)
-{
-  REAL_VALUE_TYPE r;
-
-  gcc_assert (real_nan (&r, "", 1, TYPE_MODE (type)));
-  return frange (type, r, r);
-}
-
 static void
 range_tests_nan ()
 {
@@ -3517,18 +3529,16 @@ range_tests_nan ()
   ASSERT_NE (r0, r1);
   r0.set_nan (fp_prop::YES);
   ASSERT_NE (r0, r1);
-  r0.set_nan (fp_prop::VARYING);
-  ASSERT_EQ (r0, r1);
 
   // NAN ranges are not equal to each other.
-  r0 = frange_nan ();
+  r0 = frange_nan (float_type_node);
   r1 = r0;
   ASSERT_FALSE (r0 == r1);
   ASSERT_FALSE (r0 == r0);
   ASSERT_TRUE (r0 != r0);
 
   // Make sure that combining NAN and INF doesn't give any crazy results.
-  r0 = frange_nan ();
+  r0 = frange_nan (float_type_node);
   ASSERT_TRUE (r0.get_nan ().yes_p ());
   r1 = frange_float ("+Inf", "+Inf");
   r0.union_ (r1);
@@ -3536,22 +3546,29 @@ range_tests_nan ()
   ASSERT_TRUE (r0.varying_p ());
 
   // [INF, INF] ^ NAN = VARYING
-  r0 = frange_nan ();
+  r0 = frange_nan (float_type_node);
   r1 = frange_float ("+Inf", "+Inf");
   r0.intersect (r1);
   ASSERT_TRUE (r0.varying_p ());
 
   // NAN ^ NAN = NAN
-  r0 = frange_nan ();
-  r1 = frange_nan ();
+  r0 = frange_nan (float_type_node);
+  r1 = frange_nan (float_type_node);
   r0.intersect (r1);
   ASSERT_TRUE (r0.get_nan ().yes_p ());
 
   // VARYING ^ NAN = NAN.
-  r0 = frange_nan ();
+  r0 = frange_nan (float_type_node);
   r1.set_varying (float_type_node);
   r0.intersect (r1);
   ASSERT_TRUE (r0.get_nan ().yes_p ());
+
+  // Setting the NAN bit to yes, forces to range to [NAN, NAN].
+  r0.set_varying (float_type_node);
+  r0.set_nan (fp_prop::YES);
+  ASSERT_TRUE (r0.get_nan ().yes_p ());
+  ASSERT_TRUE (real_isnan (&r0.lower_bound ()));
+  ASSERT_TRUE (real_isnan (&r0.upper_bound ()));
 }
 
 static void
diff --git a/gcc/value-range.h b/gcc/value-range.h
index 43b231b8fe0..07379d58f88 100644
--- a/gcc/value-range.h
+++ b/gcc/value-range.h
@@ -323,16 +323,6 @@ private:
   } u;
 };
 
-// Accessors for getting/setting all FP properties at once.
-
-#define FRANGE_PROP_ACCESSOR(NAME)				\
-  fp_prop get_##NAME () const { return m_props.get_##NAME (); }	\
-  void set_##NAME (fp_prop::kind f)				\
-  {								\
-    m_props.set_##NAME (f);					\
-    normalize_kind ();						\
-  }
-
 // A floating point range.
 
 class frange : public vrange
@@ -371,8 +361,9 @@ public:
   const REAL_VALUE_TYPE &lower_bound () const;
   const REAL_VALUE_TYPE &upper_bound () const;
 
-  // Each fp_prop can be accessed with get_PROP() and set_PROP().
-  FRANGE_PROP_ACCESSOR(nan)
+  // Accessors for FP properties.
+  fp_prop get_nan () const { return m_props.get_nan (); }
+  void set_nan (fp_prop::kind f);
 private:
   void verify_range ();
   bool normalize_kind ();
@@ -1186,4 +1177,15 @@ real_min_representable (REAL_VALUE_TYPE *r, tree type)
   *r = real_value_negate (r);
 }
 
+// Build a NAN of type TYPE.
+
+inline frange
+frange_nan (tree type)
+{
+  REAL_VALUE_TYPE r;
+
+  gcc_assert (real_nan (&r, "", 1, TYPE_MODE (type)));
+  return frange (type, r, r);
+}
+
 #endif // GCC_VALUE_RANGE_H

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-08-30 12:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-30 12:27 [gcc r13-2276] Force a [NAN, NAN] range when the definite NAN property is set 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).