Bug 25572 - ppc64 -mminimal-toc trashes r30
Summary: ppc64 -mminimal-toc trashes r30
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.0.3
: P3 normal
Target Milestone: 3.4.6
Assignee: Alan Modra
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2005-12-27 00:16 UTC by Anton Blanchard
Modified: 2006-01-01 05:35 UTC (History)
3 users (show)

See Also:
Host:
Target: powerpc64-unknown-linux-gnu
Build:
Known to work: 4.0.3 3.4.6 4.1.0 4.2.0
Known to fail: 3.3.3 4.0.0 3.4.0
Last reconfirmed: 2005-12-28 05:18:48


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Anton Blanchard 2005-12-27 00:16:17 UTC
We found this problem when building a ppc64 Linux kernel. It turns out r30 was not preserved in a function that was using a local TOC. The compiler used was:

gcc version 4.0.3 20051201 (prerelease) (Debian 4.0.2-5)

Although it seems to reproduce on older toolchains too (eg 3.4).

pinskia cut the original test case down to:

/* Compile with -m64 -O2 -mminimal-toc */
int per_cpu__kstat;

int *f()
{
  int *__ptr;
  asm volatile(";%0":"=g"(__ptr):"0"(&per_cpu__kstat));
  return __ptr;
}

/*
.f:
        ld 30,.LCTOC0@toc(2)
        ld 9,.LC0-.LCTOC1(30)
        mr 3,9
#APP
        ;3
#NO_APP

*/
Comment 1 Andrew Pinski 2005-12-27 00:18:30 UTC
Confirmed, not a regression.
Comment 2 Alan Modra 2005-12-28 03:03:33 UTC
Happens at -O0 too.  At -O0, r30 is used for the first time when reload decides that the asm_operands in the following needs reloading.  regs_ever_live[30] isn't set.

(insn 8 6 10 3 (set (mem/c/i:DI (plus:DI (reg/f:DI 113 sfp)
                (const_int 48 [0x30])) [0 __ptr+0 S8 A128])
        (asm_operands/v:DI (";%0") ("=g") 0 [
                (symbol_ref:DI ("per_cpu__kstat") <var_decl 0x80003499a0 per_cpu__kstat>)
            ]
             [
                (asm_input:DI ("0"))
            ] ("/src/tmp/pr25572.c") 7)) -1 (nil)
    (nil))
Comment 3 Alan Modra 2005-12-28 04:52:59 UTC
Adding
  if (no_new_pseudos)
    regs_ever_live[TOC_REGISTER] = 1;
to rs6000.c:create_TOC_reference fixes this problem.  There seems to be precedent for such chicanery: eg. rs6000_got_register and a number of places in i386.c setting regs_ever_live[PIC_OFFSET_TABLE_REGNUM].
Comment 4 Alan Modra 2005-12-29 01:10:11 UTC
Subject: Bug 25572

Author: amodra
Date: Thu Dec 29 01:10:05 2005
New Revision: 109133

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=109133
Log:
	PR target/25572
	* config/rs6000/rs6000.c (create_TOC_reference): Set regs_ever_live.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/rs6000/rs6000.c

Comment 5 Alan Modra 2005-12-29 01:14:21 UTC
Subject: Bug 25572

Author: amodra
Date: Thu Dec 29 01:14:18 2005
New Revision: 109134

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=109134
Log:
	PR target/25572
	* config/rs6000/rs6000.c (create_TOC_reference): Set regs_ever_live.


Modified:
    branches/gcc-4_1-branch/gcc/ChangeLog
    branches/gcc-4_1-branch/gcc/config/rs6000/rs6000.c

Comment 6 Alan Modra 2005-12-29 01:20:19 UTC
Subject: Bug 25572

Author: amodra
Date: Thu Dec 29 01:20:15 2005
New Revision: 109135

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=109135
Log:
	PR target/25572
	* config/rs6000/rs6000.c (create_TOC_reference): Set regs_ever_live.


Modified:
    branches/gcc-4_0-branch/gcc/ChangeLog
    branches/gcc-4_0-branch/gcc/config/rs6000/rs6000.c

Comment 7 Alan Modra 2005-12-29 01:29:21 UTC
Subject: Bug 25572

Author: amodra
Date: Thu Dec 29 01:29:18 2005
New Revision: 109136

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=109136
Log:
	PR target/25572
	* config/rs6000/rs6000.c (create_TOC_reference): Set regs_ever_live.


Modified:
    branches/gcc-3_4-branch/gcc/ChangeLog
    branches/gcc-3_4-branch/gcc/config/rs6000/rs6000.c

Comment 8 Alan Modra 2005-12-29 01:29:52 UTC
Fixed