From patchwork Wed Jul 10 03:09:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fei Gao X-Patchwork-Id: 1958655 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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 4WJjXd25tcz1xqc for ; Wed, 10 Jul 2024 13:10:25 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D7A8F38708E3 for ; Wed, 10 Jul 2024 03:10:15 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from azure-sdnproxy.icoremail.net (azure-sdnproxy.icoremail.net [207.46.229.174]) by sourceware.org (Postfix) with ESMTP id 842903846089 for ; Wed, 10 Jul 2024 03:09:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 842903846089 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=eswincomputing.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=eswincomputing.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 842903846089 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=207.46.229.174 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720580999; cv=none; b=XQODEJ4cFMzIP0VDQPvLDQUIAPC65J037vLt2Glda76YSdqZE8oyqe5mZW+IYX9XWH2zwsgboNXoUtKdREvdbYtRoVbEXeENDQTDEVs6YlDNh851g03L9eGWLKjF8EZ9oJzebSdiZrLc/hYy5YkG0jg+aucQJlzUGAfSTz22zQw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720580999; c=relaxed/simple; bh=tTPp+ev/1N3NI+n8AwMZtcVn0Vjm3ZpefUKEdEptqOc=; h=From:To:Subject:Date:Message-Id; b=JAOm8Dr6qKlPrg3aF4uVA8vUavLTrCOvmDpvRa79ObTA0DWNuTWk3QG6NK3B9GtR9K0NZY7ezE16zhf/BuKOIB1kGpzW1H/kvOXkzzBRAU8VEv8s8YzxXiPxebzj0EBQvPNrCU6E3/udvVDfrEcPxPdV+HDW/46VsKLhm3mzwLw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from localhost.localdomain (unknown [10.12.130.31]) by app1 (Coremail) with SMTP id TAJkCgBX+OSA+41mpt8UAA--.17008S4; Wed, 10 Jul 2024 11:09:53 +0800 (CST) From: Fei Gao To: gcc-patches@gcc.gnu.org Cc: kito.cheng@gmail.com, palmer@dabbelt.com, jeffreyalaw@gmail.com, gaofei@eswincomputing.com Subject: [committed][PATCH] RISC-V: backport fix zcmp popretz [PR113715] Date: Wed, 10 Jul 2024 03:09:48 +0000 Message-Id: <20240710030948.28211-1-gaofei@eswincomputing.com> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: TAJkCgBX+OSA+41mpt8UAA--.17008S4 X-Coremail-Antispam: 1UD129KBjvJXoWxZF18Kw4DWFWkuw1DtF1DZFb_yoWruFy5pF 4fJr1ayrs5AF97Wr4ftFy7ta43Kws5Wr98uws7Cw40yw4DXrW5AF9xKFyfC3s8GFZ0vF43 uF47Cr4Yvw4j937anT9S1TB71UUUUUJqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUv014x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26F1j6w1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4U JVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gc CE3s1ln4kS14v26r1Y6r17M2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE 6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1Y6r17McIj6I8E87Iv67AKxVWUJVW8JwAm72 CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7 MxkIecxEwVCm-wCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c 02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_ Jw1lIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7 CjxVAFwI0_Jr0_Gr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v2 6r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7VUb hSdDUUUUU== X-CM-SenderInfo: xjdrwv3l6h245lqf0zpsxwx03jof0z/ X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLACK 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 Root cause: https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=b27d323a368033f0b37e93c57a57a35fd9997864 Commit above tries in targetm.gen_epilogue () to detect if there's li a0,0 insn at the end of insn chain, if so, cm.popret is replaced by cm.popretz and li a0,0 insn is deleted. Insertion of the generated epilogue sequence into the insn chain doesn't happen at this moment. If later shrink-wrap decides NOT to insert the epilogue sequence at the end of insn chain, then the li a0,0 insn has already been mistakeny removed. Fix this issue by removing generation of cm.popretz in epilogue, leaving the assignment to a0 and use insn with cm.popret. That's likely going to result in some kind of code size regression, but not a correctness regression. Optimization can be done in future. Signed-off-by: Fei Gao gcc/ChangeLog: PR target/113715 * config/riscv/riscv.cc (riscv_zcmp_can_use_popretz): Removed. (riscv_gen_multi_pop_insn): Remove generation of cm.popretz. gcc/testsuite/ChangeLog: * gcc.target/riscv/rv32e_zcmp.c: Adapt TC. * gcc.target/riscv/rv32i_zcmp.c: Likewise. --- gcc/config/riscv/riscv.cc | 53 --------------------- gcc/testsuite/gcc.target/riscv/rv32e_zcmp.c | 3 +- gcc/testsuite/gcc.target/riscv/rv32i_zcmp.c | 3 +- 3 files changed, 4 insertions(+), 55 deletions(-) diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index 6fcb6fb4ad3..a599ced658c 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -7761,52 +7761,6 @@ riscv_adjust_libcall_cfi_epilogue () return dwarf; } -/* return true if popretz pattern can be matched. - set (reg 10 a0) (const_int 0) - use (reg 10 a0) - NOTE_INSN_EPILOGUE_BEG */ -static rtx_insn * -riscv_zcmp_can_use_popretz (void) -{ - rtx_insn *insn = NULL, *use = NULL, *clear = NULL; - - /* sequence stack for NOTE_INSN_EPILOGUE_BEG*/ - struct sequence_stack *outer_seq = get_current_sequence ()->next; - if (!outer_seq) - return NULL; - insn = outer_seq->first; - if (!insn || !NOTE_P (insn) || NOTE_KIND (insn) != NOTE_INSN_EPILOGUE_BEG) - return NULL; - - /* sequence stack for the insn before NOTE_INSN_EPILOGUE_BEG*/ - outer_seq = outer_seq->next; - if (outer_seq) - insn = outer_seq->last; - - /* skip notes */ - while (insn && NOTE_P (insn)) - { - insn = PREV_INSN (insn); - } - use = insn; - - /* match use (reg 10 a0) */ - if (use == NULL || !INSN_P (use) || GET_CODE (PATTERN (use)) != USE - || !REG_P (XEXP (PATTERN (use), 0)) - || REGNO (XEXP (PATTERN (use), 0)) != A0_REGNUM) - return NULL; - - /* match set (reg 10 a0) (const_int 0 [0]) */ - clear = PREV_INSN (use); - if (clear != NULL && INSN_P (clear) && GET_CODE (PATTERN (clear)) == SET - && REG_P (SET_DEST (PATTERN (clear))) - && REGNO (SET_DEST (PATTERN (clear))) == A0_REGNUM - && SET_SRC (PATTERN (clear)) == const0_rtx) - return clear; - - return NULL; -} - static void riscv_gen_multi_pop_insn (bool use_multi_pop_normal, unsigned mask, unsigned multipop_size) @@ -7817,13 +7771,6 @@ riscv_gen_multi_pop_insn (bool use_multi_pop_normal, unsigned mask, if (!use_multi_pop_normal) insn = emit_insn ( riscv_gen_multi_push_pop_insn (POP_IDX, multipop_size, regs_count)); - else if (rtx_insn *clear_a0_insn = riscv_zcmp_can_use_popretz ()) - { - delete_insn (NEXT_INSN (clear_a0_insn)); - delete_insn (clear_a0_insn); - insn = emit_jump_insn ( - riscv_gen_multi_push_pop_insn (POPRETZ_IDX, multipop_size, regs_count)); - } else insn = emit_jump_insn ( riscv_gen_multi_push_pop_insn (POPRET_IDX, multipop_size, regs_count)); diff --git a/gcc/testsuite/gcc.target/riscv/rv32e_zcmp.c b/gcc/testsuite/gcc.target/riscv/rv32e_zcmp.c index 50e443573ad..0af4d7199f6 100644 --- a/gcc/testsuite/gcc.target/riscv/rv32e_zcmp.c +++ b/gcc/testsuite/gcc.target/riscv/rv32e_zcmp.c @@ -259,7 +259,8 @@ foo (void) **test_popretz: ** cm.push {ra}, -16 ** call f1 -** cm.popretz {ra}, 16 +** li a0,0 +** cm.popret {ra}, 16 */ long test_popretz () diff --git a/gcc/testsuite/gcc.target/riscv/rv32i_zcmp.c b/gcc/testsuite/gcc.target/riscv/rv32i_zcmp.c index 1e1a8be8705..723889f49df 100644 --- a/gcc/testsuite/gcc.target/riscv/rv32i_zcmp.c +++ b/gcc/testsuite/gcc.target/riscv/rv32i_zcmp.c @@ -259,7 +259,8 @@ foo (void) **test_popretz: ** cm.push {ra}, -16 ** call f1 -** cm.popretz {ra}, 16 +** li a0,0 +** cm.popret {ra}, 16 */ long test_popretz ()