From patchwork Tue Jun 14 03:34:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takayuki 'January June' Suwa X-Patchwork-Id: 1643086 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=gMsCx6/C; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LMZMX3Zpcz9sG2 for ; Tue, 14 Jun 2022 13:55:03 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DD62B3841477 for ; Tue, 14 Jun 2022 03:54:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DD62B3841477 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1655178899; bh=LkDx8EhPjXzPbn349DAIqVl06CIKtVuxBcdFR4d6G1E=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=gMsCx6/COmYXHly3GRIay5ZeGpP5tnTrb9sTeLF59CGPco3AkyX3NrBztuCfRr8mB 8iSe6jUphOdPYRUkZWwbmlaEKu8HQpdBYN8S4zWwVhXo7ao3asyxB9yOqpbsr7HkX3 PxMBfQa+8fyZOgnZ5+/zzjTxIdEx4nhbMR7ZMar4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from nh501-vm14.bullet.mail.kks.yahoo.co.jp (nh501-vm14.bullet.mail.kks.yahoo.co.jp [183.79.56.144]) by sourceware.org (Postfix) with SMTP id A30223857363 for ; Tue, 14 Jun 2022 03:54:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A30223857363 Received: from [183.79.100.140] by nh501.bullet.mail.kks.yahoo.co.jp with NNFMP; 14 Jun 2022 03:54:35 -0000 Received: from [183.79.101.121] by t503.bullet.mail.kks.yahoo.co.jp with NNFMP; 14 Jun 2022 03:54:35 -0000 Received: from [127.0.0.1] by omp508.mail.kks.yahoo.co.jp with NNFMP; 14 Jun 2022 03:54:35 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 910455.98315.bm@omp508.mail.kks.yahoo.co.jp Received: (qmail 77911 invoked by alias); 14 Jun 2022 03:54:35 -0000 Received: from unknown (HELO ?192.168.2.3?) (175.177.45.163 with ) by smtp6008.mail.ssk.ynwp.yahoo.co.jp with SMTP; 14 Jun 2022 03:54:35 -0000 X-YMail-JAS: 3kGdhD0VM1nQxgJWJittf.0nSSsE1AoaazbzOleworMPE6JpmlF1ILJP.eigAgIfGbyOlj428zMIAFVV7R20c5KZ3I7vLbiHxNZ2XrcfhG31havwEtUVaVLLx9l3_q2UBH2ZCFmtFQ-- X-Apparently-From: X-YMail-OSG: yN4W6WQVM1lYoRRmAWmhUFY9eeXx5pVYAb5MrG3veqq9DWD wQvlcaTcBlMgIUowImfez1xyzZ.1Kf8O4TNB59yZIeQuDcQ6KJLycRaYhAEw vTjnE5_Uq8DoB1Cw6rDZ5QaL_s.URoCnGnkBDSGFPJx_BIrspbWkfn2LSvFw fahR9P.gg6Z_ryhDyyOKTe53yoTRqUEbZhTDyz.jLwQ8F5f5wLM_ReV0dx4U 7KBpqQzUleK890KR5IacSBxSAYHgJOUGSRRPSZT3ilWl0BWbprbBJfUy0fnj aVkQCYl_HWSYhQBZmzIm7Th7dRDVNqnwGc0tRKz5SHlFFdjaUGwQGbMVCdHw ceC5xw2loath7gxdZBD2lBG1nOa5LPvlcQdvZnMuqJ.p0fRBGGwaIMTN9fju 305OTnxZ2natmYyN8ac7aHjqj541OPw5QXn2wG3DItPuXpyGJc7nyMWLAuxr VBLHAIZiN776Na4QFCA.Aua9xKhvx1PA98M0dYIMdzVaGHOiE.KsgJSIBQf0 J1xJLoH86.qwbx3Vr2pP5jpBpVOaz3SaD1ntNfVCI4gcBpyIP02sSZ5r2vAm eDCMTHvnwyL_scN9.NrQiSfoDbQ5OUD6UsXRUA72p5oOGhf9UYQLQsNBBhwl 7vHcIgXOdIOJPp.gP7YGma61w9KZPcu3bOHiCQvWg2zSkhfik6s.yDT59khp SjFivqDJGZz0pSlLL9d1ES0XKRJXEJ90QKpFGyQK8Mnv05q85FrzIBBa6c8d pdrJmFMxiqHKbkvVUajf92075ZU1x9t.HOS40h222mvJFSmOyNZf9U6Y5IyA lOKZ7.E_2DjyWFF1jqL9YBCzMdZqluKfAjtQgksuCj842WNo7b4XrxJRkfUE QBqUUaKNmQbJW4u6qGAN8doIuDwBgn7Fma6vDKZ_q.GjjpAHjTnIoD.Zff2X sOmh5Ei_x.KbIX9L7yg-- Message-ID: <09db7f8f-5619-ee00-d1f5-1806d01fa068@yahoo.co.jp> Date: Tue, 14 Jun 2022 12:34:48 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Content-Language: en-US To: GCC Patches Subject: [PATCH 1/5] xtensa: Document new -mextra-l32r-costs= Xtensa-specific option X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Takayuki 'January June' Suwa via Gcc-patches From: Takayuki 'January June' Suwa Reply-To: Takayuki 'January June' Suwa Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" gcc/ChangeLog: * doc/invoke.texi: Document -mextra-l32r-costs= option. --- gcc/doc/invoke.texi | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index b6c0305f198..2a3c638de40 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -1473,7 +1473,8 @@ See RS/6000 and PowerPC Options. -mauto-litpools -mno-auto-litpools @gol -mtarget-align -mno-target-align @gol -mlongcalls -mno-longcalls @gol --mabi=@var{abi-type}} +-mabi=@var{abi-type} @gol +-mextra-l32r-costs=@var{cycles}} @emph{zSeries Options} See S/390 and zSeries Options. @@ -33526,6 +33527,14 @@ by 8 registers on entry so that its arguments are found in registers pointer. Register window is rotated 8 registers back upon return. When this version of the ABI is enabled the C preprocessor symbol @code{__XTENSA_WINDOWED_ABI__} is defined. + +@item -mextra-l32r-costs=@var{n} +@opindex mextra-l32r-costs +Specify an extra cost of instruction RAM/ROM access for @code{L32R} +instructions, in clock cycles. This affects, when optimizing for speed, +whether loading a constant from literal pool using @code{L32R} or +synthesizing the constant from a small one with a couple of arithmetic +instructions. The default value is 0. @end table @node zSeries Options From patchwork Tue Jun 14 03:36:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takayuki 'January June' Suwa X-Patchwork-Id: 1643088 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=vJcbFc06; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LMZPj4TzBz9sG2 for ; Tue, 14 Jun 2022 13:56:57 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 840DF3841447 for ; Tue, 14 Jun 2022 03:56:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 840DF3841447 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1655179013; bh=oGSvvVDhAuHJH10pXVTJwrsKLXweACNXE4YvmiM4c1o=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=vJcbFc067qi20Vz+FrHuIh+lbqVPluMMIKNwuIzIVpxj/1L0DT49nr7pDzZR4DXQ1 Uv+02kflyxzQpd4UlMZVsATaZv9yWMTzorB3CBmtd/XnbdQmCtzIS/fkdgQXyC3Y8X 1EqwASXOuE8/a79IE6hcm/kzbVX7pbpo4ZZJYdz8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from nh605-vm7.bullet.mail.ssk.yahoo.co.jp (nh605-vm7.bullet.mail.ssk.yahoo.co.jp [182.22.90.80]) by sourceware.org (Postfix) with SMTP id 2392F384F010 for ; Tue, 14 Jun 2022 03:54:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2392F384F010 Received: from [182.22.66.103] by nh605.bullet.mail.ssk.yahoo.co.jp with NNFMP; 14 Jun 2022 03:54:37 -0000 Received: from [182.22.91.204] by t601.bullet.mail.ssk.yahoo.co.jp with NNFMP; 14 Jun 2022 03:54:37 -0000 Received: from [127.0.0.1] by omp607.mail.ssk.yahoo.co.jp with NNFMP; 14 Jun 2022 03:54:37 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 420111.59718.bm@omp607.mail.ssk.yahoo.co.jp Received: (qmail 32940 invoked by alias); 14 Jun 2022 03:54:37 -0000 Received: from unknown (HELO ?192.168.2.3?) (175.177.45.163 with ) by smtp6003.mail.ssk.ynwp.yahoo.co.jp with SMTP; 14 Jun 2022 03:54:37 -0000 X-YMail-JAS: Lr4cGw4VM1lFnZdESlk6rnjZmZv1KzWpGGJzz.yGwcB0IPpT.mv6ktiXELE62EZPGNzb04.Qm9m8gvADBKRuhDK1EEKW38WUgFtAx7uAtmIftodonJ4yosoMmRDWgFOD._gY2TpInQ-- X-Apparently-From: X-YMail-OSG: HwnILiIVM1my3RpjVmzNYZVYAktiV_O7qXcup.7p2NGxxAW ghoiV9_XVoMFnBUhBq2OX0n9hl4Vs2Fn2QPqrMzteuctTOsMaqby4ObwpkI4 42XgLspGPj6rKFNcUW4RCfwMHD5oGJ8jH6XOtwJcKGfDh7GlFWc.dLK2zPVT F3OFhAbwpyC1U9QT6vzLX2cQOczvLexWFk3RGEcskE3m1onRJg_FYSwJFf.n DBHsTM52K2cQfzKuHCg5r7ZehHktXTQHXna5CCiUue7ACXb35E5WLo3GMvMQ 4HhkOTyv6_xo.wVgJzmwiK5U5T6ud0KQa2bcunpETvKl88uP3jrulpHH3Qsg d5_FS9xnZhgYjjK1Q_TVNXRQCCqDkAUi_dbVhSun.XElIuh0LrxOrDCB3dhx e6fEB.esyAh9pPKVH.iNtGjuT7_OC4bTQnfXi7GZxX.ko3KlEqoakkLDFKdg r4BvCYRuQbgzQUVJDUpk9jTN_Ibw8mbmgb5MsN7x9vaRUZ4McJvPW22daH3y lA2PuFr09C9Wz9qOwTxcUg9TwWN25TkoSXeurJUzSZI8vOVn1dY1UMAdHXMw _E19CLIbCBUYg69UTSoIIERWbwTCRuDieoQlkdlqQsE_KSc9pN6vUHXKGABG vcQursJUnY6g_IfYw3RYUiKg5d_7FT4n64V67WLGb_vhBjLHled9ZLiw_Xog Z01lHrpeS4Y6gr3TuiNS9kaXmOqWHFCGyWFHC6pMEpn2PRV__WlVzRf3cvo4 Zpcigm6fV8eCTeUrNJmk2oQpKsRiL6jlPabKBR39Xn._5j.CjQyxLh8Fmugh jQqn80jKWeaqwbiFLLjPFvkLJRtn9sRZszfi_jiPO5SDioIKQXZ65B5g4aIS 7418IwcGDoO9XjSP_wJSTGRInPBKWzfuAZ1rjXmf.RJyb6HyIwLPrPq4SLZv _uAn4gBabFB3qzt753w-- Message-ID: Date: Tue, 14 Jun 2022 12:36:10 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Content-Language: en-US To: GCC Patches Subject: [PATCH 2/5] xtensa: Add support for sibling call optimization X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, KAM_STOCKGEN, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Takayuki 'January June' Suwa via Gcc-patches From: Takayuki 'January June' Suwa Reply-To: Takayuki 'January June' Suwa Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This patch introduces support for sibling call optimization, when call0 ABI is in effect. gcc/ChangeLog: * config/xtensa/xtensa-protos.h (xtensa_prepare_expand_call, xtensa_emit_sibcall): New prototypes. (xtensa_expand_epilogue): Add new argument that specifies whether or not sibling call. * config/xtensa/xtensa.cc (TARGET_FUNCTION_OK_FOR_SIBCALL): New macro definition. (xtensa_prepare_expand_call): New function in order to share the common code. (xtensa_emit_sibcall, xtensa_function_ok_for_sibcall): New functions. (xtensa_expand_epilogue): Add new argument sibcall_p and use it for sibling call handling. * config/xtensa/xtensa.md (call, call_value): Use xtensa_prepare_expand_call. (call_internal, call_value_internal): Add the condition in order to be disabled if sibling call. (sibcall, sibcall_value, sibcall_epilogue): New expansions. (sibcall_internal, sibcall_value_internal): New insn patterns. gcc/testsuite/ChangeLog: * gcc.target/xtensa/sibcalls.c: New. --- gcc/config/xtensa/xtensa-protos.h | 4 +- gcc/config/xtensa/xtensa.cc | 63 ++++++++++++++++++-- gcc/config/xtensa/xtensa.md | 68 +++++++++++++++++----- gcc/testsuite/gcc.target/xtensa/sibcalls.c | 15 +++++ 4 files changed, 130 insertions(+), 20 deletions(-) create mode 100644 gcc/testsuite/gcc.target/xtensa/sibcalls.c diff --git a/gcc/config/xtensa/xtensa-protos.h b/gcc/config/xtensa/xtensa-protos.h index 168ad70710b..e020a332b03 100644 --- a/gcc/config/xtensa/xtensa-protos.h +++ b/gcc/config/xtensa/xtensa-protos.h @@ -53,7 +53,9 @@ extern void xtensa_expand_atomic (enum rtx_code, rtx, rtx, rtx, bool); extern void xtensa_emit_loop_end (rtx_insn *, rtx *); extern char *xtensa_emit_branch (bool, rtx *); extern char *xtensa_emit_movcc (bool, bool, bool, rtx *); +extern void xtensa_prepare_expand_call (int, rtx *); extern char *xtensa_emit_call (int, rtx *); +extern char *xtensa_emit_sibcall (int, rtx *); extern bool xtensa_tls_referenced_p (rtx); extern enum rtx_code xtensa_shlrd_which_direction (rtx, rtx); @@ -73,7 +75,7 @@ extern int xtensa_dbx_register_number (int); extern long compute_frame_size (poly_int64); extern bool xtensa_use_return_instruction_p (void); extern void xtensa_expand_prologue (void); -extern void xtensa_expand_epilogue (void); +extern void xtensa_expand_epilogue (bool); extern void order_regs_for_local_alloc (void); extern enum reg_class xtensa_regno_to_class (int regno); extern HOST_WIDE_INT xtensa_initial_elimination_offset (int from, int to); diff --git a/gcc/config/xtensa/xtensa.cc b/gcc/config/xtensa/xtensa.cc index 58b6eb0b711..b97f37ac956 100644 --- a/gcc/config/xtensa/xtensa.cc +++ b/gcc/config/xtensa/xtensa.cc @@ -189,7 +189,7 @@ static bool xtensa_can_eliminate (const int from ATTRIBUTE_UNUSED, const int to); static HOST_WIDE_INT xtensa_starting_frame_offset (void); static unsigned HOST_WIDE_INT xtensa_asan_shadow_offset (void); - +static bool xtensa_function_ok_for_sibcall (tree, tree); static rtx xtensa_delegitimize_address (rtx); @@ -347,6 +347,9 @@ static rtx xtensa_delegitimize_address (rtx); #undef TARGET_DELEGITIMIZE_ADDRESS #define TARGET_DELEGITIMIZE_ADDRESS xtensa_delegitimize_address +#undef TARGET_FUNCTION_OK_FOR_SIBCALL +#define TARGET_FUNCTION_OK_FOR_SIBCALL xtensa_function_ok_for_sibcall + struct gcc_target targetm = TARGET_INITIALIZER; @@ -2127,6 +2130,20 @@ xtensa_emit_movcc (bool inverted, bool isfp, bool isbool, rtx *operands) } +void +xtensa_prepare_expand_call (int callop, rtx *operands) +{ + rtx addr = XEXP (operands[callop], 0); + + if (flag_pic && SYMBOL_REF_P (addr) + && (!SYMBOL_REF_LOCAL_P (addr) || SYMBOL_REF_EXTERNAL_P (addr))) + addr = gen_sym_PLT (addr); + + if (!call_insn_operand (addr, VOIDmode)) + XEXP (operands[callop], 0) = copy_to_mode_reg (Pmode, addr); +} + + char * xtensa_emit_call (int callop, rtx *operands) { @@ -2145,6 +2162,24 @@ xtensa_emit_call (int callop, rtx *operands) } +char * +xtensa_emit_sibcall (int callop, rtx *operands) +{ + static char result[64]; + rtx tgt = operands[callop]; + + if (GET_CODE (tgt) == CONST_INT) + sprintf (result, "j.l\t" HOST_WIDE_INT_PRINT_HEX ", a9", + INTVAL (tgt)); + else if (register_operand (tgt, VOIDmode)) + sprintf (result, "jx\t%%%d", callop); + else + sprintf (result, "j.l\t%%%d, a9", callop); + + return result; +} + + bool xtensa_legitimate_address_p (machine_mode mode, rtx addr, bool strict) { @@ -3270,7 +3305,7 @@ xtensa_expand_prologue (void) } void -xtensa_expand_epilogue (void) +xtensa_expand_epilogue (bool sibcall_p) { if (!TARGET_WINDOWED_ABI) { @@ -3304,10 +3339,13 @@ xtensa_expand_epilogue (void) if (xtensa_call_save_reg(regno)) { rtx x = gen_rtx_PLUS (Pmode, stack_pointer_rtx, GEN_INT (offset)); + rtx reg; offset -= UNITS_PER_WORD; - emit_move_insn (gen_rtx_REG (SImode, regno), + emit_move_insn (reg = gen_rtx_REG (SImode, regno), gen_frame_mem (SImode, x)); + if (regno == A0_REG && sibcall_p) + emit_use (reg); } } @@ -3342,7 +3380,8 @@ xtensa_expand_epilogue (void) EH_RETURN_STACKADJ_RTX)); } cfun->machine->epilogue_done = true; - emit_jump_insn (gen_return ()); + if (!sibcall_p) + emit_jump_insn (gen_return ()); } bool @@ -4869,6 +4908,22 @@ xtensa_asan_shadow_offset (void) return HOST_WIDE_INT_UC (0x10000000); } +/* Implement TARGET_FUNCTION_OK_FOR_SIBCALL. */ +static bool +xtensa_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED) +{ + /* Do not allow tailcalls if the Windowed Register Option is + configured. */ + if (TARGET_WINDOWED_ABI) + return false; + + /* Do not allow indirect tailcalls. */ + if (decl == NULL) + return false; + + return true; +} + static rtx xtensa_delegitimize_address (rtx op) { diff --git a/gcc/config/xtensa/xtensa.md b/gcc/config/xtensa/xtensa.md index 5d0f346b01a..181f935e3c3 100644 --- a/gcc/config/xtensa/xtensa.md +++ b/gcc/config/xtensa/xtensa.md @@ -2148,18 +2148,13 @@ (match_operand 1 "" ""))] "" { - rtx addr = XEXP (operands[0], 0); - if (flag_pic && GET_CODE (addr) == SYMBOL_REF - && (!SYMBOL_REF_LOCAL_P (addr) || SYMBOL_REF_EXTERNAL_P (addr))) - addr = gen_sym_PLT (addr); - if (!call_insn_operand (addr, VOIDmode)) - XEXP (operands[0], 0) = copy_to_mode_reg (Pmode, addr); + xtensa_prepare_expand_call (0, operands); }) (define_insn "call_internal" [(call (mem (match_operand:SI 0 "call_insn_operand" "nir")) (match_operand 1 "" "i"))] - "" + "!SIBLING_CALL_P (insn)" { return xtensa_emit_call (0, operands); } @@ -2173,19 +2168,14 @@ (match_operand 2 "" "")))] "" { - rtx addr = XEXP (operands[1], 0); - if (flag_pic && GET_CODE (addr) == SYMBOL_REF - && (!SYMBOL_REF_LOCAL_P (addr) || SYMBOL_REF_EXTERNAL_P (addr))) - addr = gen_sym_PLT (addr); - if (!call_insn_operand (addr, VOIDmode)) - XEXP (operands[1], 0) = copy_to_mode_reg (Pmode, addr); + xtensa_prepare_expand_call (1, operands); }) (define_insn "call_value_internal" [(set (match_operand 0 "register_operand" "=a") (call (mem (match_operand:SI 1 "call_insn_operand" "nir")) (match_operand 2 "" "i")))] - "" + "!SIBLING_CALL_P (insn)" { return xtensa_emit_call (1, operands); } @@ -2193,6 +2183,46 @@ (set_attr "mode" "none") (set_attr "length" "3")]) +(define_expand "sibcall" + [(call (match_operand 0 "memory_operand" "") + (match_operand 1 "" ""))] + "!TARGET_WINDOWED_ABI" +{ + xtensa_prepare_expand_call (0, operands); +}) + +(define_insn "sibcall_internal" + [(call (mem:SI (match_operand:SI 0 "call_insn_operand" "nir")) + (match_operand 1 "" "i"))] + "!TARGET_WINDOWED_ABI && SIBLING_CALL_P (insn)" +{ + return xtensa_emit_sibcall (0, operands); +} + [(set_attr "type" "call") + (set_attr "mode" "none") + (set_attr "length" "3")]) + +(define_expand "sibcall_value" + [(set (match_operand 0 "register_operand" "") + (call (match_operand 1 "memory_operand" "") + (match_operand 2 "" "")))] + "!TARGET_WINDOWED_ABI" +{ + xtensa_prepare_expand_call (1, operands); +}) + +(define_insn "sibcall_value_internal" + [(set (match_operand 0 "register_operand" "=a") + (call (mem:SI (match_operand:SI 1 "call_insn_operand" "nir")) + (match_operand 2 "" "i")))] + "!TARGET_WINDOWED_ABI && SIBLING_CALL_P (insn)" +{ + return xtensa_emit_sibcall (1, operands); +} + [(set_attr "type" "call") + (set_attr "mode" "none") + (set_attr "length" "3")]) + (define_insn "entry" [(set (reg:SI A1_REG) (unspec_volatile:SI [(match_operand:SI 0 "const_int_operand" "i")] @@ -2260,7 +2290,15 @@ [(return)] "" { - xtensa_expand_epilogue (); + xtensa_expand_epilogue (false); + DONE; +}) + +(define_expand "sibcall_epilogue" + [(return)] + "!TARGET_WINDOWED_ABI" +{ + xtensa_expand_epilogue (true); DONE; }) diff --git a/gcc/testsuite/gcc.target/xtensa/sibcalls.c b/gcc/testsuite/gcc.target/xtensa/sibcalls.c new file mode 100644 index 00000000000..50a7b1aa431 --- /dev/null +++ b/gcc/testsuite/gcc.target/xtensa/sibcalls.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -mabi=call0 -foptimize-sibling-calls" } */ + +extern int foo(int); +extern void bar(int); + +int test_0(int a) { + return foo(a); +} + +void test_1(int a) { + bar(a); +} + +/* { dg-final { scan-assembler-not "ret" } } */ From patchwork Tue Jun 14 03:37:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takayuki 'January June' Suwa X-Patchwork-Id: 1643087 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=Sul2Ive0; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LMZNZ48hHz9sG2 for ; Tue, 14 Jun 2022 13:55:58 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B0310383F945 for ; Tue, 14 Jun 2022 03:55:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B0310383F945 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1655178956; bh=TLWY2MytSIE22KSQkf8Z1Q0OqvE6oX5SXjOzXFIuc2k=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Sul2Ive0MwBPujzTGkv/I64jEF+LrOAWRbZoVAZxaRIwjZILTI5kxcoORtQny6O2a 5ACeXBPfQUwL3pna+sAuE7SfY+qW1l2JaRwQ9A2cvxn2T/CNBjTYskC2gLzwOvTBbQ xdqmkiIrTSjhez7Ky9wYJEv9XlfmhG3Arhx/kJT8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from nh603-vm14.bullet.mail.ssk.yahoo.co.jp (nh603-vm14.bullet.mail.ssk.yahoo.co.jp [182.22.90.55]) by sourceware.org (Postfix) with SMTP id E964E386DC7B for ; Tue, 14 Jun 2022 03:54:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E964E386DC7B Received: from [182.22.66.104] by nh603.bullet.mail.ssk.yahoo.co.jp with NNFMP; 14 Jun 2022 03:54:38 -0000 Received: from [182.22.91.133] by t602.bullet.mail.ssk.yahoo.co.jp with NNFMP; 14 Jun 2022 03:54:38 -0000 Received: from [127.0.0.1] by omp606.mail.ssk.yahoo.co.jp with NNFMP; 14 Jun 2022 03:54:38 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 306886.14318.bm@omp606.mail.ssk.yahoo.co.jp Received: (qmail 82696 invoked by alias); 14 Jun 2022 03:54:38 -0000 Received: from unknown (HELO ?192.168.2.3?) (175.177.45.163 with ) by smtp6004.mail.ssk.ynwp.yahoo.co.jp with SMTP; 14 Jun 2022 03:54:38 -0000 X-YMail-JAS: JBw_6pwVM1mFo8KbFN0dc.KtpjobXCB44jgUFfSDjGDC_843NemwDdcRAF0koR8MKwycM_y5rF0..oUUwP9Y3RRona4VFwofCqkYNshQF1OXxl6xgoYBtCYwNITm378pr97zWvhyvA-- X-Apparently-From: X-YMail-OSG: 2Gx5r0sVM1lFgXqtikTGWxAX4I7Y2vkDEI27vX8qNDbek4X oLTWnVchkLfgYB85T_OhqTJQNcwldaLZY57cnq4Zbqlttz2phf9ZY8ch2bk9 ihvN2dw.oIqAmK.xrTT_zJB.tfSEBxgaOuvE7m8IiSXzCAmtmJkeqoUGpC8l tPnrWf09oMRgceUoRFxTErzvErBbkEMPlXVawCmtKGV_gHxp8jX3KLNoE8p9 fOxKPTM1GQOvaJqyBr9Qjt0rxScFzmbwWen6v2vsnxnky_6MpxA09uctg89g j.fO.hc.eMtjg50bacrj8_akv1AN0uZKIRlbedpcbtXilvNab0O.U4nca17S QV0wrYLJc8gVYoFl5Anw85fKWCSye17mxfADnM76ftGwgztpSXiMLzbKef8J bcc70EyWnYc6sDHfqEJ5WS9.ex_vius0iJFeQfr7cQ719vpoSSx3zDqXG1Xa XC3m2SbUyAHTcPS3syTO1E0tKplPDr59s8sz0oRY9ZcsWUzuO.4BhgtYSXBy lmCrapf2Nq5LdGiRT8DGsbn3iWaffk1lvK6LmEudaefCnVOP2Isa0YYayzlg fX0T6JH_yo6jjRyHmkQyRV2M5_VOCblp7Nbml.nINokZL9JFjBPNnc1cAagy Et6kbZp_BYUs2AMn20PR3Sx0X7_qKoKPfzPT.l7GsVFFQiwCQYjZFDCOSua0 DJCX3D09bMSruPCZstkvUiclsYB3jTtGqliCX9If_zv4tOD4HyWY6XPCsr0h a.Q2.sCOTJwBYdHlchJoBOZXQ0LxM3SlHE.xYPhRwDtayTTDCGvqCMsOxxBy LWHvY9WFzH5k5l1kfuQHCGhWXX4_1QmfO5e_aCg34QM4AV_muxQxTSC0Uqsx or1M3qQwTNFW0y9lpoSli794IJ8MGEUGTgOmtZBPKsmMGuzw_eLaBTyC4g37 MmQICOXc.dK28I0cN3w-- Message-ID: <6713ecef-b26f-b1ec-cfff-f41535c7d7f9@yahoo.co.jp> Date: Tue, 14 Jun 2022 12:37:54 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Content-Language: en-US To: GCC Patches Subject: [PATCH 3/5] xtensa: Add some dedicated patterns that correspond to GIMPLE canonicalizations X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Takayuki 'January June' Suwa via Gcc-patches From: Takayuki 'January June' Suwa Reply-To: Takayuki 'January June' Suwa Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This patch offers better RTL representations against straightforward derivations from some tree optimizers' canonicalized forms. - rounding up to even, such as '(x + (x & 1))', is canonicalized to '((x + 1) & -2)', but the former is one instruction less than the latter in Xtensa ISA. - signed greater or equal to zero as logical value '((signed)x >= 0)', is canonicalized to '((unsigned)(x ^ -1) >> 31)', but the equivalent '(((signed)x >> 31) + 1)' is one instruction less. gcc/ChangeLog: * config/xtensa/xtensa.md (*round_up_to_even): New insn-and-split pattern. (*signed_ge_zero): Ditto. --- gcc/config/xtensa/xtensa.md | 45 +++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/gcc/config/xtensa/xtensa.md b/gcc/config/xtensa/xtensa.md index 181f935e3c3..9588a829136 100644 --- a/gcc/config/xtensa/xtensa.md +++ b/gcc/config/xtensa/xtensa.md @@ -2679,3 +2679,48 @@ xtensa_expand_atomic (, operands[0], operands[1], operands[2], true); DONE; }) + +(define_insn_and_split "*round_up_to_even" + [(set (match_operand:SI 0 "register_operand" "=a") + (and:SI (plus:SI (match_operand:SI 1 "register_operand" "r") + (const_int 1)) + (const_int -2)))] + "" + "#" + "can_create_pseudo_p ()" + [(set (match_dup 2) + (and:SI (match_dup 1) + (const_int 1))) + (set (match_dup 0) + (plus:SI (match_dup 2) + (match_dup 1)))] +{ + operands[2] = gen_reg_rtx (SImode); +} + [(set_attr "type" "arith") + (set_attr "mode" "SI") + (set (attr "length") + (if_then_else (match_test "TARGET_DENSITY") + (const_int 5) + (const_int 6)))]) + +(define_insn_and_split "*signed_ge_zero" + [(set (match_operand:SI 0 "register_operand" "=a") + (ge:SI (match_operand:SI 1 "register_operand" "r") + (const_int 0)))] + "" + "#" + "" + [(set (match_dup 0) + (ashiftrt:SI (match_dup 1) + (const_int 31))) + (set (match_dup 0) + (plus:SI (match_dup 0) + (const_int 1)))] + "" + [(set_attr "type" "arith") + (set_attr "mode" "SI") + (set (attr "length") + (if_then_else (match_test "TARGET_DENSITY") + (const_int 5) + (const_int 6)))]) From patchwork Tue Jun 14 03:39:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takayuki 'January June' Suwa X-Patchwork-Id: 1643089 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=BF7pdusB; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LMZQt6Rsvz9s0r for ; Tue, 14 Jun 2022 13:57:58 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B516D384145E for ; Tue, 14 Jun 2022 03:57:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B516D384145E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1655179076; bh=JFag3pW6KrJhEfr2Y6NPPtAH83Sg8zocwQBHuQasjIA=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=BF7pdusB4MAEaAnUOxuQaX87I7VhkVn5jMuK5wwpZDEF8bJYjpL5e1htSeCPt1mdR is3xEzM39wFo6ZZKZY7ytwmk2Y5ml/a+JKQ75JQUm0G+IAcWtpudDAuS/jcOLuwxVH uc88zOBofbaoXwofxdhwtD0F6GvRxiBPWmA6nNr8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from nh604-vm3.bullet.mail.ssk.yahoo.co.jp (nh604-vm3.bullet.mail.ssk.yahoo.co.jp [182.22.90.60]) by sourceware.org (Postfix) with SMTP id 50C83386DC7F for ; Tue, 14 Jun 2022 03:54:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 50C83386DC7F Received: from [182.22.66.105] by nh604.bullet.mail.ssk.yahoo.co.jp with NNFMP; 14 Jun 2022 03:54:39 -0000 Received: from [182.22.91.132] by t603.bullet.mail.ssk.yahoo.co.jp with NNFMP; 14 Jun 2022 03:54:39 -0000 Received: from [127.0.0.1] by omp605.mail.ssk.yahoo.co.jp with NNFMP; 14 Jun 2022 03:54:39 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 645429.8527.bm@omp605.mail.ssk.yahoo.co.jp Received: (qmail 87768 invoked by alias); 14 Jun 2022 03:54:39 -0000 Received: from unknown (HELO ?192.168.2.3?) (175.177.45.163 with ) by smtp6002.mail.ssk.ynwp.yahoo.co.jp with SMTP; 14 Jun 2022 03:54:39 -0000 X-YMail-JAS: V78HjdMVM1kzYde6QMW_fbkN_xKwXIKGKQ8dWVm.iwJRA69uM6MatPp2f_3y281xsiwCVXT8OImGJ_8izH9Tt5EDasUBZcHm5YbSjJNTZ6WulZHa36dffoVp7_axpHLCoDvxQo2xkg-- X-Apparently-From: X-YMail-OSG: l8LAZPwVM1nqRVi6PcRBSjNvMTam2qbWjuSzQeu1U__PiAE t7VlQ0zE0B4gMyq6izl8BTTduQcf135AYwCHVbaO_2EI6OjrBFjWsieC2vHv jhBinrEC.wICdU.0rUJw0rnoWcF9ySTXNprX7rXHoZdkEvsaqbqro_ed9pk0 3GEaJf8_wQuQZkGFZjnlE5ZHlDqi2GJomA3ZXaue8PCKFJer_SzlgRi4eF1y PQZa805KwqeJJAZNqRICS9EH7tukmjVjIpesLPC8ECn8ZXAR5xnyIgx3Ghs4 chdwWANEZqw0jk5IP_9EMl0OyBp5EyGXEq3bb9MzqD.fBwLQ_AfrFKX8ZyhY VNhuB0DZDxq59.8Y9POsWw_QITRgypKd6EKnTqu4FsguhE7ikvxraqzBkanL 1s1rwwomNRZKc5LvyOYkaKqgmRiJbV5GrZlGl59X3EZJQRwKkf60zSXse2d_ y9nNJU2SLaTLRRolOHPffWlLuqGVX94yKz4Br5nYhSx_nJ27QOUw_6GurO9K Hu.zPxqCU.9BkPPKGDD1uVQdihYo70YzpMhABPEQMC78zCEXTclfyEirBvsA wzbt7yyiKxJInsqEMkWu.rzrN6ZK5or51m7Lsx8L4dJRu.MsLj2IkdWqItQ_ llo1l5WfiUcbNiYrrLnatZpoP3ubAG5cYYsDW2XjJtD5Ezak7UrEgRlVzNus zeVbBgumWTbkR_v_RC1l3bGedsF.LpT0IHwtuOyXqi1.JfuqCnWNt8IKSqMF ktC6YsR2jR7XmiQB4a60Yc6FDotvTa2C5JrzgCb4l7pNJQqxxheMftZpG85N jFBKZEDqmmlf9INMepg2sz7T2Gj6Yp1RnvrUMbftbcJ7Zp8r4UqMyM7hPLtR u.F7jHBkcmIaWc6mhMXkpA5w3OThelkJec05F4M9p4JUX2AUwSOUTBOl9Q0k vld8HwBz_XjIS0KsmqA-- Message-ID: <0ebde82d-4449-c731-1656-0e1b29d5ed9c@yahoo.co.jp> Date: Tue, 14 Jun 2022 12:39:49 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Content-Language: en-US To: GCC Patches Subject: [PATCH 4/5] xtensa: Eliminate unwanted reg-reg moves during DFmode input reloads X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Takayuki 'January June' Suwa via Gcc-patches From: Takayuki 'January June' Suwa Reply-To: Takayuki 'January June' Suwa Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" When spilled DFmode registers are reloaded in, once loaded into a pair of SImode regs and then copied from that regs. Such unwanted reg-reg moves seems not to be eliminated at the "cprop_hardreg" stage, despite no problem in output reloads. Luckily it is easy to resolve such inefficiencies, with the use of peephole2 pattern. gcc/ChangeLog: * config/xtensa/predicates.md (reload_operand): New predicate. * config/xtensa/xtensa.md: New peephole2 pattern. --- gcc/config/xtensa/predicates.md | 13 +++++++++++++ gcc/config/xtensa/xtensa.md | 31 +++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/gcc/config/xtensa/predicates.md b/gcc/config/xtensa/predicates.md index d63a6cf034c..edd13ae41b9 100644 --- a/gcc/config/xtensa/predicates.md +++ b/gcc/config/xtensa/predicates.md @@ -165,6 +165,19 @@ (and (match_code "const_int") (match_test "xtensa_mem_offset (INTVAL (op), SFmode)"))) +(define_predicate "reload_operand" + (match_code "mem") +{ + const_rtx addr = XEXP (op, 0); + if (REG_P (addr)) + return REGNO (addr) == A1_REG; + if (GET_CODE (addr) == PLUS) + return REG_P (XEXP (addr, 0)) + && REGNO (XEXP (addr, 0)) == A1_REG + && CONST_INT_P (XEXP (addr, 1)); + return false; +}) + (define_predicate "branch_operator" (match_code "eq,ne,lt,ge")) diff --git a/gcc/config/xtensa/xtensa.md b/gcc/config/xtensa/xtensa.md index 9588a829136..e6f5594762f 100644 --- a/gcc/config/xtensa/xtensa.md +++ b/gcc/config/xtensa/xtensa.md @@ -2724,3 +2724,34 @@ (if_then_else (match_test "TARGET_DENSITY") (const_int 5) (const_int 6)))]) + +(define_peephole2 + [(set (match_operand:SI 0 "register_operand") + (match_operand:SI 6 "reload_operand")) + (set (match_operand:SI 1 "register_operand") + (match_operand:SI 7 "reload_operand")) + (set (match_operand:SF 2 "register_operand") + (match_operand:SF 4 "register_operand")) + (set (match_operand:SF 3 "register_operand") + (match_operand:SF 5 "register_operand"))] + "REGNO (operands[0]) == REGNO (operands[4]) + && REGNO (operands[1]) == REGNO (operands[5]) + && peep2_reg_dead_p (4, operands[0]) + && peep2_reg_dead_p (4, operands[1])" + [(set (match_dup 2) + (match_dup 6)) + (set (match_dup 3) + (match_dup 7))] +{ + uint32_t check = 0; + int i; + for (i = 0; i <= 3; ++i) + { + uint32_t mask = (uint32_t)1 << REGNO (operands[i]); + if (check & mask) + FAIL; + check |= mask; + } + operands[6] = gen_rtx_MEM (SFmode, XEXP (operands[6], 0)); + operands[7] = gen_rtx_MEM (SFmode, XEXP (operands[7], 0)); +}) From patchwork Tue Jun 14 03:53:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takayuki 'January June' Suwa X-Patchwork-Id: 1643090 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=ZaT8smrv; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LMZRz4xKdz9s0r for ; Tue, 14 Jun 2022 13:58:55 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8253F3841461 for ; Tue, 14 Jun 2022 03:58:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8253F3841461 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1655179133; bh=6VBkaYgj6MryJciIUa8i94rODoq5W1BX5eepp7VOBc8=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=ZaT8smrvVzAxJJJPBfLEcLx1SxuUu/Hc6mKTjfreU/MHTrEPAaZAxR9LIqogZC0VS 1uODz9JE69+P13Vh5O9DZpmAVLjsJ/aYg80rJrFXwXvzAVsnpdoqoyagBfzpxJQFEd Rzw5OK/l1vOX6k1TVUjOn8eXJTHAHCrKibZjeojY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from nh605-vm1.bullet.mail.ssk.yahoo.co.jp (nh605-vm1.bullet.mail.ssk.yahoo.co.jp [182.22.90.74]) by sourceware.org (Postfix) with SMTP id 57A193857363 for ; Tue, 14 Jun 2022 03:54:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 57A193857363 Received: from [182.22.66.106] by nh605.bullet.mail.ssk.yahoo.co.jp with NNFMP; 14 Jun 2022 03:54:40 -0000 Received: from [182.22.91.129] by t604.bullet.mail.ssk.yahoo.co.jp with NNFMP; 14 Jun 2022 03:54:40 -0000 Received: from [127.0.0.1] by omp602.mail.ssk.yahoo.co.jp with NNFMP; 14 Jun 2022 03:54:40 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 623587.13723.bm@omp602.mail.ssk.yahoo.co.jp Received: (qmail 4969 invoked by alias); 14 Jun 2022 03:54:40 -0000 Received: from unknown (HELO ?192.168.2.3?) (175.177.45.163 with ) by smtp6005.mail.ssk.ynwp.yahoo.co.jp with SMTP; 14 Jun 2022 03:54:40 -0000 X-YMail-JAS: oCfeK74VM1kagkCd3prYXpw4AjDDvf.nxZBXqiCVZ3bY4KcTpzm9L6geJzJseguamRqWnRJWyZ4xtgjzmJ.wW6DL1k2odNBjKrCks6AzFbK3JSk.32DEekVbDCNaLQjjkh_ctHxBkg-- X-Apparently-From: X-YMail-OSG: nXAaS5cVM1lsgYtcTM8c1eLFvesaildKLVDxu7.gw1fVj4i aqma4IWz3hMGXSSR77iN9RmxyJcGLL9uQBg_usD5wuHE4AqJnYtJ452lk6j3 52thdW2IRH2iGXzujh5vNQHj5e8LotYOqXzpn4e9_MtpWTv.5FaBGJClHV_g x6xAO8Wewzk7siXIZ02wf6QNJqVZzWHyO8DfiFmyyNEIiO5zCEF0i.yKB9Wp 9kVzUzupOTlenoushAJFrdw92uL8ikeY1rVa0obKmY4flUPqavsSGrjqbB6H _Hl66B.BsjYI7999Rnim7DXhdzBbn_XGHhuUm4IQV89EmlYXrFYd3kZVuZhY b61SXz5NyXH9HO0Bxo6SoqH5wvg153RSAutd9xyYtn6Ak1PhHtjj.hI6bPsJ VjEYHkFS5B5PBsmXCrGpNgUfAtn3nI2ozXCfErJsJUHv55_e1x6mRrffK4L_ aHpIkzR7p81_OW4jIfjy.mXJJWtIMgEwdsizFxIksMFt9Z1RJZOqjhzA9T.V j4i1iFiLdtT3st23diT1xBZi_dwZ8kqXrgl.a1X2SUNEwW1HVUUO0LtzjBcp AWav.Q898XQ_wZmgoBBZWHM.FnYD4.7ptSa_0walKkCvey0pWmMnJeH2OBFa .MEKS6yeG.QF5C.w8xzTC7lkzfg_JseQUPtiXQBLcZmdsbWycPakmEsOHbSz XN0NSgeMGlhpU63kmnibVoBMXq0YAapF3qtIkbBgSHItnV2vHVu.wqIR3iFK YBt_RXCYViWON5CYoZVJaW2C6b52PyljXMNFyBTfaSMHqbyl5tJL0tFS4quF lP.SsAvNVxaRHf5MNGjiNozNtEPFct0tRD9YIqS_j76PFt4M4g8E70jwmhHV hcC3IocGv6Au_LGIaE_r2KSdYHujJdPkXcfa6rWxM.GHtG.n.JSeqUMWeGyi jgLJvMyBJwTVOsOU90A-- Message-ID: Date: Tue, 14 Jun 2022 12:53:04 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Content-Language: en-US To: GCC Patches Subject: [PATCH 5/5] xtensa: Eliminate [DS]Cmode hard register clobber that is immediately followed by whole overwrite the register X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Takayuki 'January June' Suwa via Gcc-patches From: Takayuki 'January June' Suwa Reply-To: Takayuki 'January June' Suwa Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" RTL expansion of substitution to [DS]Cmode hard register includes obstructive register clobber. A simplest example: double _Complex test(double _Complex c) { return c; } will be converted to: (set (reg:DF 42 [ c ]) (reg:DF 2 a2)) (set (reg:DF 43 [ c+8 ]) (reg:DF 4 a4)) (clobber (reg:DC 2 a2)) (set (reg:DF 2 a2) (reg:DF 42 [ c ])) (set (reg:DF 4 a4) (reg:DF 43 [ c+8 ])) (use (reg:DC 2 a2)) (return) and then finally: test: mov a8, a2 mov a9, a3 mov a6, a4 mov a7, a5 mov a2, a8 mov a3, a9 mov a4, a6 mov a5, a7 ret As you see, it is so ridiculous. This patch eliminates such clobber in order to prune away the wasted move instructions by the optimizer: test: ret gcc/ChangeLog: * config/xtensa/xtensa.md (DSC): New split pattern and mode iterator. --- gcc/config/xtensa/xtensa.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/gcc/config/xtensa/xtensa.md b/gcc/config/xtensa/xtensa.md index e6f5594762f..3b3be5f8436 100644 --- a/gcc/config/xtensa/xtensa.md +++ b/gcc/config/xtensa/xtensa.md @@ -86,6 +86,10 @@ ;; This code iterator is for *shlrd and its variants. (define_code_iterator ior_op [ior plus]) +;; This mode iterator allows the DC and SC patterns to be defined from +;; the same template. +(define_mode_iterator DSC [DC SC]) + ;; Attributes. @@ -2755,3 +2759,27 @@ operands[6] = gen_rtx_MEM (SFmode, XEXP (operands[6], 0)); operands[7] = gen_rtx_MEM (SFmode, XEXP (operands[7], 0)); }) + +(define_split + [(clobber (match_operand:DSC 0 "register_operand"))] + "GP_REG_P (REGNO (operands[0]))" + [(const_int 0)] +{ + unsigned int regno = REGNO (operands[0]); + machine_mode inner_mode = GET_MODE_INNER (mode); + rtx_insn *insn; + rtx x; + if (! ((insn = next_nonnote_nondebug_insn (curr_insn)) + && NONJUMP_INSN_P (insn) + && GET_CODE (x = PATTERN (insn)) == SET + && REG_P (x = XEXP (x, 0)) + && GET_MODE (x) == inner_mode + && REGNO (x) == regno + && (insn = next_nonnote_nondebug_insn (insn)) + && NONJUMP_INSN_P (insn) + && GET_CODE (x = PATTERN (insn)) == SET + && REG_P (x = XEXP (x, 0)) + && GET_MODE (x) == inner_mode + && REGNO (x) == regno + REG_NREGS (operands[0]) / 2)) + FAIL; +})