https://gcc.gnu.org/g:467a2e2a2097583f24f5c5ef2bba4a16dc6cb8c4

commit r17-3029-g467a2e2a2097583f24f5c5ef2bba4a16dc6cb8c4
Author: Aldy Hernandez <[email protected]>
Date:   Wed Aug 5 09:07:00 2026 +0000

    Remove nonzero_p.
    
    All callers now use contains_zero_p () or special case when
    appropriate.
    
    Tested on ppc64le Linux.
    
    gcc/ChangeLog:
    
            * value-range.h (vrange::nonzero_p): Remove.
            (unsupported_range::nonzero_p): Remove.
            (irange::nonzero_p): Remove.
            (prange::nonzero_p): Remove.
            (frange::nonzero_p): Remove.
            (Value_Range::nonzero_p): Remove.
            * value-range.cc (unsupported_range::nonzero_p): Remove.
            (frange::nonzero_p): Remove.
            (range_tests_misc): Test contains_zero_p instead of nonzero_p.
            (range_tests_sub_ranges_zero): Likewise.
            * range-op.cc (range_op_bitwise_and_tests): Likewise.

Diff:
---
 gcc/range-op.cc    |  2 +-
 gcc/value-range.cc | 50 +++++++++-----------------------------------------
 gcc/value-range.h  | 22 ----------------------
 3 files changed, 10 insertions(+), 64 deletions(-)

diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index a1a479a8319a..0bfc3fa33583 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -5297,7 +5297,7 @@ range_op_bitwise_and_tests ()
   i1.set_nonzero (integer_type_node);
   i2.set_varying (integer_type_node);
   op_bitwise_or.fold_range (res, integer_type_node, i1, i2);
-  ASSERT_TRUE (res.nonzero_p ());
+  ASSERT_FALSE (res.contains_zero_p ());
 
   // (NEGATIVE | X) is nonzero.
   i1 = int_range<1> (integer_type_node, INT (-5), INT (-3));
diff --git a/gcc/value-range.cc b/gcc/value-range.cc
index d45c3649582b..3da1609f8303 100644
--- a/gcc/value-range.cc
+++ b/gcc/value-range.cc
@@ -291,12 +291,6 @@ unsupported_range::zero_p () const
   return false;
 }
 
-bool
-unsupported_range::nonzero_p () const
-{
-  return false;
-}
-
 bool
 unsupported_range::contains_zero_p () const
 {
@@ -1697,31 +1691,6 @@ frange::set_nonzero (tree type)
   set (type, dconstm0, dconst0, VR_ANTI_RANGE);
 }
 
-// Return TRUE when this range is exactly the "everything but zero" set that
-// set_nonzero builds, mirroring irange::nonzero_p.  Callers wanting "does not
-// contain zero" should use the !contains_p (0) idiom.
-//
-// A NAN is not a zero, so nonzero-ness depends only on the intervals, not on
-// whether the range may also be a NAN.  We therefore recognize the nonzero
-// range by comparing intervals against set_nonzero's with the NAN state
-// ignored.  A strict *this == set_nonzero () would be wrong: set_nonzero
-// leaves the NAN able to be either sign, so a range that is otherwise exactly
-// nonzero but whose NAN has been cleared would compare unequal.
-
-bool
-frange::nonzero_p () const
-{
-  if (undefined_p () || known_isnan ())
-    return false;
-
-  frange nz;
-  nz.set_nonzero (type ());
-  nz.clear_nan ();
-  frange tmp = *this;
-  tmp.clear_nan ();
-  return tmp == nz;
-}
-
 // Return TRUE if the range contains zero (+0.0 or -0.0).
 
 bool
@@ -3600,10 +3569,10 @@ range_tests_misc ()
   r0 = range_int (0, 0);
   ASSERT_TRUE (r0.zero_p ());
 
-  // Test nonzero_p().
+  // Test contains_zero_p().
   r0 = range_int (0, 0);
   r0.invert ();
-  ASSERT_TRUE (r0.nonzero_p ());
+  ASSERT_FALSE (r0.contains_zero_p ());
 
   // r0 = ~[1,1]
   r0 = range_int (1, 1, VR_ANTI_RANGE);
@@ -3861,26 +3830,25 @@ range_tests_sub_ranges_zero ()
 
   // Excluding zero from [-0.0, 5.0] eats the lower end entirely.
   r0.set_nonzero (float_type_node);
-  ASSERT_TRUE (r0.nonzero_p ());
+  ASSERT_FALSE (r0.contains_zero_p ());
   ASSERT_FALSE (r0.contains_p (dconst0));
   ASSERT_FALSE (r0.contains_p (dconstm0));
 
