smart compilers

jlg at lanl.ARPA jlg at lanl.ARPA
Sat Dec 22 11:09:19 AEST 1984


> Wrong again.  A correct optimization would be
> 
>       If (Y.GT.0) Temp=Sqrt(Y)
>       Do 100 I=1,10
>          If (Y.GT.0) X(I)=Temp
>   100 Continue

Quite right!  My first version was wrong.  But 'Y' is a loop invariant, the
correct optimization is:

      IF (Y.GT.0) THEN
         TEMP=SQRT(Y)
         DO 100 I=1,10
            X(I)=TEMP
100      CONTINUE
      ENDIF

This has the advantage of not going through the loop at all if the
assignments would all have been skipped.  All these examples show the point
I originally made: these optimizations are unsafe unless you have a REALLY
GOOD data flow analyzer.

------------------------------------------------------------------------------
The greatest derangement of the mind is to believe in something
because one wishes it to be so - Louis Pasteur

                                              James Giles



More information about the Comp.unix.wizards mailing list