[gcc r17-3041] [frange] Convert frange_add_zeros to multi-range

Aldy Hernandez via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:ab5addf0674f07d64b18695a54f1b43bb99e61a4

commit r17-3041-gab5addf0674f07d64b18695a54f1b43bb99e61a4
Author: Aldy Hernandez <[email protected]>
Date:   Thu Aug 6 14:33:18 2026 +0000

    [frange] Convert frange_add_zeros to multi-range
    
    frange_add_zeros ensures both -0.0 and +0.0 are present whenever the
    range holds a zero, but it detected the zero via the hull endpoints.
    For a multi-pair range whose zero sits on an inner boundary, it failed
    to add +0.0.  For example, for [-1.0,-0.0][1.0,1.0] which has a hull
    of [-1.0,1.0], it failed to add +0.0.
    
    Tested on ppc64le Linux: regstrap and LAPACK.
    
    gcc/ChangeLog:
    
            * range-op-float.cc (frange_add_zeros): Detect a contained zero with
            the contains_zero_p method instead of inspecting the hull endpoints.
            (range_op_float_tests): Test that op1_range for == admits +0.0 for a
            multi-pair operand holding an inner -0.0.

Diff:
---
 gcc/range-op-float.cc | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc
index ba6af5851c26..ebf4f4e8ad80 100644
--- a/gcc/range-op-float.cc
+++ b/gcc/range-op-float.cc
@@ -476,8 +476,7 @@ frange_add_zeros (frange &r, tree type)
   if (r.undefined_p () || r.known_isnan ())
     return;
 
-  if (HONOR_SIGNED_ZEROS (type)
-      && (real_iszero (&r.lower_bound ()) || real_iszero (&r.upper_bound ())))
+  if (HONOR_SIGNED_ZEROS (type) && r.contains_zero_p ())
     {
       frange zero;
       zero.set_zero (type);
@@ -3269,6 +3268,18 @@ range_op_float_tests ()
   REAL_VALUE_TYPE five;
   real_from_string (&five, "5.0");
   ASSERT_FALSE (r.contains_p (five));
+
+  // op1_range for "op1 == op2" where op2 = [-1.0,-0.0][1.0,1.0] holds -0.0 but
+  // not +0.0 must still admit +0.0 for op1, since -0.0 == +0.0.
+  r0 = frange_float ("-1.0", "-0.0");
+  r1 = frange_float ("1.0", "1.0");
+  r0.union_ (r1);
+  r0.clear_nan ();
+  ASSERT_FALSE (r0.contains_p (dconst0));
+  ASSERT_TRUE (r0.contains_p (dconstm0));
+  int_range<2> bool_true = range_true ();
+  range_op_handler (EQ_EXPR).op1_range (r, float_type_node, bool_true, r0);
+  ASSERT_TRUE (r.contains_p (dconst0));
 }
 
 } // namespace selftest
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.