Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84 SMI; site sun.uucp
Path: utzoo!utcsrgv!garfield!philabs!cmcl2!seismo!harvard!godot!mit-eddie!genrad!decvax!decwrl!sun!gnu
From: gnu@sun.uucp (John Gilmore)
Newsgroups: net.unix-wizards,net.lang
Subject: Re:  smart compilers
Message-ID: <1900@sun.uucp>
Date: Wed, 26-Dec-84 01:52:49 EST
Article-I.D.: sun.1900
Posted: Wed Dec 26 01:52:49 1984
Date-Received: Wed, 26-Dec-84 22:41:36 EST
References: <6599@brl-tgr.ARPA> <979@opus.UUCP> <1146@ut-ngp.UUCP> <18397@lanl.ARPA> <2061@umcp-cs.UUCP> <18469@lanl.ARPA>
Organization: Sun Microsystems, Inc.
Lines: 20

> James Giles says:
>               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.

You're absolutely right!  Had you had a good data flow analyzer, it
would have detected that your optimization had changed the value of 'I'
on exit from this piece of code.