public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [COMMITTED 1/3] PR tree-optimization/109695 - Choose better initial values for ranger.
@ 2023-05-24 12:42 Andrew MacLeod
  0 siblings, 0 replies; only message in thread
From: Andrew MacLeod @ 2023-05-24 12:42 UTC (permalink / raw)
  To: gcc-patches; +Cc: hernandez, aldy


[-- Attachment #1.1: Type: text/plain, Size: 1751 bytes --]

Instead of defaulting to an initial value of VARYING before resolving 
cycles, try folding the statement using available global values 
instead.  THis can give us a much better initial approximation, 
especially in cases where there are no dependencies, ie
    f_45 = 77

This implements suggestion 2) in comment 22 of the PR:

    2) The initial value we choose is simply VARYING. This is why 1)
    alone won't solve this problem.  when we push _1947 on the stack, we
    set it to VARYING..  then proceed down along chain of other
    dependencies Driven by _1011 which are resolved first. When we get
    back to _1947 finally, we see:
       _1947 = 77;
    which evaluated to [77, 77], and is this different than VARYING, and
    thus would cause a new timestamp to be created even if (1) were
    implemented.

    TODO: When setting the initial value in the cache, rather than being
    lazy and using varying, we should invoke fold_stmt using
    get_global_range_query ().   This will fold the stmt and produce a
    result which resolved any ssa-names just using known global values.
    THis should not be expensive, and gives us a reasonable first
    approximation.  And for cases like _1947, the final result as well.

I stop doing this after inlining because there are some statements which 
change their evaluation (ie, BUILTIN_IN_CONSTANT)  which causes 
headaches... and then we  just default to VARYING again or anything 
which doesn't have a  global SSA range set..

There is a 2.7% hit to VRP to evaluate each statement this additional 
time, but only 0.09% to overall compile time. Besides, we get it back 
later in the patch set.. :-)

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

Andrew





[-- Attachment #2: 0001-Choose-better-initial-values-for-ranger.patch --]
[-- Type: text/x-patch, Size: 1612 bytes --]

From 3a20e1a33277bcb16d681b4f3633fcf8cce5a852 Mon Sep 17 00:00:00 2001
From: Andrew MacLeod <amacleod@redhat.com>
Date: Tue, 23 May 2023 15:11:44 -0400
Subject: [PATCH 1/3] Choose better initial values for ranger.

Instead of defaulting to VARYING, fold the stmt using just global ranges.

	PR tree-optimization/109695
	* gimple-range-cache.cc (ranger_cache::get_global_range): Call
	fold_range with global query to choose an initial value.
---
 gcc/gimple-range-cache.cc | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc
index 07c69ef858a..8ddfd9426c0 100644
--- a/gcc/gimple-range-cache.cc
+++ b/gcc/gimple-range-cache.cc
@@ -951,7 +951,22 @@ ranger_cache::get_global_range (vrange &r, tree name, bool &current_p)
 		|| m_temporal->current_p (name, m_gori.depend1 (name),
 					  m_gori.depend2 (name));
   else
-    m_globals.set_range (name, r);
+    {
+      // If no global value has been set and value is VARYING, fold the stmt
+      // using just global ranges to get a better initial value.
+      // After inlining we tend to decide some things are constant, so
+      // so not do this evaluation after inlining.
+      if (r.varying_p () && !cfun->after_inlining)
+	{
+	  gimple *s = SSA_NAME_DEF_STMT (name);
+	  if (gimple_get_lhs (s) == name)
+	    {
+	      if (!fold_range (r, s, get_global_range_query ()))
+		gimple_range_global (r, name);
+	    }
+	}
+      m_globals.set_range (name, r);
+    }
 
   // If the existing value was not current, mark it as always current.
   if (!current_p)
-- 
2.40.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-05-24 12:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-24 12:42 [COMMITTED 1/3] PR tree-optimization/109695 - Choose better initial values for ranger Andrew MacLeod

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).