[mips] fix $gp restore bug

Richard Sandiford rdsandiford@googlemail.com
Tue Feb 3 20:22:00 GMT 2009


Nathan Sidwell <nathan@codesourcery.com> writes:
> Richard Sandiford wrote:
>> Hmm.  Let me think about this one a bit.  Although I agree your patch
>> fixes the particular problem you found, I think there's another,
>> related, problem: because the use of $gp is implicit, it isn't enough
>> on its own to stop the optimisers from deleting the $gp restore insn.
>
> good point.  IIUC the only case that could happen would be a (huge)
> function that accessed no (other) global state and only called
> functions via function pointers (that were passed in as argument).

That's only locally true, not of the function as a whole.  E.g.:

    [A] call
    [B] restore $gp
    [C] if (foo) goto [E]
    [D] indirect call
    ...
    [E] indirect call
    ...

Then [D] and [E] would clobber $gp, so even if there are GOT uses
after [D] and [E], the optimisers could delete [B].  The same applies
if [D] and/or [E] are replaced by return statements.

> Or is the optimizer able to defer $gp restore to a later point such
> that it's available by the time an instruction explicitly refers to
> it?

Yeah, the scheduler (for one) can move things across block boundaries.

Richard



More information about the Gcc-patches mailing list