-  // A NAN is not a zero, so clearing the NAN leaves a nonzero range nonzero.
+  // A NAN is not a zero, so clearing the NAN leaves the range nonzero.
   r0.clear_nan ();
-  ASSERT_TRUE (r0.nonzero_p ());
+  ASSERT_FALSE (r0.contains_zero_p ());
 
-  // A range that merely avoids zero is not the nonzero range.
+  // A range that avoids zero does not contain zero.
   r0 = frange_float ("1.0", "10.0");
-  ASSERT_FALSE (r0.nonzero_p ());
+  ASSERT_FALSE (r0.contains_zero_p ());
 
-  // Excluding zero from [-0.0, 5.0] leaves (0, 5]: it avoids zero but is not
-  // the whole nonzero range.
+  // Excluding zero from [-0.0, 5.0] leaves (0, 5], which does not contain 
zero.
   r0 = frange_float ("-0.0", "5.0");
   r0.clear_nan ();
   r1 = frange_float_excluding ("0.0");
   r0.intersect (r1);
   ASSERT_EQ (r0.num_pairs (), 1);
-  ASSERT_FALSE (r0.nonzero_p ());
+  ASSERT_FALSE (r0.contains_zero_p ());
   ASSERT_FALSE (r0.contains_p (dconst0));
   ASSERT_FALSE (r0.contains_p (dconstm0));
   ASSERT_TRUE (r0.contains_p (real_from_str ("5.0")));
diff --git a/gcc/value-range.h b/gcc/value-range.h
index 1d138ab1828c..b767e462f768 100644
--- a/gcc/value-range.h
+++ b/gcc/value-range.h
@@ -102,7 +102,6 @@ public:
   virtual bool singleton_p (tree *result = NULL) const = 0;
   virtual bool contains_p (tree cst) const = 0;
   virtual bool zero_p () const = 0;
-  virtual bool nonzero_p () const = 0;
   // True if val == 0 may hold for some value in the range; for a float
   // range that means +0.0 or -0.0.
   virtual bool contains_zero_p () const = 0;
@@ -317,7 +316,6 @@ public:
 
   // Predicates.
   virtual bool zero_p () const override;
-  virtual bool nonzero_p () const override;
   virtual bool contains_zero_p () const override;
   virtual bool singleton_p (tree *result = NULL) const override;
   bool singleton_p (wide_int &) const;
@@ -425,7 +423,6 @@ public:
   virtual bool fits_p (const vrange &v) const final override;
   virtual bool singleton_p (tree *result = NULL) const final override;
   virtual bool zero_p () const final override;
-  virtual bool nonzero_p () const final override;
   virtual bool contains_zero_p () const final override;
   virtual void set (tree, tree, value_range_kind = VR_RANGE) final override;
   virtual tree type () const final override;
@@ -526,7 +523,6 @@ public:
   bool singleton_p (tree * = NULL) const final override;
   bool contains_p (tree) const final override;
   bool zero_p () const final override;
-  bool nonzero_p () const final override;
   bool contains_zero_p () const final override;
   void set_nonzero (tree type) final override;
   void set_zero (tree type) final override;
@@ -639,7 +635,6 @@ public:
   virtual bool supports_type_p (const_tree type) const override;
   virtual void accept (const vrange_visitor &v) const override;
   virtual bool zero_p () const override;
-  virtual bool nonzero_p () const override;
   virtual bool contains_zero_p () const override;
   virtual void set_nonzero (tree type) override;
   virtual void set_zero (tree type) override;
@@ -892,7 +887,6 @@ public:
   void set_zero (tree type) { init (type); return m_vrange->set_zero (type); }
   void set_nonzero (tree type)
     { init (type); return m_vrange->set_nonzero (type); }
-  bool nonzero_p () const { return m_vrange->nonzero_p (); }
   bool contains_zero_p () const { return m_vrange->contains_zero_p (); }
   bool zero_p () const { return m_vrange->zero_p (); }
   tree lbound () const { return m_vrange->lbound (); }
@@ -1135,16 +1129,6 @@ irange::zero_p () const
          && upper_bound (0) == 0);
 }
 
-inline bool
-irange::nonzero_p () const
-{
-  if (undefined_p ())
-    return false;
-
-  wide_int zero = wi::zero (TYPE_PRECISION (type ()));
-  return *this == int_range<2> (type (), zero, zero, VR_ANTI_RANGE);
-}
-
 inline bool
 irange::contains_zero_p () const
 {
@@ -1482,12 +1466,6 @@ prange::zero_p () const
   return ret;
 }
 
-inline bool
-prange::nonzero_p () const
-{
-  return m_kind == VR_RANGE && m_min == 1 && m_max == -1;
-}
-
 inline bool
 prange::contains_zero_p () const
 {

Reply via email to