On Mon, 10 Jun 2019, Marc Glisse wrote: > 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.
So even non-IPA needs escapes through return because we started to use this to track whether allocated storage becomes "global" and thus DSE needs to preserve stores that end up "used" by the return stmt(s). The wider issue here is that PTA globs escapes through returns and escapes through calls. It somewhat makes sense since there's also escapes through stores to global memory which means reachability from both callees and callers. So for the above example q _does_ escape through return q. A first step would be to present a separate "escapes from function invocation" to the PTA users. Since there's global memory escapes the optimization effect is probably similarly small as with the return "enhacement" though. The return enhancment helps when local variables "leak" into the points-to sets returned from the function. Richard.