smart compilers

Norman Diamond ndiamond at watdaisy.UUCP
Mon Dec 31 08:27:15 AEST 1984


> Ho hum...  The CORRECT [sic] optimization for:
> 
> 	DO 100 I = 1 TO 10
> 	IF (Y .GT. 0) X(I) = SQRT(Y)
> 	100 CONTINUE
> 
> Is, in Ratfor syntax:
> 
> 	IF (Y > 0) {
> 		TEMP = SQRT(Y)
> 		DO I = 1,10
> 			X(I) = TEMP
> 	}
> 	ELSE
> 		I = 11
> 
> (In some implementations the number 11 will be something else, most
> likely 10, but leaving I unchanged is clearly wrong!)

The else case can leave anything at all in I and still be correct.
The value of I is undefined after completion of the DO loop, and when
optimized it remains undefined after the IF statement (whether the
then-branch or ELSE-branch is taken).  The most optimal setting of
I is to leave it alone, requiring 0 machine instructions.

Otherwise, this suggestion was correct, as were several others.

-- Norman Diamond

UUCP:  {decvax|utzoo|ihnp4|allegra|clyde}!watmath!watdaisy!ndiamond
CSNET: ndiamond%watdaisy at waterloo.csnet
ARPA:  ndiamond%watdaisy%waterloo.csnet at csnet-relay.arpa

"Opinions are those of the keyboard, and do not reflect on me or higher-ups."



More information about the Comp.unix.wizards mailing list