From patchwork Thu Aug 19 09:33:32 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olivier Hainque X-Patchwork-Id: 62125 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 8BDB3B70D9 for ; Thu, 19 Aug 2010 19:33:44 +1000 (EST) Received: (qmail 4658 invoked by alias); 19 Aug 2010 09:33:42 -0000 Received: (qmail 4647 invoked by uid 22791); 19 Aug 2010 09:33:41 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mel.act-europe.fr (HELO mel.act-europe.fr) (212.99.106.210) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 19 Aug 2010 09:33:35 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 5DBB6CB026C; Thu, 19 Aug 2010 11:33:33 +0200 (CEST) Received: from mel.act-europe.fr ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id axc3CQxB68Gb; Thu, 19 Aug 2010 11:33:33 +0200 (CEST) Received: from cardhu.act-europe.fr (cardhu.act-europe.fr [10.10.0.168]) by mel.act-europe.fr (Postfix) with ESMTP id 4657FCB01D3; Thu, 19 Aug 2010 11:33:33 +0200 (CEST) Received: by cardhu.act-europe.fr (Postfix, from userid 546) id 1DEB31D9; Thu, 19 Aug 2010 11:33:33 +0200 (CEST) Date: Thu, 19 Aug 2010 11:33:32 +0200 From: Olivier Hainque To: gcc-patches@gcc.gnu.org Cc: hainque@adacore.com Subject: prevent extraneous nop past sibling call on sparc Message-ID: <20100819093332.GA9139@cardhu.act-europe.fr> Mime-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.4.1i X-IsSubscribed: yes 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 Hello, The sparc back-end emits an extra nop past calls at the very end of a function, to prevent the return address from falling within a different function, which causes trouble to some backtrace computation engines. Such a nop is pointless for a sibling call since the return address is setup explicitly, and this patch is a suggestion to remove it for this particular case. We found this useful in the course of the development of a machine code coverage analyzer. OK ? Thanks in advance, Olivier 2010-08-19 Olivier Hainque * config/sparc/sparc.c (sparc_asm_function_epilogue): Don't output an extra nop past a sibling call at the very end. testsuite/ * gcc.target/sparc/sibcall-dslot.c: New testcase. Index: config/sparc/sparc.c =================================================================== --- config/sparc/sparc.c (revision 163326) +++ config/sparc/sparc.c (working copy) @@ -4527,11 +4527,11 @@ static void sparc_asm_function_epilogue (FILE *file, HOST_WIDE_INT size ATTRIBUTE_UNUSED) { - /* If code does not drop into the epilogue, we have to still output - a dummy nop for the sake of sane backtraces. Otherwise, if the - last two instructions of a function were "call foo; dslot;" this - can make the return PC of foo (i.e. address of call instruction - plus 8) point to the first instruction in the next function. */ + /* If the last two instructions of a function are "call foo; dslot;" + the return address might point to the first instruction in the next + function and we have to output a dummy nop for the sake of sane + backtraces in such cases. This is pointless for sibling calls since + the return address is explicitly adjusted. */ rtx insn, last_real_insn; @@ -4543,7 +4543,8 @@ && GET_CODE (PATTERN (last_real_insn)) == SEQUENCE) last_real_insn = XVECEXP (PATTERN (last_real_insn), 0, 0); - if (last_real_insn && GET_CODE (last_real_insn) == CALL_INSN) + if (last_real_insn && GET_CODE (last_real_insn) == CALL_INSN + && !SIBLING_CALL_P (last_real_insn)) fputs("\tnop\n", file); sparc_output_deferred_case_vectors (); Index: testsuite/gcc.target/sparc/sibcall-dslot.c =================================================================== --- testsuite/gcc.target/sparc/sibcall-dslot.c (revision 0) +++ testsuite/gcc.target/sparc/sibcall-dslot.c (revision 0) @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +extern int one (); + +int some_n () +{ + return one (); +} + +/* { dg-final { scan-assembler-not "nop" } } */