Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!lavaca.uh.edu!menudo.uh.edu!lobster!shell!shell!rjohnson From: rjohnson@shell.com (Roy Johnson) Newsgroups: comp.lang.c Subject: Re: Heroic constant folding (was micro-optimizing loops etc.) Message-ID: Date: 11 Mar 91 22:14:59 GMT References: <10191@dog.ee.lbl.gov> <14522@ganymede.inmos.co.uk> <10450@dog.ee.lbl.gov> <1991Mar2.010049.21044@grebyn.com> Sender: usenet@shell.shell.com (USENET News System) Organization: Shell Development Company, Bellaire Research Center, Houston, TX Lines: 23 In-Reply-To: ckp@grebyn.com's message of 2 Mar 91 01:00:49 GMT In article <1991Mar2.010049.21044@grebyn.com> ckp@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