On 2/10/23 02:45, Richard Biener wrote:
On Fri, Feb 10, 2023 at 1:02 AM Andrew MacLeod via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
I was about to ping on this, and then found it in my drafts.. Doh!


get_range_global() can invoke tree.cc::nonnull_arg_p() if the item being
queried is a pointer and a parameter.  This routine assumes the context
is CFUN, and this is not always true.
Can you share the backtrace where the context is different and cfun not NULL?
I'm curious ..


Its from the assume pass when we are trying to map the actual p[aramater passed to a function with the global value we assigned to the parameter in that function.ie

   // determine x has a global range of [10, 200] in this function.
assume_func (int x) { if (x>=10 || x<=200) return 1; else return 0; }

myfunc() {
  int y_3
  assume_func (y_3)   //  Here, we lookup assume_fund parameter list, and assign [10,200]                      //  to the range of y_3 via the inferred range mechanism

}

The traceback is:

0x1e77e95 nonnull_arg_p(tree_node const*)
    /gcc/master/gcc/gcc/tree.cc:14438
0x1e96241 get_range_global
    /gcc/master/gcc/gcc/value-query.cc:330
0x1e96668 global_range_query::range_of_expr(vrange&, tree_node*, gimple*)
    /gcc/master/gcc/gcc/value-query.cc:406
0x32483c4 gimple_infer_range::check_assume_func(gcall*)
    /gcc/master/gcc/gcc/gimple-range-infer.cc:87
0x32488e8 gimple_infer_range::gimple_infer_range(gimple*)
    /gcc/master/gcc/gcc/gimple-range-infer.cc:166
0x3249635 infer_range_manager::register_all_uses(tree_node*)
    /gcc/master/gcc/gcc/gimple-range-infer.cc:374
0x3248e94 infer_range_manager::has_range_p(tree_node*, basic_block_def*)
    /gcc/master/gcc/gcc/gimple-range-infer.cc:273
0x3248f7e infer_range_manager::maybe_adjust_range(vrange&, tree_node*, basic_block_def*)
    /gcc/master/gcc/gcc/gimple-range-infer.cc:290
0x1c8b6e1 path_range_query::adjust_for_non_null_uses(basic_block_def*)
    /gcc/master/gcc/gcc/gimple-range-path.cc:501
0x1c8bf23 path_range_query::compute_ranges(bitmap_head const*)
    /gcc/master/gcc/gcc/gimple-range-path.cc:622
0x1c8a40a path_range_query::reset_path(vec<basic_block_def*, va_heap, vl_ptr> const&, bitmap_head const*)
    /gcc/master/gcc/gcc/gimple-range-path.cc:229
0x1c89af0 path_range_query::path_range_query(gimple_ranger&, vec<basic_block_def*, va_heap, vl_ptr> const&, bitmap_head const*, bool)
    /gcc/master/gcc/gcc/gimple-range-path.cc:50
0x1d52a96 back_threader::find_taken_edge_cond(vec<basic_block_def*, va_heap, vl_ptr> const&, gcond*)
    /gcc/master/gcc/gcc/tree-ssa-threadbackward.cc:324

This patch simply adds a function context to the get_range_global query,
and defaults it to cfun. If the context passed in is anything different
than cfun, then it simply chooses not to invoke nonnull_arg_p().

The check_assume function now directly calls gimple_range_global with
the correct function context instead of indirectly calling it through
the global_range_query->range_of_expr () method. Thats all it should
have been doing in the first place really since its always an ssa name.

Bootstraps on x86_64-pc-linux-gnu with no regressions.  OK for trunk?
OK.

Note that in the end nonnull_arg_p should get a struct function argument
as well, and its flag_delete_null_pointer_checks then need to become
opt_for_fn (fn->decl, flag_delete_null_pointer_checks).

I'll also note that for functions with many arguments nonnull_arg_p is
quite expensive and nonnull_arg_p on a PARM_DECL default-def
should be reflected on its range by a pass and we shouldn't re-query
this in any on-demand called function.

At the moment, Its only being queried thjis way as we try to resolve these assume_functions.  IF we enhance this to utilize IPA information next release in a similar way, it'll become more prevalent


Reply via email to