smart compilers

Chris Torek chris at umcp-cs.UUCP
Sun Dec 23 08:18:21 AEST 1984


> It is usually necessary for optimizations to break certain obscure points
> that conform to the language definition, e.g. which order STATEMENTS are
> executed in so that code can be moved out of loops.

Depends on what you mean.  If the loop is guaranteed to be executed at
least once, then moving loop-invariant expressions out of loops is
fine.  If the loop might not get executed, then you can always optimize

	for i := j to k { ... invariant-expr ... }

into

	if j <= k then {
		temp := invariant-expr;
		i := j; do { ... temp ... } while ++i <= k;
	}

(please excuse the syntax).  Note that the "do" is probably slightly
more efficient than the "for", and should probably be used to avoid
degrading performance when j always <= k.

Of course, if you allow such things as interrupts which modify variables
into your language, then the optimizer must be either MUCH smarter (has
to read and understand all your interrupt handlers [.5 :-)]) or you need
hints like ``volatile''.
-- 
(This line accidently left nonblank.)

In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (301) 454-7690
UUCP:	{seismo,allegra,brl-bmd}!umcp-cs!chris
CSNet:	chris at umcp-cs		ARPA:	chris at maryland



More information about the Comp.unix.wizards mailing list