From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22351 invoked by alias); 17 Apr 2011 17:31:22 -0000 Received: (qmail 22343 invoked by uid 22791); 17 Apr 2011 17:31:21 -0000 X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RFC_ABUSE_POST,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org Received: from mail-wy0-f175.google.com (HELO mail-wy0-f175.google.com) (74.125.82.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 17 Apr 2011 17:31:08 +0000 Received: by wye20 with SMTP id 20so4095651wye.20 for ; Sun, 17 Apr 2011 10:31:07 -0700 (PDT) Received: by 10.227.179.68 with SMTP id bp4mr4267615wbb.110.1303061467015; Sun, 17 Apr 2011 10:31:07 -0700 (PDT) Received: from localhost (rsandifo.gotadsl.co.uk [82.133.89.107]) by mx.google.com with ESMTPS id ed10sm2783233wbb.49.2011.04.17.10.31.05 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 17 Apr 2011 10:31:06 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, rdsandiford@googlemail.com Subject: [committed] Fix handling of global registers in MIPS prologues Date: Sun, 17 Apr 2011 18:40:00 -0000 Message-ID: <877hashjjb.fsf@firetop.home> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2011-04/txt/msg01331.txt.bz2 PR 45074 showed up a rather embarrassing oversight in the MIPS backend: global registers were still being treated as call-saved. Fixed with the attached patch. Tested on mips64-linux-gnu and applied. Richard gcc/ * config/mips/mips.c (mips_cfun_call_saved_reg_p): Handle global registers. gcc/testsuite/ * gcc.target/mips/reg-var-1.c: New test. Index: gcc/config/mips/mips.c =================================================================== --- gcc/config/mips/mips.c 2011-04-16 09:02:10.000000000 +0100 +++ gcc/config/mips/mips.c 2011-04-17 11:14:53.000000000 +0100 @@ -9097,6 +9097,11 @@ mips_interrupt_extra_call_saved_reg_p (u static bool mips_cfun_call_saved_reg_p (unsigned int regno) { + /* If the user makes an ordinarily-call-saved register global, + that register is no longer call-saved. */ + if (global_regs[regno]) + return false; + /* Interrupt handlers need to save extra registers. */ if (cfun->machine->interrupt_handler_p && mips_interrupt_extra_call_saved_reg_p (regno)) Index: gcc/testsuite/gcc.target/mips/reg-var-1.c =================================================================== --- /dev/null 2011-04-17 10:56:28.045573347 +0100 +++ gcc/testsuite/gcc.target/mips/reg-var-1.c 2011-04-17 11:22:39.000000000 +0100 @@ -0,0 +1,16 @@ +/* { dg-do run } */ +register int g asm ("$18"); + +void __attribute__((noinline)) +test (void) +{ + g = g + 1; +} + +int +main (void) +{ + g = 2; + test (); + return g != 3; +}