Newsgroups: comp.lang.c Path: utzoo!utgpu!cunews!dgbt!don From: don@dgbt.doc.ca (Donald McLachlan) Subject: re: optimizing Message-ID: <1991Mar12.164518.9878@dgbt.doc.ca> Sender: don@dgbt.doc.ca (Donald McLachlan) Organization: The Communications Research Centre, Ottawa, Canada Date: Tue, 12 Mar 91 16:45:18 GMT > >From: rjohnson@shell.com (Roy Johnson) >Newsgroups: comp.lang.c >Subject: Re: Heroic constant folding (was micro-optimizing loops etc.) > >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. I would also recommend checking that those variables are not decalared volatile. It is possible that another processor is watching the progression of a variable through certain states (not likely under Unix, but C is no limited to Unix:-).