This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Fix powerpc zapping static chain
On Mon, Mar 24, 2003 at 01:20:07PM -0800, Geoff Keating wrote:
> Alan Modra <amodra at bigpond dot net dot au> writes:
>
> > The following testcase compiled with powerpc-linux-gcc -fpic shows r11,
> > the static chain pointer, being zapped inside function bar.
> >
> > extern int x;
> > int foo (void)
> > {
> > int y;
> > int bar (void) { return x + y; }
> > return bar ();
> > }
> >
> > This patch fixes the problem, and marks the instructions used to save
> > and restore LR as possibly dead. See PR 8659 for why they might be
> > dead with new-ra.
> >
> > * config/rs6000/rs6000.c (rs6000_emit_prologue): Use r12 for
> > save_LR_around_toc_setup, and mark insns as maybe_dead. Simplify
> > cr_save_rtx test.
> >
> > Bootstrapped, regtested powerpc-linux. OK mainline? 3.3 too?
>
> No, not OK.
>
> I don't see any explanation in PR 8659. In fact, that bug was closed with:
>
> > I tried with plain 3.2.1 and the testcase now compiles fine.
>
> so it doesn't seem relevant to 3.3 or to mainline.
I'm fixing two different bugs with this patch. First, there's the fact
that r11 is overwritten as shown by the testcase I included. Did you
bother to compile it? Here's -fpic -O1 output for bar:
bar.0:
stwu 1,-32(1)
stw 30,24(1)
mflr 11 # r11 overwritten
bl _GLOBAL_OFFSET_TABLE_ at local-4
mflr 30
mtlr 11
stw 11,8(1)
lwz 9,x at got(30)
lwz 3,0(9)
lwz 0,0(11) # r11 used as static chain
add 3,3,0
lwz 30,24(1)
addi 1,1,32
blr
The second bug is an inconsistency. The instructions that save and
restore LR around the GOT pointer setup are not marked with
REG_MAYBE_DEAD, yet we go to the bother of marking the GOT pointer
setup insns with REG_MAYBE_DEAD. Presumably the GOT pointer setup
insns are marked with good reason, they might be deleted. If they are
deleted, then a sufficiently intelligent optimizer should realize that
the save and restore of LR can also be deleted. Thus they also need
marking with REG_MAYBE_DEAD. No, I don't have a testcase to show this
happening. Does that mean the patch is wrong?
--
Alan Modra
IBM OzLabs - Linux Technology Centre