Take the following code: #define NUMPOINTS 20 static float opoints[NUMPOINTS];
double sqrt (double); double f(double); void NormalizeVectors1 (void) { int i, r; float s, x, y, z; static float d = 0.0; d += 0.2f; s = d; for (i=0; i<NUMPOINTS; i++) opoints[i] = f(s); } Compile at -O2 and -O3 and compare. See how we load/store now at -O3 to the static variable, d inside the loop. -- Summary: [4.1 Regression] We produce worse code on the mainline for a loop Product: gcc Version: 4.1.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal 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=22532