From: Andrew MacLeod <amacleod@redhat.com>
To: gcc-patches <gcc-patches@gcc.gnu.org>
Cc: "hernandez, aldy" <aldyh@redhat.com>
Subject: [COMMITTED 1/3] PR tree-optimization/109695 - Choose better initial values for ranger.
Date: Wed, 24 May 2023 08:42:07 -0400 [thread overview]
Message-ID: <ec30da59-e022-905d-c710-3b1223ff7712@redhat.com> (raw)
[-- 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 ¤t_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
reply other threads:[~2023-05-24 12:42 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ec30da59-e022-905d-c710-3b1223ff7712@redhat.com \
--to=amacleod@redhat.com \
--cc=aldyh@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).