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

Reply via email to