This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: [Patch] Do not rerun loop optimisation by default.


I wrote:

> So I'll refrain from performing this update and rather concentrate on
> why a rerun of loop optimisation _sometimes_ makes things worse (like in
> the two-common-block example).

I might have a handle on why rerunning loop optimisation sometimes makes
things worse.  Take the two-common-blocks example:

$ cat ../swim2.f
      SUBROUTINE SWIM
      PARAMETER(N=100)
      COMMON /COM1/ A(N), B(N), C(N)
      COMMON /COM2/ X(N), Y(N), Z(N)
      COMMON /INT/ M
      DO I = 1, M
         A(I) = B(I) + C(I)
         X(I) = Y(I) + Z(I)
      ENDDO
      END

If we look at swim2.f.11.loop, we see the following:

First run of loop optimisation:

...
Giv 63: insn 36 src reg 58 benefit 4 lifetime 1 replaceable ncav
 mult (4)
 add  (0)
Giv 64: insn 38 src reg 58 benefit 8 lifetime 8 replaceable
 mult (4)
 add  (-4)
Dest address: insn 56 src reg 58 benefit -1 lifetime 1 replaceable
 mult (4)
 add  (const (plus (symbol_ref ("com1_")) (396)))
Dest address: insn 58 src reg 58 benefit -1 lifetime 1 replaceable
 mult (4)
 add  (const (plus (symbol_ref ("com1_")) (796)))
Dest address: insn 61 src reg 58 benefit -1 lifetime 1 replaceable
 mult (4)
 add  (const (plus (symbol_ref ("com1_")) (-4)))
Dest address: insn 90 src reg 58 benefit -1 lifetime 1 replaceable
 mult (4)
 add  (const (plus (symbol_ref ("com2_")) (396)))
Dest address: insn 92 src reg 58 benefit -1 lifetime 1 replaceable
 mult (4)
 add  (const (plus (symbol_ref ("com2_")) (796)))
Dest address: insn 95 src reg 58 benefit -1 lifetime 1 replaceable
 mult (4)
 add  (const (plus (symbol_ref ("com2_")) (-4)))
Loop iterations: Initial value not constant (reg 59).
Final biv value for 59, biv dead after loop exit.
Cannot eliminate biv 59: biv used in insn 23.
Sorted combine statistics:

biv 58 can be eliminated.
Sorted combine statistics:
 {38, 20} {95, 3} {92, 3} {90, 3} {61, 3} {58, 3} {56, 3} {36, 0}
giv at 95 combined with giv at 38; new benefit 8 + 0, lifetime 9
giv at 92 combined with giv at 38; new benefit 8 + 0, lifetime 10
giv at 90 combined with giv at 38; new benefit 8 + 0, lifetime 11
giv at 61 combined with giv at 38; new benefit 8 + 0, lifetime 12
giv at 58 combined with giv at 38; new benefit 8 + 0, lifetime 13
giv at 56 combined with giv at 38; new benefit 8 + 0, lifetime 14
Sorted combine statistics:
 {36, 0}
giv at 95 reduced to (plus (reg 92) (symbol_ref ("com2_")))
giv at 92 reduced to (plus (reg 92) (const (plus (symbol_ref ("com2_"))
(800))))
giv at 90 reduced to (plus (reg 92) (const (plus (symbol_ref ("com2_"))
(400))))
giv at 61 reduced to (plus (reg 92) (symbol_ref ("com1_")))
giv at 58 reduced to (plus (reg 92) (const (plus (symbol_ref ("com1_"))
(800))))
giv at 56 reduced to (plus (reg 92) (const (plus (symbol_ref ("com1_"))
(400))))
giv at 38 reduced to (reg 92)
giv at 36 reduced to (reg 93)
...

[ and we get the six offsets combined with *one* giv ]

Second loop optimisation:

...
Dest address: insn 56 src reg 92 benefit -1 lifetime 1 replaceable
 mult (1)
 add  (const (plus (symbol_ref ("com1_")) (400)))
Dest address: insn 58 src reg 92 benefit -1 lifetime 1 replaceable
 mult (1)
 add  (const (plus (symbol_ref ("com1_")) (800)))
Dest address: insn 61 src reg 92 benefit -1 lifetime 1 replaceable
 mult (1)
 add  (symbol_ref ("com1_"))
Dest address: insn 90 src reg 92 benefit -1 lifetime 1 replaceable
 mult (1)                       
 add  (const (plus (symbol_ref ("com2_")) (400)))
Dest address: insn 92 src reg 92 benefit -1 lifetime 1 replaceable
 mult (1)                       
 add  (const (plus (symbol_ref ("com2_")) (800)))
Dest address: insn 95 src reg 92 benefit -1 lifetime 1 replaceable
 mult (1)                       
 add  (symbol_ref ("com2_"))
Loop iterations: Initial value not constant (reg 59).
Final biv value for 59, biv dead after loop exit.
Cannot eliminate biv 59: biv used in insn 23.
Sorted combine statistics:

Final biv value for 58, biv dead after loop exit.
biv 58 can be eliminated. 
Sorted combine statistics:

biv 58 was eliminated.
Reg 58: biv eliminated
Final biv value for 93, biv dead after loop exit.
biv 93 can be eliminated.
Sorted combine statistics:   

biv 93 was eliminated.
Reg 93: biv eliminated
biv 92 can be eliminated.
Sorted combine statistics:
 {95, 3} {92, 3} {90, 3} {61, 3} {58, 3} {56, 3}
giv at 92 combined with giv at 95; new benefit -1 + 0, lifetime 2
giv at 90 combined with giv at 95; new benefit -1 + 0, lifetime 3
Sorted combine statistics:
 {61, 3} {58, 3} {56, 3}
giv at 58 combined with giv at 61; new benefit -1 + 0, lifetime 2
giv at 56 combined with giv at 61; new benefit -1 + 0, lifetime 3
Sorted combine statistics:

giv at 95 reduced to (reg 95)
giv at 92 reduced to (plus (reg 95) (800))
giv at 90 reduced to (plus (reg 95) (400))
giv at 61 reduced to (reg 96)
giv at 58 reduced to (plus (reg 96) (800))
giv at 56 reduced to (plus (reg 96) (400))
...

[ and the six offsets are combined with *two* givs ]

However, the difference is that in the second round, there are two givs
of the following form:

 mult (1)
 add  (symbol_ref ("com{1,2}_"))

Note the absence of "const" in the add_val.  If this absence has real
significance to giv combining, it would explain why the second set of
givs cannot "expressed_from" the first one: Their difference is not a
constant and hence cannot be expressed in the register+offset form.

Unfortunately, I haven't yet found

1. Why a single symbol_ref isn't "const", while a symbol_ref+const is.

2. Whether this actually matters in the way I mention above.

-- 
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)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]