This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [mips] fix $gp restore bug
Richard Sandiford writes:
> FWIW, the idea I'm toying with at the moment is:
>
> - Make every branch use pic_offset_table_rtx.
>
> - Try to detect cases where a function only needs a global pointer
> because of branches. In this case, emit easily-identifiable "ghost"
> instructions (in the .md "type" attribute sense) to set, save and
> restore the gp.
>
> These ghost instructions would replace the sequences we'd normally use.
> They would have 0 length at this stage, and in theory shouldn't interfere
> with things like scheduling.
>
> - At the end of md_reorg, run shorten_branches to see whether
> all branches are in range. This should be safe because we run
> dbr_schedule within mips_reorg. Nothing after mips_reorg should
> change the insn stream besides shorten_branches itself.
>
> - If some branches are not in range, go through the insn stream and
> replace all the ghost instructions with real implementations.
> (This will of course invalidate the results of the shorten_branches
> call, but the "real" shorten_branches pass will then calculate new
> lengths.)
This sounds like a good plan to me, FWIW.
> Besides the complication, the main drawback I can see is that we'd be
> unable to fill the delay slots of branches with insns that restore $gp,
> even in the usual case where no long branches are needed.
>
> That's certainly a problem for -Os. I'm not sure it's much of a concern
> for other options. dbr_schedule doesn't take the pipeline into account
> at all when filling delay slots, and postponing a restoration of $gp
> isn't always a good idea performance-wise.
I guess this applies more to the old ABIs. For the new ABIs all we lose is
the possibility to optimally schedule the pic_offset_table_rtx instructions
and that the register in pic_offset_table_rtx won't be available to the
register allocator even though it might be never used or used for a shorter
time than assumed.
Adam