Reload inheritance and auto inc/dec

Alexandre Oliva aoliva@redhat.com
Tue Sep 12 04:33:00 GMT 2000


I've been investigating a reload problem that showed up while
compiling some code for SH.  Basically, the problem is that reload
didn't take advantage of inheritance for a pseudo used in an post_inc
memory reference, and, in a subsequence insn, ended up inheriting the
value of an out-dated register.

A longer description of the problem follows.  After lreg, we had:

(insn 939 197 199 (set (reg:SI 130)
        (reg:SI 14 r14)) 85 {movsi_i} (nil)
    (nil))

(insn 199 939 200 (set (reg:QI 120)
        (mem/s:QI (post_inc:SI (reg:SI 130)) 0)) 89 {movqi_i} (insn_list 939 (nil))
    (expr_list:REG_INC (reg:SI 130)
        (nil)))

[snip]

(insn 220 218 221 (set (reg:QI 131)
        (mem/s:QI (reg:SI 130) 0)) 89 {movqi_i} (insn_list 218 (nil))
    (expr_list:REG_EQUIV (mem/s:QI (reg:SI 130) 0)
        (nil)))

The relevant reloads are:

Reloads for insn # 941
Reload 0: reload_out (SI) = (mem:SI (plus:SI (reg:SI 15 r15)
                                                        (const_int 32 [0x20])) 0)
	NO_REGS, RELOAD_FOR_OUTPUT (opnum = 0), optional
	reload_out_reg: (reg:SI 130)
Reload 1: reload_in (SI) = (plus:SI (reg:SI 15 r15)
                                                    (const_int 4 [0x4]))
	GENERAL_REGS, RELOAD_FOR_INPUT (opnum = 1)
	reload_in_reg: (plus:SI (reg:SI 15 r15)
                                                    (const_int 4 [0x4]))
	reload_reg_rtx: (reg:SI 2 r2)

Reloads for insn # 199
Reload 0: reload_in (SI) = (mem:SI (plus:SI (reg:SI 15 r15)
                                                        (const_int 32 [0x20])) 0)
	reload_out (SI) = (mem:SI (plus:SI (reg:SI 15 r15)
                                                        (const_int 32 [0x20])) 0)
	GENERAL_REGS, RELOAD_OTHER (opnum = 1)
	reload_in_reg: (mem:SI (plus:SI (reg:SI 15 r15)
                                                        (const_int 32 [0x20])) 0)
	reload_out_reg: (mem:SI (plus:SI (reg:SI 15 r15)
                                                        (const_int 32 [0x20])) 0)
	reload_reg_rtx: (reg:SI 0 r0)

Reloads for insn # 220
Reload 0: reload_in (SI) = (mem:SI (plus:SI (reg:SI 15 r15)
                                                        (const_int 32 [0x20])) 0)
	GENERAL_REGS, RELOAD_FOR_OPERAND_ADDRESS (opnum = 1), can't combine
	reload_in_reg: (reg:SI 130)
	reload_reg_rtx: (reg:SI 2 r2)

You see, it used register r0 for the post-increment and, even though
it ends up copying r0 from r2, it doesn't copy it back, and insn 220
ends up using r2, because the scan for an equivalent register ignores
reload-generated insns, but insn 941 is considered, since it's
modified by reload.  The end result is:

(insn 1127 197 1128 (set (reg:SI 2 r2)
        (const_int 4 [0x4])) 85 {movsi_i} (nil)
    (nil))

(insn 1128 1127 941 (set (reg:SI 2 r2)
        (plus:SI (reg:SI 2 r2)
            (reg:SI 15 r15))) 18 {addsi3} (nil)
    (expr_list:REG_EQUIV (plus:SI (reg:SI 15 r15)
            (const_int 4 [0x4]))
        (nil)))

(insn 941 1128 1131 (set (mem:SI (plus:SI (reg:SI 15 r15)
                (const_int 32 [0x20])) 0)
        (reg:SI 2 r2)) 85 {movsi_i} (nil)
    (nil))

(insn 1131 941 199 (set (reg:SI 0 r0)
        (reg:SI 2 r2)) 85 {movsi_i} (nil)
    (nil))

(insn 199 1131 1134 (set (reg:QI 7 r7)
        (mem/s:QI (post_inc:SI (reg:SI 0 r0)) 0)) 89 {movqi_i} (insn_list 941 (nil))
    (expr_list:REG_INC (reg:SI 0 r0)
        (nil)))

(insn 1134 199 200 (set (mem:SI (plus:SI (reg:SI 15 r15)
                (const_int 32 [0x20])) 0)
        (reg:SI 0 r0)) 85 {movsi_i} (nil)
    (nil))

[snip]

(insn 220 218 221 (set (reg:QI 1 r1)
        (mem/s:QI (reg:SI 2 r2) 0)) 89 {movqi_i} (insn_list 218 (nil))
    (expr_list:REG_EQUIV (mem/s:QI (reg:SI 2 r2) 0)
        (nil)))

The problem seemed to be that choose_reload_regs would never set
search_equiv in case both rld.in and .out were set, which is the case
for an auto-inc memory reference.  The following patch fixes the
problem, arranging for the register to be inherited for the reload for
insn 199.  Is it ok to install?

I'm wondering whether there is some way to eliminate insn 941, since
the same memory address is being overwritten in insn 1134, and it
doesn't seem to me that the value read in insn 199 might be reading
from it.



More information about the Gcc-patches mailing list