Heroic constant folding (was micro-optimizing loops etc.)
Roy Johnson
rjohnson at shell.com
Tue Mar 12 08:14:59 AEST 1991
In article <1991Mar2.010049.21044 at grebyn.com> ckp at grebyn.com (Checkpoint Technologies) 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).
You "simply" check each loop to be sure that there are no function
calls, and that all variables referenced in the loop are initialized
there. Then you can generate appropriate moves instead of a loop.
If you want to initialize an array, though, the usual time-space
tradeoff is still there: you generate n move instructions to
initialize a size n array, rather than probably two moves, an
addition/increment, a conditional, and a goto.
--
======= !{sun,psuvax1,bcm,rice,decwrl,cs.utexas.edu}!shell!rjohnson =======
Feel free to correct me, but don't preface your correction with "BZZT!"
Roy Johnson, Shell Development Company
More information about the Comp.lang.c
mailing list