Loop opt weirdness

Andreas Schwab schwab@issan.cs.uni-dortmund.de
Fri Jun 11 01:45:00 GMT 1999


Suppose we have the following loop:

----------------------------------------------------------------------
(note 26 62 27 "" NOTE_INSN_DELETED)

(insn 27 26 29 (set (reg:SI 33)
        (plus:SI (reg/v:SI 29)
            (const_int -4 [0xfffffffc]))) 126 {*addsi3_internal} (nil)
    (nil))

(insn 29 27 31 (set (mem:SI (reg:SI 33) 2)
        (reg/v:SI 30)) 42 {movsi+1} (nil)
    (nil))

(insn 31 29 33 (set (reg:SI 34)
        (plus:SI (reg/v:SI 29)
            (const_int -8 [0xfffffff8]))) 126 {*addsi3_internal} (nil)
    (nil))

(insn 33 31 35 (set (mem:SI (reg:SI 34) 2)
        (reg/v:SI 30)) 42 {movsi+1} (nil)
    (nil))

(insn 35 33 37 (set (reg:SI 35)
        (plus:SI (reg/v:SI 29)
            (const_int -12 [0xfffffff4]))) 126 {*addsi3_internal} (nil)
    (nil))

(insn 37 35 39 (set (mem:SI (reg:SI 35) 2)
        (reg/v:SI 30)) 42 {movsi+1} (nil)
    (nil))

(insn 39 37 41 (set (reg/v:SI 29)
        (plus:SI (reg/v:SI 29)
            (const_int -16 [0xfffffff0]))) 126 {*addsi3_internal} (nil)
    (nil))

(insn 41 39 43 (set (mem:SI (reg/v:SI 29) 2)
        (reg/v:SI 30)) -1 (nil)
    (nil))

(note 43 41 60 "" NOTE_INSN_LOOP_CONT)
----------------------------------------------------------------------

Register 29 is a biv, and there are four givs at insns 27, 31, 35 and 41:

----------------------------------------------------------------------
Loop from 17 to 49: 10 real insns.
Continue at insn 43.
Insn 27: possible biv, reg 29, const = -4
Insn 31: possible biv, reg 29, const = -4
Insn 35: possible biv, reg 29, const = -4
Insn 39: possible biv, reg 29, const = -4
Reg 29: biv verified
Biv 29 initialized at insn 15: initial value is complex
Increment 27 of biv 29 converted to giv 33.

Increment 31 of biv 29 converted to giv 34.

Increment 35 of biv 29 converted to giv 35.

Insn 41: dest address src reg 29 benefit 0 lifetime 1 replaceable ncav mult 1 add 0
Loop iterations: Not normal loop.
Final biv value for 29, biv dead after loop exit.
Cannot eliminate biv 29: biv used in insn 20.
----------------------------------------------------------------------

Now in combine_givs the giv at 41 is combined with the giv at 35:

----------------------------------------------------------------------
Sorted combine statistics:
 {35, 6} {31, 6} {27, 6} {41, 1}
giv at 41 combined with giv at 35
----------------------------------------------------------------------

So far so good.  The strength reduced giv is computed as

(plus:SI (reg:SI 35)
    (const_int 12 [0xc]))

Wrong, this completely ignores the biv increment at insn 39.  The correct
expression would be (plus (reg 35) -4).

Can someone please explain me how this is supposed to work?

Andreas.

-- 
Andreas Schwab                                      "And now for something
schwab@issan.cs.uni-dortmund.de                      completely different"
schwab@gnu.org


More information about the Gcc mailing list