From patchwork Thu Jun 26 10:56:03 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 364480 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 14C3414009B for ; Thu, 26 Jun 2014 20:56:23 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; q=dns; s=default; b=WPj6efs9SZzOsK2t0 id0WI3UsIHvBb2ZEVDgX3GQkqkGcQIlUn4F5VwTD22oqzzvPt5sOKbHcq5GFYd4r obp6ElPgxog+Cg8cC/MB3ozF41DTSXJFTJ9IcNk+cVkmIxkwQxS/DgJHuKPuG+19 JRCbjv57iikcMES4R1VBIG3AjQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; s=default; bh=TkoDlM25xE6jZHCmiKBSLsD Xfxs=; b=Y2hh9MxWgtz91Ml0XOfv5qr0A0WbcBYJr53o9DRvIa/pnkXMbtbg5tu G0SXe7p28/Tx+6uB6t2zV+eOEnE5KQUJEs6zxeorhI86sabm6qHfrXHiYMiNh7+K avXiHwvw73lUEYr1nUKvD8ZK+Ifwyf9qHcD62+t7UE4Eq2qC4vHg= Received: (qmail 12807 invoked by alias); 26 Jun 2014 10:56:16 -0000 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 Received: (qmail 12794 invoked by uid 89); 26 Jun 2014 10:56:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00 autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 26 Jun 2014 10:56:14 +0000 Received: from svr-orw-fem-01.mgc.mentorg.com ([147.34.98.93]) by relay1.mentorg.com with esmtp id 1X07Lc-00007e-OV from Tom_deVries@mentor.com ; Thu, 26 Jun 2014 03:56:08 -0700 Received: from SVR-IES-FEM-03.mgc.mentorg.com ([137.202.0.108]) by svr-orw-fem-01.mgc.mentorg.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Thu, 26 Jun 2014 03:56:08 -0700 Received: from [127.0.0.1] (137.202.0.76) by SVR-IES-FEM-03.mgc.mentorg.com (137.202.0.108) with Microsoft SMTP Server id 14.2.247.3; Thu, 26 Jun 2014 11:56:06 +0100 Message-ID: <53ABFC43.6050002@mentor.com> Date: Thu, 26 Jun 2014 12:56:03 +0200 From: Tom de Vries User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: Richard Henderson CC: GCC Patches Subject: Re: Fix finding reg-sets of call insn in collect_fn_hard_reg_usage References: <53A30AB7.1060800@mentor.com> <53A3127E.1060409@redhat.com> <53A31429.9000708@redhat.com> In-Reply-To: <53A31429.9000708@redhat.com> On 19-06-14 18:47, Richard Henderson wrote: > And I forgot to mention it might be worth while to notice simple recursion. > Avoid the early exit path if caller == callee, despite the caller-save info not > being valid. > > Richard, attached patch enables handling of self-recursive functions in the fuse-caller-save optimization, and adds a test-case. I've done an x86_64 build and ran the i386.exp testsuite. OK for trunk if full bootstrap and reg-test succeeds? Thanks, - Tom 2014-06-26 Tom de Vries * final.c (get_call_fndecl): Declare. (self_recursive_call_p): New function. (collect_fn_hard_reg_usage): Handle self-recursive function calls. * gcc.target/i386/fuse-caller-save-rec.c: New test. diff --git a/gcc/final.c b/gcc/final.c index 9525efc..ed0ba0b 100644 --- a/gcc/final.c +++ b/gcc/final.c @@ -225,6 +225,7 @@ static int final_addr_vec_align (rtx); #endif static int align_fuzz (rtx, rtx, int, unsigned); static void collect_fn_hard_reg_usage (void); +static tree get_call_fndecl (rtx); /* Initialize data in final at the beginning of a compilation. */ @@ -4750,6 +4751,16 @@ make_pass_clean_state (gcc::context *ctxt) return new pass_clean_state (ctxt); } +/* Return true if INSN is a call to the the current function. */ + +static bool +self_recursive_call_p (rtx insn) +{ + tree fndecl = get_call_fndecl (insn); + return (fndecl == current_function_decl + && decl_binds_to_current_def_p (fndecl)); +} + /* Collect hard register usage for the current function. */ static void @@ -4775,7 +4786,8 @@ collect_fn_hard_reg_usage (void) if (!NONDEBUG_INSN_P (insn)) continue; - if (CALL_P (insn)) + if (CALL_P (insn) + && !self_recursive_call_p (insn)) { if (!get_call_reg_set_usage (insn, &insn_used_regs, call_used_reg_set)) diff --git a/gcc/testsuite/gcc.target/i386/fuse-caller-save-rec.c b/gcc/testsuite/gcc.target/i386/fuse-caller-save-rec.c new file mode 100644 index 0000000..b30a0b4 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/fuse-caller-save-rec.c @@ -0,0 +1,32 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fuse-caller-save -fomit-frame-pointer -fno-optimize-sibling-calls" } */ +/* { dg-additional-options "-mregparm=1" { target ia32 } } */ + +/* Test -fuse-caller-save optimization on self-recursive function. */ + +static int __attribute__((noinline)) +bar (int x) +{ + if (x > 4) + return bar (x - 3); + return 0; +} + +int __attribute__((noinline)) +foo (int y) +{ + return y + bar (y); +} + +int +main (void) +{ + return !(foo (5) == 13); +} + +/* Verify that no registers where saved on stack. */ +/* { dg-final { scan-assembler-not "\.cfi_offset" } } */ + +/* Verify that bar is self-recursive. */ +/* { dg-final { scan-assembler-times "call\tbar" 2 } } */ + -- 1.9.1