Bug 23134

Summary: Address escapes even though the called function does not cause it to escape
Product: gcc Reporter: Andrew Pinski <pinskia>
Component: tree-optimizationAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: enhancement CC: gcc-bugs, P.Schaffnit, rguenth
Priority: P2 Keywords: alias, missed-optimization
Version: 4.1.0   
Target Milestone: 4.6.0   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2006-08-21 06:05:19

Description Andrew Pinski 2005-07-29 13:40:01 UTC
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.
Comment 1 Serge Belyshev 2005-07-29 13:57:51 UTC
Confirmed.
Comment 2 Andrew Pinski 2005-08-11 17:20:21 UTC
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.  */
Comment 3 Daniel Berlin 2005-10-10 12:45:23 UTC
The comment actually has nothing to do with the actual problem here
Comment 4 Andrew Pinski 2005-12-24 07:54:35 UTC
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.
Comment 5 Steven Bosscher 2010-07-13 10:33:30 UTC
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?


Comment 6 Richard Biener 2010-07-13 13:34:39 UTC
There is already testcases like this in gcc.dg/ipa/ipa-pta-*.c