From patchwork Tue Mar 26 14:44:25 2024 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: 1916209 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=yahoo.co.jp header.i=@yahoo.co.jp header.a=rsa-sha256 header.s=yj20110701 header.b=NN1gXB/k; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4V3t151RT3z1yY2 for ; Wed, 27 Mar 2024 01:46:49 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7E1F9385843E for ; Tue, 26 Mar 2024 14:46:47 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from omggw0022.mail.otm.yahoo.co.jp (omggw0022.mail.otm.yahoo.co.jp [182.22.18.42]) by sourceware.org (Postfix) with ESMTPS id ECE263858C56 for ; Tue, 26 Mar 2024 14:46:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ECE263858C56 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=yahoo.co.jp Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=yahoo.co.jp ARC-Filter: OpenARC Filter v1.0.0 sourceware.org ECE263858C56 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=182.22.18.42 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711464383; cv=none; b=XD7qiW/XC46Y2Ta5P0EI/G7EuSh7C2QfcbVp5CFMEsWEYfLgUkBR9XJ8wPNQ7DGjwg7AgDc+TtghFP3WFX3q7IXaWsw0oJs1RB0vbj8Fb7EAS+hLPHNBvguOkWbRWpCKMsjs9Jloo8d2+2Ev6EDymg2tk9ByioL4QEmWkiqfK1c= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711464383; c=relaxed/simple; bh=DzUrkHD9v9d0y9CXp00W5l65YEIuGQ6X3waulNtD0fE=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=h0gU6zmcGVgLeqdu4wcnJkGlsZ1c0OEnYOchNad70gglk74ovIvaVMat8Mr6JFsgfI3R4CXQUzgyjySwUsttt7i1mPxbWO2ykOmTl7vWy4tc7yRexxhj3haxQ9aBRdFNuanBiaDtVgQpf/qbLHza7/Tx3iUQlI81UwI9q/0Rea0= ARC-Authentication-Results: i=1; server2.sourceware.org X-YMail-OSG: GQVCEEcVM1lytChBn2.Ketr.gdH2HMT7RbbeDOAZBkK9lWg1l5H8RAWj3Cuo_tU gABb7pVVjBox75n4HWVdRfvpmgaq9yqvVBzxv4oSE2Z6wV7V0gRZY89FvyQhPE7E1VVSinFCukax TaH.5jZCJ.nZRUzETfg9dzIv.wyiKjU07HIKuRl20z_D__9bOT3MINiJaQU.YCl21K8P.SBMBm8A EIxZWzDJ5HOZ_0GDpzIyBISIEUUIBKX_cEq9br7Cn_0cLN67TVXUogbqmTSvAAsZcOW.RvZyLQvh aExsfRBCjn3Za986JYR.Z5SCh5fApT9xvYi2U4fP6gXJeClgEM48a9YebXSShC3e4Qbvtd7vbgaw Kf_vashWJENyX9OeVMTGqt6CeohcZ4meXKBMSWmNf92xMvcqjUJKf9fxco7ErcJ_.Mt2LCDiwH3y BiRAFy5gzffuwVGXEACbKIn7sbN79IZw5SEAx9XqgMSHbSo.C0VjfuyNRh.wszAbvxW3kYH8YlNn LOX0oLuIw11BL1aduh3UEOD8T_GxaRxkkhdgyrxwL2b4K1RQ0AlBk817i_WadAqYN4TTj09KVQoC .484qYx7w7sBa7RpLdjUfoOfnMc77dJZOdMZRZYSEQ_p0Zi0EJCd_K6gqnUffAiBEO9vPGazUFhM prjCkio.Yd3mStBROuLoctTHfJPYWaIx9IYjYeQG2YWjsrjaJM54C4AG3xzn03xZmZ8i3vTdwLRP zH97kWgQ7EcMN7miAfxCni_xvkQ4WQurK9KyekkzzWQC0VTuTp.XU6UW4IK3NT42wxSbLnKVOTlb 4ypyq5ECreW_pY4QaE3Y4PVWptpPBJ4qYCrGA6K2.HUuFQeB75CoL_a2WW0d81Kxw0083pCM9oBl YyT31op_PnxLGpMyxoxg00DtNW38T3g9TBZ.0THhfR5ErywW7bTaugpAzMle0tZzoNHVBNF8sog_ qnIZ2hKHzeMZ56dnC_jSHK5MN7AIELz0jRrWvLeW5HPB_M7zc3RiAFZ.Qgq18_d04XemYv7wblRQ 1zkR_DUfPLlEKE1VV2DFEXM3cMyAh92JI2I06Ssp9FZhTOTE2DhmPQLB7uHCyt2uCVxpZ7sFUSGD LQ2aV28rUKrPZqKdHyvg- Received: from sonicgw.mail.yahoo.co.jp by sonicconh6003.mail.ssk.yahoo.co.jp with HTTP; Tue, 26 Mar 2024 14:46:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1711464265; s=yj20110701; d=yahoo.co.jp; h=References:Content-Transfer-Encoding:Content-Type:Subject:From:Cc:To:MIME-Version:Date:Message-ID; bh=mqJ7UfyAj3+0jiJ3eoCL50w5U5U4U8/BvNjuuO+B5EI=; b=NN1gXB/k6dveuvPA/cp4W7PdNWZV0JJ4w2ePg5lAFtMMQlsyOAfXaMyEicc88smf 2/ruARy+3J2RwwZPLJ+H7bDHwAP8E9+MdoI4HYCxrKHB4g4gzPXHfX7TTWodcsciV/u ezh9rP7R6ROAW5LVWxzc6GfDuJtDNtnUeY5wGPRI= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=yj20110701; d=yahoo.co.jp; h=Message-ID:Date:MIME-Version:Cc:From:Content-Type:Content-Transfer-Encoding:References; b=EEC9eL3zc7vQnX3E4wRTrAvbpqhtAcSR6l1AsN8+99gSTTzzicHQll7oMH1KxIVe hAO06rn5R6jHhwbEBE+tI1JYKEEDcy164zrHvswib8FJubQ5Xa6gE+o/8H2Ghu3LZk8 8B2sE2SeXhgHUN3aM34aFpFj6hlD6eAc998BCgQs=; Received: by smtphe5007.mail.kks.ynwp.yahoo.co.jp (YJ Hermes SMTP Server) with ESMTPA ID 0a0248039892f8f7a2a485836dbd0a45; Tue, 26 Mar 2024 23:46:16 +0900 (JST) Message-ID: <2cc8ab8b-84fe-4930-ba84-257b2458120e@yahoo.co.jp> Date: Tue, 26 Mar 2024 23:44:25 +0900 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: GCC Patches Cc: Max Filippov From: Takayuki 'January June' Suwa Subject: [PATCH 1/2] xtensa: Resurrect LEAF_REGISTERS and LEAF_REG_REMAP References: <2cc8ab8b-84fe-4930-ba84-257b2458120e.ref@yahoo.co.jp> X-Spam-Status: No, score=-12.4 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, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_PASS, TXREP 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org They were once mistakenly removed with "xtensa: Remove old broken tweak for leaf function", but caused unwanted register spills. gcc/ChangeLog: * config/xtensa/xtensa.h (LEAF_REGISTERS, LEAF_REG_REMAP): Withdraw the removal. (REG_ALLOC_ORDER): Cosmetics. * config/xtensa/xtensa.cc (xtensa_leaf_regs): Withdraw the removal. (xtensa_adjust_reg_alloc_order): Cosmetics. --- gcc/config/xtensa/xtensa.cc | 45 ++++++++++++++++++++++++++++++------- gcc/config/xtensa/xtensa.h | 29 ++++++++++++++++++++++-- 2 files changed, 64 insertions(+), 10 deletions(-) diff --git a/gcc/config/xtensa/xtensa.cc b/gcc/config/xtensa/xtensa.cc index 9beac932467..df888294556 100644 --- a/gcc/config/xtensa/xtensa.cc +++ b/gcc/config/xtensa/xtensa.cc @@ -110,6 +110,18 @@ struct GTY(()) machine_function HARD_REG_SET eliminated_callee_saved; }; +/* Vector, indexed by hard register number, which contains 1 for a + register that is allowable in a candidate for leaf function + treatment. */ + +const char xtensa_leaf_regs[FIRST_PSEUDO_REGISTER] = +{ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1 +}; + static void xtensa_option_override (void); static enum internal_test map_test_to_internal_test (enum rtx_code); static rtx gen_int_relational (enum rtx_code, rtx, rtx); @@ -4314,15 +4326,32 @@ void xtensa_adjust_reg_alloc_order (void) { static const int reg_windowed_alloc_order[FIRST_PSEUDO_REGISTER] = - REG_ALLOC_ORDER; + REG_ALLOC_ORDER; static const int reg_call0_alloc_order[FIRST_PSEUDO_REGISTER] = - { - 9, 10, 11, 7, 6, 5, 4, 3, 2, 8, 0, 12, 13, 14, 15, - 18, - 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, - 1, 16, 17, - 35, - }; + { + /* a9 ... a11 : no special usage */ + 9, 10, 11, + /* a7 ... a2 : function arguments, in reverse order */ + 7, 6, 5, 4, 3, 2, + /* a8 : static chain */ + 8, + /* a0 : return address (also callee saved) */ + 0, + /* a12 ... a15 : callee saved */ + 12, 13, 14, 15, + /* b0 : boolean register for floating-point CC */ + 18, + /* f0 ... f15 : floating-point registers */ + 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, + /* sp : stack pointer */ + 1, + /* fp : FRAME_POINTER (fake) */ + 16, + /* argp : ARG_POINTER (fake) */ + 17, + /* acc : MAC16 accumulator */ + 35, + }; memcpy (reg_alloc_order, TARGET_WINDOWED_ABI ? reg_windowed_alloc_order : reg_call0_alloc_order, diff --git a/gcc/config/xtensa/xtensa.h b/gcc/config/xtensa/xtensa.h index 9591b3d4b40..835cb4bbf3b 100644 --- a/gcc/config/xtensa/xtensa.h +++ b/gcc/config/xtensa/xtensa.h @@ -248,14 +248,39 @@ along with GCC; see the file COPYING3. If not see #define REG_ALLOC_ORDER \ { \ - 8, 9, 10, 11, 12, 13, 14, 15, 7, 6, 5, 4, 3, 2, \ + /* a8 ... a15 : no special usage */ \ + 8, 9, 10, 11, 12, 13, 14, 15, \ + /* a7 ... a2 : incoming arguments, in reverse order */ \ + 7, 6, 5, 4, 3, 2, \ + /* b0 : boolean register for floating-point CC */ \ 18, \ + /* f0 ... f15 : floating-point registers */ \ 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, \ - 0, 1, 16, 17, \ + /* a0 : return address */ \ + 0, \ + /* sp : stack pointer */ \ + 1, \ + /* fp : FRAME_POINTER (fake) */ \ + 16, \ + /* argp : ARG_POINTER (fake) */ \ + 17, \ + /* acc : MAC16 accumulator */ \ 35, \ } #define ADJUST_REG_ALLOC_ORDER xtensa_adjust_reg_alloc_order () +/* For Xtensa, the only point of this is to prevent GCC from otherwise + giving preference to call-used registers. To minimize window + overflows for the AR registers, we want to give preference to the + lower-numbered AR registers. For other register files, which are + not windowed, we still prefer call-used registers, if there are any. */ +extern const char xtensa_leaf_regs[FIRST_PSEUDO_REGISTER]; +#define LEAF_REGISTERS xtensa_leaf_regs + +/* For Xtensa, no remapping is necessary, but this macro must be + defined if LEAF_REGISTERS is defined. */ +#define LEAF_REG_REMAP(REGNO) ((int) (REGNO)) + /* Internal macros to classify a register number. */ /* 16 address registers + fake registers */