From: Andrew MacLeod <amacleod@redhat.com>
To: Jan Hubicka <hubicka@ucw.cz>
Cc: aldyh@redhat.com, mjambor@suse.cz, gcc-patches@gcc.gnu.org,
jwakely@redhat.com
Subject: Re: Enable ranger for ipa-prop
Date: Tue, 27 Jun 2023 13:54:39 -0400 [thread overview]
Message-ID: <a4f6bf28-fe8a-d4db-9a10-0642559de1c6@redhat.com> (raw)
In-Reply-To: <ZJsNQi6iPz6yLTRM@kam.mff.cuni.cz>
On 6/27/23 12:24, Jan Hubicka wrote:
>> On 6/27/23 09:19, Jan Hubicka wrote:
>>> Hi,
>>> as shown in the testcase (which would eventually be useful for
>>> optimizing std::vector's push_back), ipa-prop can use context dependent ranger
>>> queries for better value range info.
>>>
>>> Bootstrapped/regtested x86_64-linux, OK?
>> Quick question.
>>
>> When you call enable_ranger(), its gives you a ranger back, but it also sets
>> the range query for the specified context to that same instance. So from
>> that point forward all existing calls to get_range_query(fun) will now use
>> the context ranger
>>
>> enable_ranger (struct function *fun, bool use_imm_uses)
>> <...>
>> gcc_checking_assert (!fun->x_range_query);
>> r = new gimple_ranger (use_imm_uses);
>> fun->x_range_query = r;
>> return r;
>>
>> So you probably dont have to pass a ranger around? or is that ranger you
>> are passing for a different context?
> I don't need passing ranger around - I just did not know that. I tought
> the default one is the context insensitive one, I will simplify the
> patch. I need to look more into how ranger works.
>
>
No need. Its magic!
Andrew
PS. well, we tried to provide an interface to make it as seamless as
possible with the whole range-query thing.
10,000 foot view:
The range_query object (value-range.h) replaces the old
SSA_NAME_RANGE_INFO macros. It adds the ability to provide an optional
context in the form of a stmt or edge to any query. If no context is
provided, it simply provides the global value. There are basically 3
queries:
virtual bool range_of_expr (vrange &r, tree expr, gimple * = NULL) ;
virtual bool range_on_edge (vrange &r, edge, tree expr);
virtual bool range_of_stmt (vrange &r, gimple *, tree name = NULL);
- range_of_stmt evaluates the DEF of the stmt, but can also evaluate
things like "if (x < y)" that have an implicit boolean LHS. If NAME is
provided, it needs to match the DEF. Thats mostly flexibility for
dealing with something like multiple defs, you can specify which def.
- range_on_edge provides the range of an ssa-name as it would be valued
on a specific edge.
- range_of_expr is used to ask for the range of any ssa_name or tree
expression as it occurs on entry to a specific stmt. Normally we use
this to ask for the range of an ssa-name as its used on a stmt, but it
can evaluate expression trees as well.
These requests are not limited to names which occur on a stmt.. we can
recompute values by asking for the range of value as they occur at other
locations in the IL. ie
x_2 = b_3 + 5
<...>
if (b_3 > 7)
blah (x_2)
When we ask for the range of x_2 at the call to blah, ranger actually
recomputes x_2 = b_3 + 5 at the call site by asking for the range of b_3
on the outgoing edge leading to the block with the call to blah, and
thus uses b_3 == [8, +INF] to re-evaluate x_2
Internally, ranger uses the exact same API to evaluate everything that
external clients use.
The default query object is global_range_query, which ignores any
location (stmt or edge) information provided, and simply returns the
global value. This amounts to an identical result as the old
SSA_NAME_RANGE_INFO request, and when get_range_query () is called, this
is the default range_query that is provided.
When a pass calls enable_ranger(), the default query is changed to this
new instance (which supports context information), and any further calls
to get_range_query() will now invoke ranger instead of the
global_range_query. It uses its on-demand support to go and answer the
range question by looking at only what it needs to in order to answer
the question. This is the exact same ranger code base that all the VRP
passes use, so you get almost the same level of power to answer
questions. There are just a couple of little things that VRP enables
because it does a DOM walk, but they are fairly minor for most cases.
if you use the range_query API, and do not provide a stmt or an edge,
then we can't provide contextual range information, and you'll go back
to getting just global information again.
I think Aldy has converted everything to the new range_query API...
which means any pass that could benefit from contextual range
information , in theory, only needs to enable_ranger() and provide a
context stmt or edge on the range query call.
Just remember to disable it when done :-)
Andrew
next prev parent reply other threads:[~2023-06-27 17:54 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-27 13:19 Jan Hubicka
2023-06-27 14:00 ` Andrew MacLeod
2023-06-27 16:24 ` Jan Hubicka
2023-06-27 17:54 ` Andrew MacLeod [this message]
2023-06-28 7:37 ` Jan Hubicka
2023-06-27 15:14 ` Martin Jambor
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=a4f6bf28-fe8a-d4db-9a10-0642559de1c6@redhat.com \
--to=amacleod@redhat.com \
--cc=aldyh@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=hubicka@ucw.cz \
--cc=jwakely@redhat.com \
--cc=mjambor@suse.cz \
/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).