On Wed, 24 Nov 2021, Jan Hubicka wrote:

> > This improves value-numbering of calls that read memory, calls
> > to const functions with aggregate arguments and calls to
> > pure functions where the latter include const functions we
> > demoted to pure for the fear of interposing with a less
> > optimized version.  Note that for pure functions we do not
> > handle functions that access global memory.
> 
> Thank you! I am happy we finally undid some of the pessimization caused
> by the interposition panic.  I was wondering if I should try next stage1
> start tracking eliminated reads in functions, but that is tricky to do
> since things like if (*global_var == *globa_var) is folded already in
> frontend.
> 
> I was thinking a bit what to do abou global accesses and I think we
> still can do something (also next stage1).  
> 
> Currently we disambiguate using
>   if (stmt_may_clobber_ref_p_1 (def, &ref, true))
> where ref is the REF is a ao_ref we built from the summary of STMT and
> DEF is another statement.  This is fine but we ignore info we have from
> PTA on STMT (the statement we try to optimize).
> 
> I we could look at DEF, and try to disambiguate all memory it
> writes against STMT using PTA oracle and that would let us to handle
> global memory well (we don't need REF for that) because we will work out
> that some accesses are not escaping to STMT becaue they are not in
> CALLUSED. Somewhat anoying is that we don't have predicate in
> tree-ssa-alias for that (stmt_clobber_stmt_p :)

Yes, note that we don't have callused unless IPA PTA is enabled,
but it might be salveagable from IPA reference info?  What we're
missing is a stmt_clobbers_pt_solution_p, or rather a reasonably
cheap way to construct an ao_ref covering all of a points-to
solution.  The not-so-cheap way to do that is

  tree tem = make_ssa_name (ptr_type_node);
  ptr_info_def *pi = get_ptr_info (p);
  pt->pt = *gimple_call_use_set (call_stmt);
  tree ref = build2 (MEM_REF, void_type_node /* ?? */, tem, build_zero_cst 
(ptr_type_node /* that effectively is ref-all */));
  ao_ref_init (&r, ref);
  r->base = ref;
  r->ref = NULL_TREE;
  r->offset = 0;
  r->alias_set = 0;
  r->base_alias_set = 0;

and if we come from IPA reference we first have to build a
points-to bitmap as well.

What would be a bit more convenient is probably adding
a pt_solution * member to ao_ref.  Maybe also avoiding
the MEM_REF build we already do in some cases and overload
the base field using a union and a designator ...

But yes, sth for next stage1.

Richard.

Reply via email to