VRP currently searches the ssa_name list for globals to exported after it  finishes running.  This change simply exports globals as they are calculated for the final time during the DOM walk.

This avoid the occasional awkwardness of determined what ssa-names in the list are important, as well as allowing forthcoming side-effect code to adjust what is currently known as a global value during the walk without affecting the values exported for the entire function.

Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed.

Andrew
commit af34279921f4bb95b07c0be7fce9baeffafcb53d
Author: Andrew MacLeod <amacl...@redhat.com>
Date:   Wed Feb 16 19:59:34 2022 -0500

    Export global ranges during the VRP block walk.
    
    VRP currently searches the ssa_name list for globals to exported after it
    finishes running.  Recent changes have VRP calling a side-effect routine for
    each stmt during the walk.  This change simply exports globals as they are
    calculated the final time during the walk.
    
            * gimple-range.cc (gimple_ranger::register_side_effects): First check
            if the DEF should be exported as a global.
            * tree-vrp.cc (rvrp_folder::pre_fold_bb): Process PHI side effects,
            which will export globals.
            (execute_ranger_vrp): Remove call to export_global_ranges.

diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc
index f0caefce2a3..1fdee026a4b 100644
--- a/gcc/gimple-range.cc
+++ b/gcc/gimple-range.cc
@@ -458,6 +458,28 @@ gimple_ranger::fold_stmt (gimple_stmt_iterator *gsi, tree (*valueize) (tree))
 void
 gimple_ranger::register_side_effects (gimple *s)
 {
+  // First, export the LHS if it is a new global range.
+  tree lhs = gimple_get_lhs (s);
+  if (lhs)
+    {
+      int_range_max tmp;
+      if (range_of_stmt (tmp, s, lhs) && !tmp.varying_p ()
+	  && update_global_range (tmp, lhs) && dump_file)
+	{
+	  value_range vr = tmp;
+	  fprintf (dump_file, "Global Exported: ");
+	  print_generic_expr (dump_file, lhs, TDF_SLIM);
+	  fprintf (dump_file, " = ");
+	  vr.dump (dump_file);
+	  int_range_max same = vr;
+	  if (same != tmp)
+	    {
+	      fprintf (dump_file, " ...  irange was : ");
+	      tmp.dump (dump_file);
+	    }
+	  fputc ('\n', dump_file);
+	}
+    }
   m_cache.block_apply_nonnull (s);
 }
 
diff --git a/gcc/tree-vrp.cc b/gcc/tree-vrp.cc
index 0cbd9d369ca..8ba9ca7328f 100644
--- a/gcc/tree-vrp.cc
+++ b/gcc/tree-vrp.cc
@@ -4302,6 +4302,9 @@ public:
   void pre_fold_bb (basic_block bb) OVERRIDE
   {
     m_pta->enter (bb);
+    for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi);
+	 gsi_next (&gsi))
+      m_ranger->register_side_effects (gsi.phi ());
   }
 
   void post_fold_bb (basic_block bb) OVERRIDE
@@ -4345,7 +4348,6 @@ execute_ranger_vrp (struct function *fun, bool warn_array_bounds_p)
   gimple_ranger *ranger = enable_ranger (fun);
   rvrp_folder folder (ranger);
   folder.substitute_and_fold ();
-  ranger->export_global_ranges ();
   if (dump_file && (dump_flags & TDF_DETAILS))
     ranger->dump (dump_file);
 

Reply via email to