From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from sonicconh5002.mail.kks.yahoo.co.jp (sonicconh5002.mail.kks.yahoo.co.jp [114.110.61.26]) by sourceware.org (Postfix) with ESMTPS id 3B0C83858D28 for ; Thu, 19 Jan 2023 03:50:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3B0C83858D28 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: 59egE8kVM1kuxbmYhItV3ZCTcju35gMPDR43KTOLXjPdXnr99SV6mj1YP_1aF41 GqibsvLG6altOrUZw_wglmej.MAY1RGlOD7ZqZmJSEzw2g4gHLNIM3VnIXFXMWXp8g_PGByi8w0l OGnJTTbhnNFPuob_IZx.dHIhkL5qzgK1eImSPGpxMOaBQNJ5dSx8LAaU6R7Ap28xkGLhjBkKCZmA CSgtimaN5D9X9MYRZX3mu2VNbkSjNMKBzYAjf8cYy.G8_td1SoZrDD2SiUjb7ajLHi1GXsKKC1GU 5oTq1Ar2iyt.E7pJa_hnqiJ0P2lWPqdT3fW_iw76SiVg2vtvrgdSwz3IgcqLSCOZlyVhLHj63D5z eLwKkhA4WUSY.BxVavvGTz5XbG2qdHVFFFQaU7kOV6dsQyceTYjy0ScBCo1nS_iU8ECBJIQKsyEK MHH2Oso7fjkrZtNutOhDKNE8t5WJ8qUuYiV9fk6c_mH0SWzaDDP5KVgfi1SExp1PRoZdv_EnGN2s UZanOwQVBS94sffSx1a7KQT_grpBf3R3uTLTTlVsBCaQJz6ybzqjoUmcNcev1dmdp3ETR2FbfLaA PfScq8Svt1xpTiVh3zPibfdi2qldq6wpaWFFfRjs57aZBcwONanOphdpr.puK6l6twThU1D9pCKI 23CkVzeZI.zZqQDaVK50MCzPwe1wjlGJCuSEyCzAINU9XiKx1KkMJ4cpipGpN081nFk4nxMHyIP. pR1BYos4FC7WQEvbWVg_6J79jVrus0RP4wxJyY5U13horNXPeJ5oyjMNUhKd5AvwoVgPxuUgt_7U V_FodbBirnT8Pgmvyt4key2AtMhxgg9Dz47RCwawvyFqL0Ii0p7PxiOsOLXYBcLDrYPc3FvSXaml b1DaUeuBXf5L1sP4ksBLgayo6OZ_ti0FM8COzafK5SBeU04zg0YtEwgzc1RCEcujKA4XywP0Qr_O zxmBk3TM- Received: from sonicgw.mail.yahoo.co.jp by sonicconh5002.mail.kks.yahoo.co.jp with HTTP; Thu, 19 Jan 2023 03:50:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1674100213; s=yj20110701; d=yahoo.co.jp; h=Message-ID:Date:MIME-Version:From:Subject:To:Cc:Content-Type:Content-Transfer-Encoding:References; bh=CB/5ughfF+qp2YDToekVACI85rMTIKf1PLiiU8GccaM=; b=OlJjQ15edr9PCipbTobMHYaKXgv6BmdA3KOFvKU+VQXKQ3G7y/5JhNDpSaSJqyxB 0ihmyc4p+ca/p3gcVpQoyPd0kJQAZDOhEoV6IDNmv5ouZGyrL5WAdFmAOXGlLqIEn2G 8I/3d+0AqopcMah14gv9buDs1a+s4vZYN8yAsOG4= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=yj20110701; d=yahoo.co.jp; h=Message-ID:Date:MIME-Version:From:Cc:Content-Type:Content-Transfer-Encoding:References; b=qEDxw3G7jVZioduTbnQ5vI91BLIG+KgYOFJUrAkqYdgliUBnCf3fHxky1RyvcR1c uokGF07UOBZG9XX4iwJsQxd889ER8jOo8l9lucpAQ9dAeMt+gAQmeUE4lUAszuQEw5z pvBa+rhF7BkrxjE3ZpFsqehUMKJrZsGxMSQbU+gQ=; Received: by smtphe5002.mail.kks.ynwp.yahoo.co.jp (YJ Hermes SMTP Server) with ESMTPA ID af6a8cd935fe9e1ab8852e4a201f4723; Thu, 19 Jan 2023 12:50:10 +0900 (JST) Message-ID: <465b0cbe-73ca-f5a0-661d-d34217e29b4d@yahoo.co.jp> Date: Thu, 19 Jan 2023 12:50:10 +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 From: Takayuki 'January June' Suwa Subject: [PATCH v4] xtensa: Eliminate the use of callee-saved register that saves and restores only once To: GCC Patches Cc: Max Filippov Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit References: <465b0cbe-73ca-f5a0-661d-d34217e29b4d.ref@yahoo.co.jp> X-Spam-Status: No, score=-12.0 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: In the previous patch, if insn is JUMP_INSN or CALL_INSN, it bypasses the reg check (possibly FAIL). ===== 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 4f1e8fd13..ac04ef6f0 100644 --- a/gcc/config/xtensa/xtensa.md +++ b/gcc/config/xtensa/xtensa.md @@ -3029,3 +3029,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 + || DEBUG_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 + || DEBUG_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