> > 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! Cool, thanks for the explanation! I pushed the following simplified version of the patch. Now back to getting push_back faster :)
gcc/ChangeLog: PR tree-optimization/110377 * ipa-prop.cc (ipa_compute_jump_functions_for_edge): Pass statement to the ranger query. (ipa_analyze_node): Enable ranger. gcc/testsuite/ChangeLog: PR tree-optimization/110377 * gcc.dg/ipa/pr110377.c: New test. diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc index 41c812194ca..33bda8288fc 100644 --- a/gcc/ipa-prop.cc +++ b/gcc/ipa-prop.cc @@ -2386,7 +2386,7 @@ ipa_compute_jump_functions_for_edge (struct ipa_func_body_info *fbi, if (TREE_CODE (arg) == SSA_NAME && param_type - && get_range_query (cfun)->range_of_expr (vr, arg) + && get_range_query (cfun)->range_of_expr (vr, arg, cs->call_stmt) && vr.nonzero_p ()) addr_nonzero = true; else if (tree_single_nonzero_warnv_p (arg, &strict_overflow)) @@ -2408,7 +2408,7 @@ ipa_compute_jump_functions_for_edge (struct ipa_func_body_info *fbi, && Value_Range::supports_type_p (param_type) && irange::supports_p (TREE_TYPE (arg)) && irange::supports_p (param_type) - && get_range_query (cfun)->range_of_expr (vr, arg) + && get_range_query (cfun)->range_of_expr (vr, arg, cs->call_stmt) && !vr.undefined_p ()) { Value_Range resvr (vr); @@ -3190,7 +3190,9 @@ ipa_analyze_node (struct cgraph_node *node) bi->cg_edges.safe_push (cs); } + enable_ranger (cfun, false); analysis_dom_walker (&fbi).walk (ENTRY_BLOCK_PTR_FOR_FN (cfun)); + disable_ranger (cfun); ipa_release_body_info (&fbi); free_dominance_info (CDI_DOMINATORS); diff --git a/gcc/testsuite/gcc.dg/ipa/pr110377.c b/gcc/testsuite/gcc.dg/ipa/pr110377.c new file mode 100644 index 00000000000..63120a97bd0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/pr110377.c @@ -0,0 +1,16 @@ +/* { dg-do compile */ +/* { dg-options "-O2 -fdump-ipa-cp" } */ +int test3(int); +__attribute__ ((noinline)) +void test2(int a) +{ + test3(a); +} +void +test(int n) +{ + if (n > 5) + __builtin_unreachable (); + test2(n); +} +/* { dg-final { scan-ipa-dump "-INF, 5" "cp" } } */