diff mbox series

[1/2] tree-optimization/104530 - Export global ranges during the VRP block walk.

Message ID 42952c85-5f66-6905-2d34-8d78646a2f7e@redhat.com
State New
Headers show
Series tree-optimization/104530 - proposed re-evaluation. | expand

Commit Message

Andrew MacLeod Feb. 22, 2022, 4:40 p.m. UTC
Ranger currently waits until the end of the VRP pass, then calls 
export_global_ranges ().

This method walks the list of ssa-names looking for names which it 
thinks should have SSA_NAME_RANGE_INFO updated, and is an artifact of 
the on-demand mechanism where there isn't an obvious time to finalize a 
name.

The changes for 104288 introduced the register_side_effects method and 
do provide a final place where stmt's are processed during the DOMWALK.

This patch exports the global range calculated by the statement (before 
processing side effects), and avoids the need for calling the export 
method.  This is generally better all round I think.

Bootstraps on x86_64-pc-linux-gnu with no regressions. Re-running to 
ensure...

OK for trunk? or defer to stage 1?

Andrew

Comments

Richard Biener Feb. 23, 2022, 7:25 a.m. UTC | #1
On Tue, Feb 22, 2022 at 5:42 PM Andrew MacLeod via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> Ranger currently waits until the end of the VRP pass, then calls
> export_global_ranges ().
>
> This method walks the list of ssa-names looking for names which it
> thinks should have SSA_NAME_RANGE_INFO updated, and is an artifact of
> the on-demand mechanism where there isn't an obvious time to finalize a
> name.
>
> The changes for 104288 introduced the register_side_effects method and
> do provide a final place where stmt's are processed during the DOMWALK.
>
> This patch exports the global range calculated by the statement (before
> processing side effects), and avoids the need for calling the export
> method.  This is generally better all round I think.
>
> Bootstraps on x86_64-pc-linux-gnu with no regressions. Re-running to
> ensure...
>
> OK for trunk? or defer to stage 1?

I'm getting a bit nervous so lets defer to stage 1 unless a P1 fix
requires this.

Thanks,
Richard.

>
> Andrew
Andrew MacLeod Feb. 23, 2022, 2:05 p.m. UTC | #2
On 2/23/22 02:25, Richard Biener wrote:
> On Tue, Feb 22, 2022 at 5:42 PM Andrew MacLeod via Gcc-patches
> <gcc-patches@gcc.gnu.org> wrote:
>> Ranger currently waits until the end of the VRP pass, then calls
>> export_global_ranges ().
>>
>> This method walks the list of ssa-names looking for names which it
>> thinks should have SSA_NAME_RANGE_INFO updated, and is an artifact of
>> the on-demand mechanism where there isn't an obvious time to finalize a
>> name.
>>
>> The changes for 104288 introduced the register_side_effects method and
>> do provide a final place where stmt's are processed during the DOMWALK.
>>
>> This patch exports the global range calculated by the statement (before
>> processing side effects), and avoids the need for calling the export
>> method.  This is generally better all round I think.
>>
>> Bootstraps on x86_64-pc-linux-gnu with no regressions. Re-running to
>> ensure...
>>
>> OK for trunk? or defer to stage 1?
> I'm getting a bit nervous so lets defer to stage 1 unless a P1 fix
> requires this.

Me too, so good :-)
diff mbox series

Patch

From 60ba59b5d57236ce4bab28ecdcb790c21c733904 Mon Sep 17 00:00:00 2001
From: Andrew MacLeod <amacleod@redhat.com>
Date: Wed, 16 Feb 2022 19:59:34 -0500
Subject: [PATCH 1/2] 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-cache.cc (ranger_cache::update_to_nonnull): Set the
	global value in the def block, remove the on-entry cache hack.
	* 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.
---
 gcc/gimple-range.cc | 22 ++++++++++++++++++++++
 gcc/tree-vrp.cc     |  4 +++-
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc
index 04075a98a80..3d1843670a5 100644
--- a/gcc/gimple-range.cc
+++ b/gcc/gimple-range.cc
@@ -454,6 +454,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 e9f19d0c8b9..1ad099b9ba3 100644
--- a/gcc/tree-vrp.cc
+++ b/gcc/tree-vrp.cc
@@ -4295,6 +4295,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
@@ -4338,7 +4341,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);
 
-- 
2.17.2