public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "lance604 at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/43732]  New: -ffixed-reg and register globals broken for MIPS
Date: Mon, 12 Apr 2010 16:43:00 -0000	[thread overview]
Message-ID: <bug-43732-19025@http.gcc.gnu.org/bugzilla/> (raw)

With gcc 4.4.3 and 4.3.4 and MIPS target, code is incorrectly generated to
save/restore registers specified as "fixed" via the "-ffixed-reg" command-line
option to gcc. This also applies to register globals (which should be treated
as "fixed".)

Test code (test.c):

    register int foo asm ("$23");

    void test(void)
    {
          foo = 0;
    }

Compiler invocation:

    mips-unknown-linux-gnu-gcc -ffixed-s7 -O2 -c test.c

Disassembly of above code build with gcc 4.2.2 (correct):

    4.2.2/test.o:     file format elf32-tradbigmips

    Disassembly of section .text:

    00000000 <test>:
       0:   03e00008        jr      ra
       4:   0000b821        move    s7,zero
            ...

Disassembly with gcc 4.4.3 (incorrectly saves/restores s7, optimizes away
assignment to register global):
    4.4.3/test.o:     file format elf32-tradbigmips

    Disassembly of section .text:

    00000000 <test>:
       0:   27bdfff8        addiu   sp,sp,-8
       4:   afb70004        sw      s7,4(sp)
       8:   8fb70004        lw      s7,4(sp)
       c:   03e00008        jr      ra
      10:   27bd0008        addiu   sp,sp,8
            ...

Patch that appears to fix this issue:
diff -Naur gcc-4.4.3.base/gcc/config/mips/mips.c
gcc-4.4.3/gcc/config/mips/mips.c
--- gcc-4.4.3.base/gcc/config/mips/mips.c       2010-04-09 14:10:00.235609702
-0400
+++ gcc-4.4.3/gcc/config/mips/mips.c    2010-04-09 14:12:28.520998582 -0400
@@ -8495,7 +8495,7 @@
      property here.  */
   return (regno == GLOBAL_POINTER_REGNUM
          ? TARGET_CALL_SAVED_GP
-         : !call_really_used_regs[regno]);
+         : !call_really_used_regs[regno] && !fixed_regs[regno]);
 }

 /* Return true if the function body might clobber register REGNO.


Disassembled output with above patch applied:
    4.4.3fix/test.o:     file format elf32-tradbigmips

    Disassembly of section .text:

    00000000 <test>:
       0:   03e00008        jr      ra
       4:   0000b821        move    s7,zero
            ...


-- 
           Summary: -ffixed-reg and register globals broken for MIPS
           Product: gcc
           Version: 4.4.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: lance604 at gmail dot com
 GCC build triplet: x86_64-build_pc-linux-gnu
  GCC host triplet: x86_64-build_pc-linux-gnu
GCC target triplet: mips-unknown-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43732


             reply	other threads:[~2010-04-12 16:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-12 16:43 lance604 at gmail dot com [this message]
2010-04-12 18:18 ` [Bug c/43732] " pinskia at gcc dot gnu dot org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-43732-19025@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).