Help with casts

Walter Bright bright at nazgul.UUCP
Wed Mar 6 05:14:56 AEST 1991


/Bear in mind that C is one of the hardest languages in the world to
/optimize. For instance, in pascal the index of a for loop cannot be referenced
/outside of that loop, thus the code can be optimized by making that index a
/register variable. ... 

C is hard to optimize, but that is because of the aliasing problem, not
identification of loop variables. Standard textbook algorithms exist
(see the Dragon Book) which can identify the loop variable(s) from out
of a rat's nest of goto's. It is also easilly determined if the loop variable
is used after exit of the loop or not.

In fact, I'd say it was easier and more reliable than fiddling with the
loop constructs in a parse tree... The right way to optimize is to convert
everything to a bunch of expressions connected by goto's. Then analyze the
goto's to determine the loops and everything else needed.

I've implemented these algorithms in Zortech's optimizer, and they do work.
They did have to be modified, however, to support the idea that ints and
pointers are not the same size!



More information about the Comp.lang.c mailing list