From patchwork Sun Aug 26 19:23:18 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 180082 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 238FE2C00F6 for ; Mon, 27 Aug 2012 05:23:36 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1346613817; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:From:To:Mail-Followup-To:Subject:Date:Message-ID: User-Agent:MIME-Version:Content-Type:Mailing-List:Precedence: List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=9w5axBYFFqC1R1rNPgCRfqrGabg=; b=yMbGMjS84InrR9b 0Mca5tvkQyV17/rBtwIhwCb7EcPFyxsbF+tMPk+RIKmMVY3Gr7wGLkzry5CgIr8I VHe/NfkoZoE0D5dAkaAOShefBwQOjLsaLYBMZXLjvTrbK/c3wJ9CyOGK7LrIPBT2 XFAFM1HHZLZP1nbytm8fDScI2tfU= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:From:To:Mail-Followup-To:Subject:Date:Message-ID:User-Agent:MIME-Version:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=ZROfjfheE8uH8uQ74m3f4mC2vCmCSOElfbpxB/F66JYV70XtWF46NU2Ec0ec+S ZyiT++o/Tt6iJW3cNYlfhnBLB7OkG9izAyVthK8obFjddUjiyP9CXmmEin5G3JLf Bcj5mI0cu0+ZzHsE81k77dAguX6Ekr5FcHp6fYGKtNDQo=; Received: (qmail 26460 invoked by alias); 26 Aug 2012 19:23:34 -0000 Received: (qmail 26451 invoked by uid 22791); 26 Aug 2012 19:23:33 -0000 X-SWARE-Spam-Status: No, hits=-4.3 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, KHOP_RCVD_TRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE X-Spam-Check-By: sourceware.org Received: from mail-wi0-f179.google.com (HELO mail-wi0-f179.google.com) (209.85.212.179) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 26 Aug 2012 19:23:20 +0000 Received: by wibhq4 with SMTP id hq4so2034099wib.8 for ; Sun, 26 Aug 2012 12:23:18 -0700 (PDT) Received: by 10.180.98.200 with SMTP id ek8mr20029434wib.0.1346008998817; Sun, 26 Aug 2012 12:23:18 -0700 (PDT) Received: from localhost ([2.26.188.227]) by mx.google.com with ESMTPS id k20sm11042577wiv.11.2012.08.26.12.23.17 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 26 Aug 2012 12:23:17 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, rdsandiford@googlemail.com Subject: [MIPS, committed] Fix handling of long branches with delay slots Date: Sun, 26 Aug 2012 20:23:18 +0100 Message-ID: <87fw7931ax.fsf@talisman.home> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) MIME-Version: 1.0 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Converting gcc.target/mips to gcc-dg showed up a brown-paper-bag bug in my long-branch code. The function that checks whether $gp is needed only for long branches runs (and must run) after delayed-branch scheduling, but it wasn't looking inside the SEQUENCEs. I also made the code check the same jump condition as mips16_split_long_branches. Tested on mipsisa64-elf, mips64-elf and mips64-linux-gnu. Applied. Will be tested once gcc.target/mips uses gcc-dg. Richard gcc/ * config/mips/mips.c (mips_has_long_branch_p): New function, split out from... (mips_expand_ghost_gp_insns): ...here. Look inside sequences. Index: gcc/config/mips/mips.c =================================================================== --- gcc/config/mips/mips.c 2012-08-26 11:21:13.000000000 +0100 +++ gcc/config/mips/mips.c 2012-08-26 11:32:09.530815882 +0100 @@ -15513,23 +15513,15 @@ mips_reorg_process_insns (void) htab_delete (htab); } -/* If we are using a GOT, but have not decided to use a global pointer yet, - see whether we need one to implement long branches. Convert the ghost - global-pointer instructions into real ones if so. */ +/* Return true if the function has a long branch instruction. */ static bool -mips_expand_ghost_gp_insns (void) +mips_has_long_branch_p (void) { - rtx insn; + rtx insn, subinsn; int normal_length; - /* Quick exit if we already know that we will or won't need a - global pointer. */ - if (!TARGET_USE_GOT - || cfun->machine->global_pointer == INVALID_REGNUM - || mips_must_initialize_gp_p ()) - return false; - + /* We need up-to-date instruction lengths. */ shorten_branches (get_insns ()); /* Look for a branch that is longer than normal. The normal length for @@ -15538,12 +15530,32 @@ mips_expand_ghost_gp_insns (void) but they have no delay slot. */ normal_length = (TARGET_MIPS16 ? 4 : 8); for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) - if (JUMP_P (insn) - && USEFUL_INSN_P (insn) - && get_attr_length (insn) > normal_length) - break; + FOR_EACH_SUBINSN (subinsn, insn) + if (JUMP_P (subinsn) + && USEFUL_INSN_P (subinsn) + && get_attr_length (subinsn) > normal_length + && (any_condjump_p (subinsn) || any_uncondjump_p (subinsn))) + return true; + + return false; +} + +/* If we are using a GOT, but have not decided to use a global pointer yet, + see whether we need one to implement long branches. Convert the ghost + global-pointer instructions into real ones if so. */ + +static bool +mips_expand_ghost_gp_insns (void) +{ + /* Quick exit if we already know that we will or won't need a + global pointer. */ + if (!TARGET_USE_GOT + || cfun->machine->global_pointer == INVALID_REGNUM + || mips_must_initialize_gp_p ()) + return false; - if (insn == NULL_RTX) + /* Run a full check for long branches. */ + if (!mips_has_long_branch_p ()) return false; /* We've now established that we need $gp. */