Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.1 6/24/83; site umcp-cs.UUCP
Path: utzoo!utcsrgv!garfield!philabs!cmcl2!seismo!umcp-cs!mangoe
From: mangoe@umcp-cs.UUCP (Charley Wingate)
Newsgroups: net.unix-wizards,net.lang
Subject: Re:  smart compilers
Message-ID: <2061@umcp-cs.UUCP>
Date: Fri, 21-Dec-84 17:42:05 EST
Article-I.D.: umcp-cs.2061
Posted: Fri Dec 21 17:42:05 1984
Date-Received: Sat, 22-Dec-84 09:43:18 EST
References: <6599@brl-tgr.ARPA> <979@opus.UUCP> <1146@ut-ngp.UUCP> <18397@lanl.ARPA>
Organization: U of Maryland, Computer Science Dept., College Park, MD
Lines: 38

In article <18397@lanl.ARPA> jlg@lanl.ARPA writes:

>> However, the IBM H Level FORTRAN Programmer's Guide does warn that code
>> such as
>> 
>> 	DO 100 I = 1 TO 10
>> 	IF (Y .GT. 0) X(I) = SQRT(Y)
>>     100 CONTINUE
>> 
>> (with X appropriately declared as an array of course) can cause an error
>> because it tries to take the square root of a negative number.  The
>> optimizer compiles this as if it were
>> 
>> 	TEMP = SQRT(Y)
>> 	DO 100 I = 1 TO 10
>> 	IF (Y .GT. 0) X(I) = TEMP
>>     100 CONTINUE

>This particular example should be optimized as
>
>      IF ( Y.GT.0 ) TEMP=SQRT(Y)
>      DO 100 I = 1,10         !THERE ARE NO 'TO' DELIMITERS IN FORTRAN
>         X(I)=TEMP            !FOLLOW INDENTATION STANDARDS PLEASE
>100   CONTINUE

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

If Y is negative, X should be unchanged, according to the original program.
My feeling is that an optimizer should produce the same "action" on some
well-defined level as the original unoptimized code.  Well-defined in this
case should be equivalent to well-documented.

Charley Wingate   umcp-cs!mangoe