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);
  }
}

-- 
           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
           Version: 4.0.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P2
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: pinskia at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19905

Reply via email to