On Wed, 5 Jun 2019, Richard Biener wrote:

The following was inspired by Marins work on escapes of locals
and the discussion there.  It teaches points-to analysis that
the point of function return is special and thus escapes through
that a) do not influence other points-to solutions, b) can be
pruned of all locals.

This is one example of reasonably simple "post-processing".

The effects are small, I've done statistics, counting the number
of variables we do not mark escaped only after this patch.  This
number is usually zero, sometimes one and a few cases more
(but never more than 11) during bootstrap:

0 95830
1 19268
2 19
3 2
5 2
6 1
8 1
11 1

so not sure if it is worth all the effort.  It does allow us
to do more DSE but that requires the accesses to be indirect
which is not often true for locals.

IIUC, if we did not have IPA and PT was used only to check for potential aliasing, we could skip return statements entirely. In that sense, it may sound worth working around the penalty imposed by the other uses, although after inlining the cases where this matters may be rare.

However, the patch doesn't really seem to disable much of the impact of a return statement. If I randomly try

int g;
int*f(int**x){
  int*p=*x;
  int*q=__builtin_malloc(4);
  *p=4;*q=5;g=*p;*p=6;
#ifdef OK
  int volatile i=*q;
  int*volatile v=q;
  return 0;
#else
  return q;
#endif
}

With -DOK, q does not escape, we know that p and q do not alias, and we simplify quite a bit. Without -DOK, q does escape, and we simplify nothing. Replacing malloc with alloca works, but returning a pointer to a local variable is not really an interesting case...

Maintaining 2 escaped sets (with/without returns) would be overkill for this, unless it was part of a wider flow-sensitivity strategy.

--
Marc Glisse

Reply via email to