possible gcse failure: not able to eliminate redundant loads

Toon Moene toon@moene.indiv.nluug.nl
Tue Dec 17 15:20:00 GMT 2002


Richard Henderson wrote:

> On Mon, Dec 16, 2002 at 11:46:57PM +0100, Toon Moene wrote:
> 
>>Yes, that's impossible to express in Fortran (90/95/F2K), hence we don't 
>>have to worry about it.
>>
>>[ The way to do this in Fortran is to write:
>>
>>        IF (ASSOCIATED(P)) THEN
>>            .... USE P
>>        ELSE
>>            .... BETTER KEEP YOUR PAWS OFF ....
>>        ENDIF

> Um, isn't this still exactly what I talked about?  The use of P
> is protected by a conditional.

Yes, it might well be that I do not understand the purpose of the 
prohibition of this optimization in GCC.  Obviously (he says now :-) I 
expect optimizations to conserve the "correct program" property, i.e. if 
A is a program in Fortran then opt(A) also is a program in Fortran (note 
that this property is - much - weaker than: encodes the same computation).

If we do not conserve this property, then all bets are off:

       DIMENSION A(10), B(11)
       ...
       DO I = 1, 11
          IF (I .GT. 10) THEN
             B(I) = 0.0 ! Default value
          ELSE
             B(I) = A(I)
          ENDIF
       ENDDO
       END

Of course this is not a valid Fortran program if the compiler moved 
B=A(I) out of the IF .. THEN .. ELSE .. ENDIF construct.

-- 
Toon Moene - mailto:toon@moene.indiv.nluug.nl - phoneto: +31 346 214290
Saturnushof 14, 3738 XG  Maartensdijk, The Netherlands
Maintainer, GNU Fortran 77: http://gcc.gnu.org/onlinedocs/g77_news.html
Join GNU Fortran 95: http://g95.sourceforge.net/ (under construction)



More information about the Gcc mailing list