From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8821 invoked by alias); 12 Apr 2010 16:43:18 -0000 Received: (qmail 8745 invoked by uid 48); 12 Apr 2010 16:43:00 -0000 Date: Mon, 12 Apr 2010 16:43:00 -0000 Subject: [Bug c/43732] New: -ffixed-reg and register globals broken for MIPS X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "lance604 at gmail dot com" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2010-04/txt/msg01183.txt.bz2 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 : 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 : 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 : 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