[PATCH] [frange] Convert frange_add_zeros to multi-range

Aldy Hernandez <[email protected]> Thu, 6 Aug 2026 23:07:31 +0200
Newsgroups gmane.comp.gcc.patches
Message-ID <[email protected]>
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.

Pushed.

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.
---
 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 ba6af5851c2..ebf4f4e8ad8 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
-- 
2.47.3