This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: -freduce-all-givs and fortran
- To: Toon Moene <moene at knmi dot nl>
- Subject: Re: -freduce-all-givs and fortran
- From: Toon Moene <toon at moene dot indiv dot nluug dot nl>
- Date: Thu, 06 Sep 2001 22:28:08 +0200
- CC: aj at suse dot de, jh at suse dot de, gcc-patches at gcc dot gnu dot org, gcc at gcc dot gnu dot org
- Organization: Moene Computational Physics, Maartensdijk, The Netherlands
- References: <3B979A4B.3886AC01@knmi.nl>
I wrote:
> OK, so swim indeed gets most optimised "without" loop optimisation.
>
> :-)
>
> Someone who shall remain nameless showed me a (small) part of swim that
> should fall wholly within the "fair use" clause. I mailed it home to
> study it there (where I actually have access to g77 :-)
>
> However, I think I already know what's wrong ...
The problem is easily exemplified by the following code:
$ cat swim.f
SUBROUTINE SWIM
PARAMETER(N=100)
COMMON /COM/ A(N), B(N), C(N)
COMMON /INT/ M
DO I = 1, M
A(I) = B(I) + C(I)
ENDDO
END
Because giv-combining should notice that any reference to A, B and C is
simply addr(COMMON) + constant, the final number of registers needed in
the loop is just 2: One for that base address and one for the loop
counter. However, this is what we get from g77 -O2 -S swim.f when using
the latest snapshot (on alphaev6-unknown-linux-gnu):
$L5:
lds $f10,0($3)
lds $f11,0($2)
mov $6,$1
lda $3,4($3)
addl $1,$31,$5
lda $2,4($2)
lda $6,-1($6)
adds $f10,$f11,$f10
sts $f10,0($4)
lda $4,4($4)
bge $5,$L5
which uses 6 integer registers ($1 .. $6) [I get the feeling Alpha is
even worse off than all other architectures here] but at least it's
clear that the three registers for addressing $3, $2 and $4 is overdone
by 2.
More arrays in this common block make this worse (the original swim code
had 7, which means 8 registers in the inner loop, 2 more than available
to a Pentium I/II/III/IV or Athlon).
Somehow, the giv-combine code doesn't examine the base addresses of
these arrays [quoting swim.f.11.loop]:
Giv 78: insn 38 src reg 69 benefit 4 lifetime 1 replaceable ncav
mult (4)
add (0)
Giv 79: insn 39 src reg 69 benefit 8 lifetime 5 replaceable
mult (4)
add (-4)
Giv 80: insn 40 src reg 69 benefit 4 lifetime 8 replaceable
mult (4)
add (const (plus (symbol_ref ("com_")) (-4)))
Giv 88: insn 51 src reg 69 benefit 4 lifetime 3 replaceable
mult (4)
add (const (plus (symbol_ref ("com_")) (396)))
Giv 96: insn 62 src reg 69 benefit 4 lifetime 2 replaceable
mult (4)
add (const (plus (symbol_ref ("com_")) (796)))
Dest address: insn 64 src reg 69 benefit 4 lifetime 1 replaceable
mult (4)
add (const (plus (symbol_ref ("com_")) (396)))
Dest address: insn 66 src reg 69 benefit 4 lifetime 1 replaceable
mult (4)
add (const (plus (symbol_ref ("com_")) (796)))
Dest address: insn 69 src reg 69 benefit 4 lifetime 1 replaceable
mult (4)
add (const (plus (symbol_ref ("com_")) (-4)))
Giv 101: insn 75 src reg 69 benefit 4 lifetime 1 replaceable
mult (1)
add (1)
Giv 74: insn 22 src reg 70 benefit 4 lifetime 1 replaceable
mult (1)
add (-1)
Loop iterations: Initial value not constant (reg 70).
Final biv value for 70, biv dead after loop exit.
Cannot eliminate biv 70: biv used in insn 27.
Sorted combine statistics:
{22, 0}
giv at 22 reduced to (reg 108)
biv 69 can be eliminated.
Sorted combine statistics:
{39, 8} {69, 4} {66, 4} {64, 4} {75, 0} {62, 0} {51, 0} {40, 0} {38, 0}
Note that it *does* notice that register 69 is the source of all these
base addresses.
Perhaps I find time during the weekend to dig into this.
--
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)