Patch to improve shadowing of loop variables
Toon Moene
toon@moene.indiv.nluug.nl
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):
Fortran:
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)
enddo
end
Assembler with -O2 on i686-pc-linux-gnu (loop only):
.L6:
flds (%eax)
addl $4, %eax
fadds (%edx)
addl $4, %edx
fstps (%ecx)
addl $4, %ecx
decl %ebx
jns .L6
Assembler with -O2 -fno-automatic:
.L6:
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 - mailto:toon@moene.indiv.nluug.nl - phoneto: +31 346 214290
Saturnushof 14, 3738 XG Maartensdijk, The Netherlands
GNU Fortran 77: http://gcc.gnu.org/onlinedocs/g77_news.html
GNU Fortran 95: http://g95.sourceforge.net/ (under construction)
More information about the Gcc-patches
mailing list