This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Reload patch v4
- To: Jeffrey A Law <law at cygnus dot com>
- Subject: Re: Reload patch v4
- From: Bernd Schmidt <crux at Pool dot Informatik dot RWTH-Aachen dot DE>
- Date: Thu, 8 Oct 1998 14:43:43 +0200 (MET DST)
- cc: egcs-patches at cygnus dot com
> > I believe it is safe because of the following piece of code in
> > forget_old_reloads_1. Note the comment at the top, it seems to describe
> > the scenario we are discussing.
> >
> > /* Storing into a spilled-reg invalidates its contents.
> > This can happen if a block-local pseudo is allocated to that reg
> > and it wasn't spilled because this block's total need is 0.
> > Then some insn might have an optional reload and use this reg. */
> > for (i = 0; i < nr; i++)
> > /* But don't do this if the reg actually serves as an output
> > reload reg in the current instruction. */
> > if (n_reloads == 0
> > || ! TEST_HARD_REG_BIT (reg_is_output_reload, regno + i))
> > CLEAR_HARD_REG_BIT (reg_reloaded_valid, regno + i);
> Right, but do we see all stores into the spill reg?
forget_old_reloads is called from reload_as_needed for every insn that it
sees, not just those which need reloads. The situation we are worrying
about at the moment should always look mostly like this:
- insn 1 uses hard reg A as reload register; and it's marked as usable for
inheritance
- insn 2 stores hard reg A because it was allocated to a pseudo X
whose lifetime starts here (there _must_ be a store here, since otherwise
X would be live before this insn, and therefore so would A, and A could
not have been used as a reload register in insn 1).
- insn 3 uses hard reg A (for pseudo X); X dies here, which means that after
this insn, A can again be used as reload reg
- insn 4 uses hard reg A as reload register, the reloaded value from insn
1 would match, but we can't use it because A was used in between as a
normal hard reg allocated as a pseudo.
The question is, does the inheritance code notice that insns 2 and 3 make
A unavailable for reload inheritance in insn 4? To decide that, we need
to know how insns 2 and 3 will look like during reload_as_needed. Pseudo
X is allocated to A, that means reg_renumber[X] == A, and alter_reg will
have been called before reload_as_needed for pseudo X (all the interesting
calls to alter_reg happen before reload_as_needed; those which happen during
are only there to improve debugging output a bit).
This means all references to pseudo X are gone from the RTL, we only ever see
A where X used to be. (Pseudos that did not get a hard reg will still be
visible, because alter_reg does not substitute a MEM into regno_reg_rtx).
Then, when reload_as_needed is done processing insn 1, it will get to insn
number 2.
Suppose insn 2 does not need reloads, then all we are going to do with it is
to call note_stores (..., forget_old_reloads_1) on it. And this in turn will
notice that hard reg A is being set, and clear reg_reloaded_valid for it.
This will later prevent reg A from being used for inheritance in insn 4.
Suppose that insn 2 does need reloads, but none of these affect the set of
reg A. Then the same argument applies, we'll call forget_old_reloads on
the insn, and the set of reg A is still there.
Suppose that the set of reg A gets output reloaded. That case is handled
as well, since emit_reload_insns calls note_stores (..., forget_old_reloads_1)
for all the insns it emits. One of them will be a set of reg A, and the
same argument as above applies.
All in all, I'm fairly certain that the problem that can already happen
with the code that avoids spilling block-local pseudos, and the similar
problem that could occur with more clever spill code, are both avoided.
> You might also look at the call in emit_reload_insns -- I don't think we've
> one register replacements at the time when we call forget_old_reloads_1 from
> emit_reload_insns.
Sorry, I'm not sure about the terminology. What do you mean by "register
replacements"? If you mean calls to alter_reg which change those pseudos
which were lucky into hard regs: those have been done already.
Bernd