From patchwork Wed Apr 2 11:04:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiong Wang X-Patchwork-Id: 336318 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 659161400F4 for ; Wed, 2 Apr 2014 22:04:30 +1100 (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=G4gbCL6XZZkwGwLqc lI2RRZgRTIlMyV0BVK4LDCU+fgGu4+QsgoSg3Fmp4mJT9kkWCIJguXTtZC7rSxeq /beWvu9nZdRkeX1dJgMETkBW1Xrp/83chaAH+SaAVGdOAdZrpUCEf9bdzhCUCLcK +gKIaQNM3ayIWR731/H77IiLR0= 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=g58Tq/Bu8+1Up2vb9c17iVf sjlQ=; b=Fm0pdckUflcjLKqHRslHcuWEwy2D21VqZdnjsBv/XLIlB2F+eCJX+kH iMAhb2+FH3MU/skhHTpKVC+6oaeYxCxM22PvcKhdfL0Rvxgb4zaKG1/TgMm+EuHj PNTWHTw57zkl4HaMU0Rzk/ewyMJQ+usIRnRzQyXB8kllsgvY+OLw= Received: (qmail 16644 invoked by alias); 2 Apr 2014 11:04:23 -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 16630 invoked by uid 89); 2 Apr 2014 11:04:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.3 required=5.0 tests=AWL, BAYES_05, KAM_STOCKGEN, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 X-HELO: service87.mimecast.com Received: from service87.mimecast.com (HELO service87.mimecast.com) (91.220.42.44) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 02 Apr 2014 11:04:20 +0000 Received: from cam-owa1.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.21]) by service87.mimecast.com; Wed, 02 Apr 2014 12:04:17 +0100 Received: from [10.1.205.52] ([10.1.255.212]) by cam-owa1.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Wed, 2 Apr 2014 12:04:29 +0100 Message-ID: <533BEEAC.7010808@arm.com> Date: Wed, 02 Apr 2014 12:04:12 +0100 From: Jiong Wang User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.1 MIME-Version: 1.0 To: Richard Earnshaw CC: GCC Patches Subject: Re: [PATCH, ARM] Enable tail call optimization for long call References: <53301680.9040602@arm.com> <5331A476.5060100@arm.com> In-Reply-To: <5331A476.5060100@arm.com> X-MC-Unique: 114040212041702201 X-IsSubscribed: yes On 25/03/14 15:44, Richard Earnshaw wrote: > On 24/03/14 11:26, Jiong Wang wrote: >> This patch enables tail call optimization for long call on arm. >> >> Previously we have too strict check on arm_function_ok_for_sibcall and >> be lack of the support on sibcall/sibcall_value expand that long call tail oppportunities are lost. >> >> OK for next next stage 1? >> > I think this is OK for EABI targets (since we can rely on the linker > generating the right form of interworking veneer), but I'm less certain > about other systems (do we still support COFF). > > I think I'd prefer the patch to factor in TARGET_AAPCS_BASED and to > assume that if that is true then arbitrary tail-calls are safe. Hi Richard, IMHO, this is actually a tail call optimization, we just need to make sure the register which hold the address be caller saved then it will be OK. Updated the change log to fix that "aarch64" typo. No modification on the patch, but enclose it in this reply to keep wholeness. So, is it ok for next stage-1? Thanks. diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c index d5f9ff3..8dcdfa8 100644 --- a/gcc/config/arm/arm.c +++ b/gcc/config/arm/arm.c @@ -6087,11 +6087,6 @@ arm_function_ok_for_sibcall (tree decl, tree exp) if (TARGET_VXWORKS_RTP && flag_pic && !targetm.binds_local_p (decl)) return false; - /* Cannot tail-call to long calls, since these are out of range of - a branch instruction. */ - if (decl && arm_is_long_call_p (decl)) - return false; - /* If we are interworking and the function is not declared static then we can't tail-call it unless we know that it exists in this compilation unit (since it might be a Thumb routine). */ diff --git a/gcc/config/arm/arm.md b/gcc/config/arm/arm.md index 2ddda02..fe285f0 100644 --- a/gcc/config/arm/arm.md +++ b/gcc/config/arm/arm.md @@ -9444,8 +9444,10 @@ "TARGET_32BIT" " { - if (!REG_P (XEXP (operands[0], 0)) - && (GET_CODE (XEXP (operands[0], 0)) != SYMBOL_REF)) + if ((!REG_P (XEXP (operands[0], 0)) + && GET_CODE (XEXP (operands[0], 0)) != SYMBOL_REF) + || (GET_CODE (XEXP (operands[0], 0)) == SYMBOL_REF + && arm_is_long_call_p (SYMBOL_REF_DECL (XEXP (operands[0], 0))))) XEXP (operands[0], 0) = force_reg (SImode, XEXP (operands[0], 0)); if (operands[2] == NULL_RTX) @@ -9462,8 +9464,10 @@ "TARGET_32BIT" " { - if (!REG_P (XEXP (operands[1], 0)) && - (GET_CODE (XEXP (operands[1],0)) != SYMBOL_REF)) + if ((!REG_P (XEXP (operands[1], 0)) + && GET_CODE (XEXP (operands[1], 0)) != SYMBOL_REF) + || (GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF + && arm_is_long_call_p (SYMBOL_REF_DECL (XEXP (operands[1], 0))))) XEXP (operands[1], 0) = force_reg (SImode, XEXP (operands[1], 0)); if (operands[3] == NULL_RTX) diff --git a/gcc/config/arm/predicates.md b/gcc/config/arm/predicates.md index ce5c9a8..3673343 100644 --- a/gcc/config/arm/predicates.md +++ b/gcc/config/arm/predicates.md @@ -673,5 +673,6 @@ (match_code "reg" "0"))) (define_predicate "call_insn_operand" - (ior (match_code "symbol_ref") + (ior (and (match_code "symbol_ref") + (match_test "!arm_is_long_call_p (SYMBOL_REF_DECL (op))")) (match_operand 0 "s_register_operand"))) diff --git a/gcc/testsuite/gcc.target/arm/tail-long-call.c b/gcc/testsuite/gcc.target/arm/tail-long-call.c new file mode 100644 index 0000000..9b27468 --- /dev/null +++ b/gcc/testsuite/gcc.target/arm/tail-long-call.c @@ -0,0 +1,12 @@ +/* { dg-skip-if "need at least armv5te" { *-*-* } { "-march=armv[234]*" "-mthumb" } { "" } } */ +/* { dg-options "-O2 -march=armv5te -marm" } */ +/* { dg-final { scan-assembler "bx" } } */ +/* { dg-final { scan-assembler-not "blx" } } */ + +int lcal (int) __attribute__ ((long_call)); + +int +dec (int a) +{ + return lcal (a); +}