Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84; site sdcsla.UUCP
Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!godot!harvard!seismo!hao!hplabs!sdcrdcf!sdcsvax!sdcsla!west
From: west@sdcsla.UUCP (Larry West)
Newsgroups: net.lang.f77
Subject: Re: bug using loop variable as start value
Message-ID: <763@sdcsla.UUCP>
Date: Fri, 18-Jan-85 23:53:03 EST
Article-I.D.: sdcsla.763
Posted: Fri Jan 18 23:53:03 1985
Date-Received: Mon, 21-Jan-85 04:35:30 EST
References: <787@ttds.UUCP>
Reply-To: west@sdcsla.UUCP (Larry West)
Organization: UC San Diego: Institute for Cognitive Science
Lines: 49
Summary: 

In article <787@ttds.UUCP> sundman@ttds.UUCP (Bo Sundman) writes:
>	DIMENSION X(10)
>	L=1
>	DO 100 L=L,10
>	   X(L)=L
>100	CONTINUE
>200	WRITE(*,*)L,X
>	I=1
>	DO 300 L=I,10
>	   X(L)=L
>300	CONTINUE
>400	WRITE(*,*)L,X
>	END
>
>C Output from the example:
>C
>C  2147479256  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
>C  11   1.00000   2.00000   3.00000   4.00000   5.00000   6.00000   7.00000
>C   8.00000   9.00000   10.0000
 
Bo did not say what computer/OS this was done on, but I tried this out
on a Sun and Vax-11/750, running nearly identical 4.2bsd.   The bug only
appeared on the Vax, withOUT the "-O" flag.   According to "f77 -v", this
is "Berkeley F77, version 1.0", while on the Sun it's "SMI F77, version 1.1".
 
Looking at the assembly language output (VAX, w/o "-O"), it's easy to see
the error: at the start of the loop, register 10 is loaded from itself:
 
L13: 
        movl    $1,v.2-v.1(r11)
        movl    r10,r10
        cmpl    r10,$10 
        jgtr    L16 
 
This is the first access to "r10" in the program.   The correct code is 
emitted by the VAX f77 with "-O": 
 
L13:    movl    $1,v.2-v.1(r11) 
        movl    v.2-v.1(r11),r10
        movl    r10,r10
        cmpl    r10,$10
        jgtr    L16
 
Seems like optimization by comparison, of course... 
-- 

--|  Larry West, UC San Diego, Institute for Cognitive Science
--|  UUCP:	{decvax!ucbvax,ihnp4}!sdcsvax!sdcsla!west
--|  ARPA:	west@NPRDC	{ NOT:  }