From patchwork Wed Nov 15 17:14:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Preudhomme X-Patchwork-Id: 838262 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-466896-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="DKYoCKgN"; dkim-atps=neutral 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 3ycWFT3m30z9s71 for ; Thu, 16 Nov 2017 04:14:21 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=OZbTWbP6GfoL85d8e+GbmoEwuaEavMgAICKkaacjV//wRuQxux w1Zlgz/Xq/Y5vRPvb6j7GGLtWNKzO10fFERSvvOgIORiuQcAiI2dvScbBk7m5qOs rHkT7BPdtP0PirKyWXH9X/+EcygbwCvVHSUf1niIXvATO1OwCFgH5Uuiw= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=gkP6OyDdSvzGQrUJ00TEgVhub3A=; b=DKYoCKgNtzPPjwSaOlEC 1qBF52DltovftJwyRp8gRr94Z0BY2jKzBbKU3CPUlQQtrs8KV4hdsnTIO2Rh31GV 2Tz2FbuQ0EaHXRW/mVwQvtYOLmmAEXewwtpYjdCLXHyL0lH5kO16gPUR5FRJdt81 U278brkrQ5H8K+SX9LJY/DI= Received: (qmail 10470 invoked by alias); 15 Nov 2017 17:14:12 -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 10203 invoked by uid 89); 15 Nov 2017 17:14:12 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, KAM_LOTSOFHASH, KB_WAM_FROM_NAME_SINGLEWORD, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=sk:UNSPEC_, sk:unspec_, H*M:af15, H*MI:af15 X-HELO: foss.arm.com Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 15 Nov 2017 17:14:03 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 39E8C80D; Wed, 15 Nov 2017 09:14:02 -0800 (PST) Received: from [10.2.206.52] (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 705EB3F246; Wed, 15 Nov 2017 09:14:01 -0800 (PST) To: Kyrill Tkachov , Ramana Radhakrishnan , Richard Earnshaw , "gcc-patches@gcc.gnu.org" From: Thomas Preudhomme Subject: [PATCH, GCC/ARM] Do no clobber r4 in Armv8-M nonsecure call Message-ID: Date: Wed, 15 Nov 2017 17:14:00 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 X-IsSubscribed: yes Hi, Expanders for Armv8-M nonsecure call unnecessarily clobber r4 despite the libcall they perform not writing to r4. Furthermore, the requirement for the branch target address to be in r4 as expected by the libcall is modeled in a convoluted way in the define_insn patterns: the address is a register match_operand constrained by the match_dup for the clobber which is guaranteed to be r4 due to the expander. This patch simplifies all this by simply requiring the address to be in r4 and removing the clobbers. Expanders are left alone because cmse_nonsecure_call_clear_caller_saved relies on branch target memory attributes which would be lost if expanding to reg:SI R4_REGNUM. ChangeLog entry is as follows: *** gcc/ChangeLog *** 2017-10-24 Thomas Preud'homme * config/arm/arm.md (R4_REGNUM): Define constant. (nonsecure_call_internal): Remove r4 clobber. (nonsecure_call_value_internal): Likewise. * config/arm/thumb1.md (nonsecure_call_reg_thumb1_v5): Remove second clobber and resequence match_operands. (nonsecure_call_value_reg_thumb1_v5): Likewise. * config/arm/thumb2.md (nonsecure_call_reg_thumb2): Likewise. (nonsecure_call_value_reg_thumb2): Likewise. Testing: Bootstrapped on arm-linux-gnueabihf and testsuite shows no regression. Is this ok for trunk? Best regards, Thomas diff --git a/gcc/config/arm/arm.md b/gcc/config/arm/arm.md index ddb9d8f359007c1d86d497aef0ff5fc0e4061813..6b0794ede9fbc5a4f41e1f4a92acb9b649a277bc 100644 --- a/gcc/config/arm/arm.md +++ b/gcc/config/arm/arm.md @@ -30,6 +30,7 @@ (define_constants [(R0_REGNUM 0) ; First CORE register (R1_REGNUM 1) ; Second CORE register + (R4_REGNUM 4) ; Fifth CORE register (IP_REGNUM 12) ; Scratch register (SP_REGNUM 13) ; Stack pointer (LR_REGNUM 14) ; Return address register @@ -8118,14 +8119,13 @@ UNSPEC_NONSECURE_MEM) (match_operand 1 "general_operand" "")) (use (match_operand 2 "" "")) - (clobber (reg:SI LR_REGNUM)) - (clobber (reg:SI 4))])] + (clobber (reg:SI LR_REGNUM))])] "use_cmse" " { rtx tmp; tmp = copy_to_suggested_reg (XEXP (operands[0], 0), - gen_rtx_REG (SImode, 4), + gen_rtx_REG (SImode, R4_REGNUM), SImode); operands[0] = replace_equiv_address (operands[0], tmp); @@ -8210,14 +8210,13 @@ UNSPEC_NONSECURE_MEM) (match_operand 2 "general_operand" ""))) (use (match_operand 3 "" "")) - (clobber (reg:SI LR_REGNUM)) - (clobber (reg:SI 4))])] + (clobber (reg:SI LR_REGNUM))])] "use_cmse" " { rtx tmp; tmp = copy_to_suggested_reg (XEXP (operands[1], 0), - gen_rtx_REG (SImode, 4), + gen_rtx_REG (SImode, R4_REGNUM), SImode); operands[1] = replace_equiv_address (operands[1], tmp); diff --git a/gcc/config/arm/thumb1.md b/gcc/config/arm/thumb1.md index 5d196a673355a7acf7d0ed30f21b997b815913f5..f91659386bf240172bd9a3076722683c8a50dff4 100644 --- a/gcc/config/arm/thumb1.md +++ b/gcc/config/arm/thumb1.md @@ -1732,12 +1732,11 @@ ) (define_insn "*nonsecure_call_reg_thumb1_v5" - [(call (unspec:SI [(mem:SI (match_operand:SI 0 "register_operand" "l*r"))] + [(call (unspec:SI [(mem:SI (reg:SI R4_REGNUM))] UNSPEC_NONSECURE_MEM) - (match_operand 1 "" "")) - (use (match_operand 2 "" "")) - (clobber (reg:SI LR_REGNUM)) - (clobber (match_dup 0))] + (match_operand 0 "" "")) + (use (match_operand 1 "" "")) + (clobber (reg:SI LR_REGNUM))] "TARGET_THUMB1 && use_cmse && !SIBLING_CALL_P (insn)" "bl\\t__gnu_cmse_nonsecure_call" [(set_attr "length" "4") @@ -1779,12 +1778,11 @@ (define_insn "*nonsecure_call_value_reg_thumb1_v5" [(set (match_operand 0 "" "") (call (unspec:SI - [(mem:SI (match_operand:SI 1 "register_operand" "l*r"))] + [(mem:SI (reg:SI R4_REGNUM))] UNSPEC_NONSECURE_MEM) - (match_operand 2 "" ""))) - (use (match_operand 3 "" "")) - (clobber (reg:SI LR_REGNUM)) - (clobber (match_dup 1))] + (match_operand 1 "" ""))) + (use (match_operand 2 "" "")) + (clobber (reg:SI LR_REGNUM))] "TARGET_THUMB1 && use_cmse" "bl\\t__gnu_cmse_nonsecure_call" [(set_attr "length" "4") diff --git a/gcc/config/arm/thumb2.md b/gcc/config/arm/thumb2.md index 776d611d2538e790a5f504995050ffdfc51d7193..d56a8bd167575263edc2a4b3f66bda34a4a7a72a 100644 --- a/gcc/config/arm/thumb2.md +++ b/gcc/config/arm/thumb2.md @@ -555,12 +555,11 @@ ) (define_insn "*nonsecure_call_reg_thumb2" - [(call (unspec:SI [(mem:SI (match_operand:SI 0 "s_register_operand" "r"))] + [(call (unspec:SI [(mem:SI (reg:SI R4_REGNUM))] UNSPEC_NONSECURE_MEM) - (match_operand 1 "" "")) - (use (match_operand 2 "" "")) - (clobber (reg:SI LR_REGNUM)) - (clobber (match_dup 0))] + (match_operand 0 "" "")) + (use (match_operand 1 "" "")) + (clobber (reg:SI LR_REGNUM))] "TARGET_THUMB2 && use_cmse" "bl\\t__gnu_cmse_nonsecure_call" [(set_attr "length" "4") @@ -581,12 +580,11 @@ (define_insn "*nonsecure_call_value_reg_thumb2" [(set (match_operand 0 "" "") (call - (unspec:SI [(mem:SI (match_operand:SI 1 "register_operand" "l*r"))] + (unspec:SI [(mem:SI (reg:SI R4_REGNUM))] UNSPEC_NONSECURE_MEM) - (match_operand 2 "" ""))) - (use (match_operand 3 "" "")) - (clobber (reg:SI LR_REGNUM)) - (clobber (match_dup 1))] + (match_operand 1 "" ""))) + (use (match_operand 2 "" "")) + (clobber (reg:SI LR_REGNUM))] "TARGET_THUMB2 && use_cmse" "bl\t__gnu_cmse_nonsecure_call" [(set_attr "length" "4")