Heroic constant folding (was micro-optimizing loops etc.)

Walter Bright bright at nazgul.UUCP
Sat Mar 23 21:28:48 AEST 1991


In article <RJOHNSON.91Mar11141459 at olorin.shell.com> rjohnson at shell.com (Roy Johnson) writes:
/>Of course, the best optimization for:
/>	for (i = 1; i < 100; i++)
/>		x += i;
/>is:
/>	x += 4950;
/This doesn't look to be such a bad thing to optimize away (speaking
/with all the authority of one who doesn't write compilers).

Actually, it is probably not worth the bother to attempt to optimize away.
In general, a program that needs to be optimized is one that is going to be
run many times. A loop that is determinate (doesn't change from run to run)
generally does not appear in a program that is to be run many times.

There are still lots of unexploited opportunities for optimizations in
code that *does* commonly appear in production programs.



More information about the Comp.lang.c mailing list