[COMMITTED] Tweak ssa_cache::merge_range API.

Message ID a8506f4a-8320-203e-6810-6fa3c77143b7@redhat.com
State Unresolved
Headers
Series [COMMITTED] Tweak ssa_cache::merge_range API. |

Checks

Context Check Description
snail/gcc-patch-check warning Git am fail log

Commit Message

Andrew MacLeod Sept. 20, 2023, 7:29 p.m. UTC
  Merge_range use to return TRUE if there was already a range in the 
cache.   This patches change the meaning of the return value such that 
it returns TRUE if the range in the cache changes..  ie, it either set a 
range where there wasn't one before, or updates an existing range when 
the old one intersects with the new one results in a different range.

It also tweaks the debug output for the cache to no longer output the 
header text "non-varying Global Ranges" in the class, as the class is 
now used for other purpoises as well.   The text is moved to when the 
dump is actually from a global table.

Bootstraps on 86_64-pc-linux-gnu with no regressions.   Pushed.

Andrew
commit 0885e96272f1335c324f99fd2d1e9b0b3da9090c
Author: Andrew MacLeod <amacleod@redhat.com>
Date:   Wed Sep 20 12:53:04 2023 -0400

    Tweak merge_range API.
    
    merge_range use to return TRUE if ter was already a arange.  Now it
    returns TRUE if it adds a new range, OR updates and existing range
    with a new value.  FALSE is returned when the range already matches.
    
            * gimple-range-cache.cc (ssa_cache::merge_range): Change meaning
            of the return value.
            (ssa_cache::dump): Don't print GLOBAL RANGE header.
            (ssa_lazy_cache::merge_range): Adjust return value meaning.
            (ranger_cache::dump): Print GLOBAL RANGE header.
  

Patch

diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc
index 5b74681b61a..3c819933c4e 100644
--- a/gcc/gimple-range-cache.cc
+++ b/gcc/gimple-range-cache.cc
@@ -606,7 +606,7 @@  ssa_cache::set_range (tree name, const vrange &r)
 }
 
 // If NAME has a range, intersect it with R, otherwise set it to R.
-// Return TRUE if there was already a range set, otherwise false.
+// Return TRUE if the range is new or changes.
 
 bool
 ssa_cache::merge_range (tree name, const vrange &r)
@@ -616,19 +616,23 @@  ssa_cache::merge_range (tree name, const vrange &r)
     m_tab.safe_grow_cleared (num_ssa_names + 1);
 
   vrange_storage *m = m_tab[v];
-  if (m)
+  // Check if this is a new value.
+  if (!m)
+    m_tab[v] = m_range_allocator->clone (r);
+  else
     {
       Value_Range curr (TREE_TYPE (name));
       m->get_vrange (curr, TREE_TYPE (name));
-      curr.intersect (r);
+      // If there is no change, return false.
+      if (!curr.intersect (r))
+	return false;
+
       if (m->fits_p (curr))
 	m->set_vrange (curr);
       else
 	m_tab[v] = m_range_allocator->clone (curr);
     }
-  else
-    m_tab[v] = m_range_allocator->clone (r);
-  return m != NULL;
+  return true;
 }
 
 // Set the range for NAME to R in the ssa cache.
@@ -656,27 +660,14 @@  ssa_cache::clear ()
 void
 ssa_cache::dump (FILE *f)
 {
-  /* Cleared after the table header has been printed.  */
-  bool print_header = true;
   for (unsigned x = 1; x < num_ssa_names; x++)
     {
       if (!gimple_range_ssa_p (ssa_name (x)))
 	continue;
       Value_Range r (TREE_TYPE (ssa_name (x)));
-      // Invoke dump_range_query which is a private virtual version of
-      // get_range.   This avoids performance impacts on general queries,
-      // but allows sharing of the dump routine.
+      // Dump all non-varying ranges.
       if (get_range (r, ssa_name (x)) && !r.varying_p ())
 	{
-	  if (print_header)
-	    {
-	      /* Print the header only when there's something else
-		 to print below.  */
-	      fprintf (f, "Non-varying global ranges:\n");
-	      fprintf (f, "=========================:\n");
-	      print_header = false;
-	    }
-
 	  print_generic_expr (f, ssa_name (x), TDF_NONE);
 	  fprintf (f, "  : ");
 	  r.dump (f);
@@ -684,8 +675,6 @@  ssa_cache::dump (FILE *f)
 	}
     }
 
-  if (!print_header)
-    fputc ('\n', f);
 }
 
 // Return true if NAME has an active range in the cache.
@@ -716,7 +705,7 @@  ssa_lazy_cache::set_range (tree name, const vrange &r)
 }
 
 // If NAME has a range, intersect it with R, otherwise set it to R.
-// Return TRUE if there was already a range set, otherwise false.
+// Return TRUE if the range is new or changes.
 
 bool
 ssa_lazy_cache::merge_range (tree name, const vrange &r)
@@ -731,7 +720,7 @@  ssa_lazy_cache::merge_range (tree name, const vrange &r)
   if (v >= m_tab.length ())
     m_tab.safe_grow (num_ssa_names + 1);
   m_tab[v] = m_range_allocator->clone (r);
-  return false;
+  return true;
 }
 
 // Return TRUE if NAME has a range, and return it in R.
@@ -996,6 +985,8 @@  ranger_cache::~ranger_cache ()
 void
 ranger_cache::dump (FILE *f)
 {
+  fprintf (f, "Non-varying global ranges:\n");
+  fprintf (f, "=========================:\n");
   m_globals.dump (f);
   fprintf (f, "\n");
 }