Bug 19905

Summary: Extra V_MAY_DEF on a static variable whose address is not taken (we should be able to move the load out of the loop)
Product: gcc Reporter: Andrew Pinski <pinskia>
Component: tree-optimizationAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: enhancement CC: dnovillo, gcc-bugs
Priority: P2 Keywords: missed-optimization
Version: 4.0.0   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2009-04-22 22:15:04
Bug Depends on: 22532    
Bug Blocks: 18439, 20367    

Description Andrew Pinski 2005-02-11 14:47:15 UTC
The following two functions should be the same (note don't compile with -ffast-math or even -fno-
math-errno as sqrt is marked as pure)

#define NUMPOINTS 20

float opoints[NUMPOINTS];

double sqrt (double);

void NormalizeVectors (void)
{
  int i, r;
  float s, x, y, z;
  static float d = 0.0;
  
  d += 0.2f;
  
  if (d > 4)
    d = 0.0;
  
  for (i=0; i<NUMPOINTS; i++)
  {
    opoints[i] = sqrt (d);
  }
}
void NormalizeVectors1 (void)
{
  int i, r;
  float s, x, y, z;
  static float d = 0.0;

  d += 0.2f;

  if (d > 4)
    d = 0.0;
  s = d;

  for (i=0; i<NUMPOINTS; i++)
  {
    opoints[i] = sqrt (s);
  }
}
Comment 1 Andrew Pinski 2005-02-20 14:12:07 UTC
Confirmed.
Comment 2 Andrew Pinski 2005-05-08 17:40:26 UTC
oh, why is d considered call clobbered when it cannot be:
Variable: d.0, UID 0, float
Variable: d, UID 1, float, is global, call clobbered, default def: d_4
Comment 3 Andrew Pinski 2005-07-17 20:34:11 UTC
This is not fixed Kenny's promote statics, in fact we now produce worse code at -O3.  Note on ppc-
darwin the code is fine since -fno-math-errno is done by default.
Comment 4 Andrew Pinski 2005-07-17 20:52:36 UTC
(In reply to comment #3)
> This is not fixed Kenny's promote statics, in fact we now produce worse code at -O3.  Note on ppc-
> darwin the code is fine since -fno-math-errno is done by default.
I filed that as PR 22532.

Comment 5 Andrew Pinski 2005-08-23 16:40:01 UTC
I think the FIXME in tree-ssa-operands.c is the answer 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 6 Richard Biener 2014-03-13 10:52:31 UTC
Long fixed.