Optimization
Jim Wilson
wilson@cygnus.com
Thu Apr 2 11:32:00 GMT 1998
for (i=0; i<100; i++)
for (j=0; j<100; j++)
for (k=0; k<100; k++)
*(x+i*step[2]+j*step[1]+k*step[0]) *=
*(x+i*step[2]+j*step[1]+k*step[0]);
This is a hard problem. We can't move the loads from step[] outside
the loop unless we can know for sure that the stores into *(x+...) won't
modify any of the values pointed to by step. Since we have no info about
where x or step point to, we make the worst case assumption that they
overlap, and hence the loads from step[] are not loop invariant.
It is actually a bit more complicated than that (we have type info to help
with aliasing), but it is still a complicated problem.
The ISO C9X restrict keyword would make this optimization easier, because
this would allow the programmer to tell the compiler that there is no aliasing.
Jim
More information about the Gcc
mailing list