[gcc r17-2764] [frange] Walk sub-ranges when restoring and printing.

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

commit r17-2764-g30e546b781b87188d6b1eed7db8854473fe253e5
Author: Aldy Hernandez <[email protected]>
Date:   Tue Jul 28 11:18:07 2026 +0000

    [frange] Walk sub-ranges when restoring and printing.
    
    Teach the two remaining single-interval consumers to walk the whole
    set of sub-ranges: frange_storage::get_frange() and the pretty
    printer.
    
    This is also a non-functional change.
    
    Tested on ppc64le: bootstrap, tests, LAPACK, and verifying that
    assembly doesn't change on a corpus of LAPACK fortran preprocessed
    sources.
    
    gcc/ChangeLog:
    
            * value-range-storage.cc (frange_storage::get_frange): Restore
            every sub-range.
            * value-range-pretty-print.cc (vrange_printer::visit): Print each
            sub-range.

Diff:
---
 gcc/value-range-pretty-print.cc | 20 +++++++++++---------
 gcc/value-range-storage.cc      | 12 +++++++-----
 2 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/gcc/value-range-pretty-print.cc b/gcc/value-range-pretty-print.cc
index c3e62b0d73a1..8b857b1d59a9 100644
--- a/gcc/value-range-pretty-print.cc
+++ b/gcc/value-range-pretty-print.cc
@@ -219,15 +219,17 @@ vrange_printer::visit (const frange &r) const
       print_frange_nan (r);
       return;
     }
-  pp_character (pp, '[');
-  bool has_endpoints = !r.known_isnan ();
-  if (has_endpoints)
-    {
-      print_real_value (type, r.lower_bound ());
-      pp_string (pp, ", ");
-      print_real_value (type, r.upper_bound ());
-    }
-  pp_character (pp, ']');
+  if (r.known_isnan ())
+    pp_string (pp, "[]");
+  else
+    for (unsigned i = 0; i < r.num_pairs (); ++i)
+      {
+	pp_character (pp, '[');
+	print_real_value (type, r.lower_bound (i));
+	pp_string (pp, ", ");
+	print_real_value (type, r.upper_bound (i));
+	pp_character (pp, ']');
+      }
   print_frange_nan (r);
 }
 
diff --git a/gcc/value-range-storage.cc b/gcc/value-range-storage.cc
index 6f8b53814a8d..153a2aecb48f 100644
--- a/gcc/value-range-storage.cc
+++ b/gcc/value-range-storage.cc
@@ -556,11 +556,13 @@ frange_storage::get_frange (frange &r, tree type) const
       return;
     }
 
-  // FIXME: Rewrite for sub-ranges.  This only reconstructs the first pair.
-  // Eventually do it piecewise like irange_storage::get_irange: start
-  // undefined and union each sub-range built through the constructor (so
-  // every piece is re-canonicalized).
-  r = frange (type, m_pairs[0].min, m_pairs[0].max, m_kind);
+  // Rebuild piecewise, like irange_storage::get_irange().
+  r.set_undefined ();
+  for (unsigned i = 0; i < m_num_ranges; ++i)
+    {
+      frange tmp (type, m_pairs[i].min, m_pairs[i].max, m_kind);
+      r.union_ (tmp);
+    }
 
   // The constructor will set the NAN bits for HONOR_NANS, but we must
   // make sure to set the NAN sign if known.
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.