Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84; site lanl.ARPA
Path: utzoo!utcsrgv!garfield!philabs!cmcl2!lanl!jlg
From: jlg@lanl.ARPA
Newsgroups: net.unix-wizards,net.lang
Subject: Re:  smart compilers
Message-ID: <18469@lanl.ARPA>
Date: Fri, 21-Dec-84 20:09:19 EST
Article-I.D.: lanl.18469
Posted: Fri Dec 21 20:09:19 1984
Date-Received: Sat, 22-Dec-84 09:43:36 EST
References: <6599@brl-tgr.ARPA> <979@opus.UUCP> <1146@ut-ngp.UUCP> <18397@lanl.ARPA> <2061@umcp-cs.UUCP>
Sender: newsreader@lanl.ARPA
Organization: Los Alamos National Laboratory
Lines: 27

> 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