From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from sonicconh6003-vm2.mail.ssk.yahoo.co.jp (sonicconh6003-vm2.mail.ssk.yahoo.co.jp [182.22.37.43]) by sourceware.org (Postfix) with ESMTPS id 93D2A3858D28 for ; Wed, 18 Jan 2023 04:24:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 93D2A3858D28 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 X-YMail-OSG: hX_0YTAVM1mRAZNopLQbdXQjjO8fM0yWk00iCnMA_E6HEaVN5h0956NN._HYFJV QJCAvx27rMZ.JvJf5o35bHlhQMHRpQsb9ozD8VfHeqDT7TmXwK4NvdC6SfjbehPyE84BzP7lRQP9 cUrkIigqa8Ibz021cd3o91DGpTlWygbSE7ZURPuHYzAFf3Eaz7NJyHgeqBXc_VNePJJvrQw4tIBP 3HfxCbq7nkWEjz6cZH4.ncJGDlRekYBuJknllYRP2sFlU2y5y9AvMoF0XbphFFejWLCFv46x6xJQ SL6Rsxf5O1aygFxZmTHU0b0wnGve4Rhc2q.dkze20S3kDR3WE6_jCesjGu4DzZ9h2uNpHa8gTbfv bOaiWMY6aEJZPJfMtefDX7vcY0voAIjWPX2POBBOMkycW5Y2zxbZ3EIi0ETSDrI3Nbv1W.nLaRPs T3MtaAyCjtk2bAkT.TbBSCFWBvNskrgdxXUhubDYhPyJol6TBjCLACLIKPEw0KRH0ED2O_JM6Yu5 qejwl5ff.NkVh6J_RC9yM_kkFs5YrZVjP0RONvD7P6bwAbVHEefFTbdatgwdNKuT9iwBLrS4V3s8 QFg_230jI94RNzHXiOLWEW6bQWOsv6SmtxsY0QsaSZfYJU8Ol_VVJgWrAeLub_xTC2aqc7uVdixu 1TPnK7saiv9j4tT.3mqLVk4PN8h4GXqNmA.HeUXv0ISq_q5NC5Vb18FIOFUGrN7hGFvtWwiDXpTV .JjPvAyngDoetrNXNDk_Z0CxXCbeci1CZyIaS5pDc8G1zUx7MXLrxm2ANHlpgh3ppU3CFquoY8_j qd1iW_NjlufWgHisoAteYTFhoyHpiXp82RL_ihsO__Vyyqds782G7uauVmaeCbNucAe7Dd4cd0nd 6KwidygDsX6r35woh4lSxiO0GPbLOShzidddgEF9o_pOC5FVuVQY1j1HEvN1a8GU70sP_VMi0Wwq Jf54qlsKk Received: from sonicgw.mail.yahoo.co.jp by sonicconh6003.mail.ssk.yahoo.co.jp with HTTP; Wed, 18 Jan 2023 04:23:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1674015837; s=yj20110701; d=yahoo.co.jp; h=Message-ID:Date:MIME-Version:Subject:To:References:Cc:From:In-Reply-To:Content-Type:Content-Transfer-Encoding; bh=v0ahYZbUSUpu2bKlVg3VwzZx1TsR7LTdzEbJceXRz9o=; b=kN/W1BqYMtsN1g3DK7ORvIhkUCalU86d/tqTtzNwZKYK25FfQTsXx2edqubpe5xI nsAhy55PItQNbyeJ3h5Xy40NKP7SUWZxoFCkRVqN4WdesGZSfprcdi3E/joZtiFlyrS m1sUQN15H3qdoLNv+70RQW/+weq8/3lpi7OU8/9Q= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=yj20110701; d=yahoo.co.jp; h=Message-ID:Date:MIME-Version:References:Cc:From:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=vJE3wV6I/D5w+SKmkNm6HePSkpKDUyRIeEw8621pVT3WvBz5WpIh+EDNz/WVLrn3 dg8mQRzT6t3kggtL6Hz7V6D2NkT7PknQbuhwlhPqybDll9Wm9s0ViZK6Ml6z43wGcHK HNuaOymsJ0JPDJj9CAUc6yG9Mbh7GP93Jm8VrNmU=; Received: by smtphe5005.mail.kks.ynwp.yahoo.co.jp (YJ Hermes SMTP Server) with ESMTPA ID 12378e7b42370c7f6836888d1f1ad30f; Wed, 18 Jan 2023 13:23:53 +0900 (JST) Message-ID: Date: Wed, 18 Jan 2023 13:23:52 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: [PATCH v3] xtensa: Eliminate the use of callee-saved register that saves and restores only once To: GCC Patches References: <70bdc2f9-f0ae-cca7-0910-859cacbf5eae.ref@yahoo.co.jp> <70bdc2f9-f0ae-cca7-0910-859cacbf5eae@yahoo.co.jp> Cc: Max Filippov From: Takayuki 'January June' Suwa In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.8 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,RCVD_IN_MSPIKE_H2,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 List-Id: On 2023/01/17 20:23, Max Filippov wrote: > Hi Suwa-san, Hi! > There's still a few regressions in tests with -fcompare-debug because > code generated with -g and without it is different: > E.g. check the following test with -g0 and -g: Again debug_insn is the problem... ===== In the case of the CALL0 ABI, values that must be retained before and after function calls are placed in the callee-saved registers (A12 through A15) and referenced later. However, it is often the case that the save and the reference are each only once and a simple register- register move (the frame pointer is needed to recover the stack pointer and must be excluded). e.g. in the following example, if there are no other occurrences of register A14: ;; before ; prologue { ... s32i.n a14, sp, 16 ... ; } prologue ... mov.n a14, a6 ... call0 foo ... mov.n a8, a14 ... ; epilogue { ... l32i.n a14, sp, 16 ... ; } epilogue It can be possible like this: ;; after ; prologue { ... (deleted) ... ; } prologue ... s32i.n a6, sp, 16 ... call0 foo ... l32i.n a8, sp, 16 ... ; epilogue { ... (deleted) ... ; } epilogue This patch introduces a new peephole2 pattern that implements the above. gcc/ChangeLog: * config/xtensa/xtensa.md: New peephole2 pattern that eliminates the use of callee-saved register that saves and restores only once for other register, by using its stack slot directly. --- gcc/config/xtensa/xtensa.md | 62 +++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/gcc/config/xtensa/xtensa.md b/gcc/config/xtensa/xtensa.md index 98f3c468f8b..2f3b2256d8b 100644 --- a/gcc/config/xtensa/xtensa.md +++ b/gcc/config/xtensa/xtensa.md @@ -3024,3 +3024,65 @@ FALLTHRU:; operands[1] = GEN_INT (imm0); operands[2] = GEN_INT (imm1); }) + +(define_peephole2 + [(set (match_operand:SI 0 "register_operand") + (match_operand:SI 1 "reload_operand"))] + "!TARGET_WINDOWED_ABI && df + && epilogue_contains (insn) + && ! call_used_or_fixed_reg_p (REGNO (operands[0])) + && (!frame_pointer_needed + || REGNO (operands[0]) != HARD_FRAME_POINTER_REGNUM)" + [(const_int 0)] +{ + rtx reg = operands[0], pattern; + rtx_insn *insnP = NULL, *insnS = NULL, *insnR = NULL; + df_ref ref; + rtx_insn *insn; + for (ref = DF_REG_DEF_CHAIN (REGNO (reg)); + ref; ref = DF_REF_NEXT_REG (ref)) + if (DF_REF_CLASS (ref) != DF_REF_REGULAR + || ! NONJUMP_INSN_P (insn = DF_REF_INSN (ref))) + continue; + else if (insn == curr_insn) + continue; + else if (GET_CODE (pattern = PATTERN (insn)) == SET + && rtx_equal_p (SET_DEST (pattern), reg) + && REG_P (SET_SRC (pattern))) + { + if (insnS) + FAIL; + insnS = insn; + continue; + } + else + FAIL; + for (ref = DF_REG_USE_CHAIN (REGNO (reg)); + ref; ref = DF_REF_NEXT_REG (ref)) + if (DF_REF_CLASS (ref) != DF_REF_REGULAR + || ! NONJUMP_INSN_P (insn = DF_REF_INSN (ref))) + continue; + else if (prologue_contains (insn)) + { + insnP = insn; + continue; + } + else if (GET_CODE (pattern = PATTERN (insn)) == SET + && rtx_equal_p (SET_SRC (pattern), reg) + && REG_P (SET_DEST (pattern))) + { + if (insnR) + FAIL; + insnR = insn; + continue; + } + else + FAIL; + if (!insnP || !insnS || !insnR) + FAIL; + SET_DEST (PATTERN (insnS)) = copy_rtx (operands[1]); + df_insn_rescan (insnS); + SET_SRC (PATTERN (insnR)) = copy_rtx (operands[1]); + df_insn_rescan (insnR); + set_insn_deleted (insnP); +}) -- 2.30.2