Patch to improve shadowing of loop variables

Toon Moene
Mon Aug 7 13:37:00 GMT 2000

Michael Hayes wrote:

> Toon Moene writes:

>  > Hmmm, I'd hoped that it would improve induction variable strength
>  > reduction and elimination for Fortran code that has to be translated
>  > with -fno-automatic (which makes all local variables static).

> Do you have some RTL for a simple example?  I wrote the code to be
> very conservative and there may well be a simple solution.

Hmmm, perhaps it's easier if you experiment for yourself (I do not know
how much of the function's RTL you need to get to a useful conclusion):


      subroutine sum(a, b, c, n)
      integer i, n
      real a(n), b(n), c(n)
      do i = 1, n
         c(i) = a(i) + b(i)

Assembler with -O2 on i686-pc-linux-gnu (loop only):

        flds    (%eax)
        addl    $4, %eax
        fadds   (%edx)
        addl    $4, %edx
        fstps   (%ecx)
        addl    $4, %ecx
        decl    %ebx
        jns     .L6

Assembler with -O2 -fno-automatic:

        flds    (%edi,%edx)
        incl    %ecx
        fadds   (%esi,%edx)
        fstps   (%ebx,%edx)
        addl    $4, %edx
        decl    %eax
        jns     .L6

[ Note how on the ia32 architecture *not* strength-reducing the
  induction variables _in this small loop_ seems actually beneficial ]

$ /usr/snp/bin/g77 -v
g77 version 2.96 20000807 (experimental) (from FSF-g77 version 0.5.26
20000807 (experimental))

Hope this helps,

Toon Moene - - phoneto: +31 346 214290
Saturnushof 14, 3738 XG  Maartensdijk, The Netherlands
GNU Fortran 77:
GNU Fortran 95: (under construction)

More information about the Gcc-patches mailing list