Take this "stupid" example (even though this most likely shows up in GCC but I don't know for sure): int g1(int); static void h(int *a) { *a = 1; } int g(void) { int t = 0; h(&t); int t1 = t; g1(t1); return t1 == t; } That return should have been turned into "return 1" as t does not escape via h as h only touches it. Compile with -O3 -fno-inline to see the problem.
Confirmed.
I think the FIXME in tree-ssa-operands.c is the issue here: /* FIXME - if we have better information from the static vars analysis, we need to make the cache call site specific. This way we can have the performance benefits even if we are doing good optimization. */
The comment actually has nothing to do with the actual problem here
ICC does not even do this optimization. I should note that Fortran code has something like this, except you don't need to know about the function that is being called, just the variable and if it has TARGET on it or not.
r162134 at -O3: ;; Function h (h) h (int * a) { <bb 2>: *a_1(D) = 1; return; } ;; Function g (g) g () { int t1; int t; int t.0; int D.1984; <bb 2>: t = 0; h (&t); t1_1 = t; g1 (t1_1); t.0_2 = t; D.1984_3 = t1_1 == t.0_2; return D.1984_3; } r162134 at -O3 -fipa-pta: ;; Function h (h) h (int * a) { <bb 2>: *a_1(D) = 1; return; } ;; Function g (g) g () { int t1; int t; <bb 2>: t = 0; h (&t); t1_1 = t; g1 (t1_1); return 1; } Thus, fixed with -fipa-pta. Richi, test case for you?
There is already testcases like this in gcc.dg/ipa/ipa-pta-*.c