From patchwork Tue Jun 20 09:40:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fei Gao X-Patchwork-Id: 110370 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3541866vqr; Tue, 20 Jun 2023 02:42:22 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7wmsYuPJZYHuKEXiYhYfwSt+7VhS5/oNK+UJYJsXZlp61/pNYF6Y1s9eD8DsjPS3far1rt X-Received: by 2002:a50:ef12:0:b0:51a:f6de:bb81 with SMTP id m18-20020a50ef12000000b0051af6debb81mr2693040eds.28.1687254142236; Tue, 20 Jun 2023 02:42:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687254142; cv=none; d=google.com; s=arc-20160816; b=of+b+iOxVRl7C80kwq7IcOmlbP2AqmhoInD0QcOEvJui/JyjF78LtOYKcXaN3uHIzD ApM+AUVK0OC38rI+D66QIuZZViBf+QB0Hl0xfiedbTJ60y62WwFkQT3tq0AKwaTiiIiC LoXJE2/awcoPNF8cTlg649KCJwyEOC0pnih0UaUfBwGkQLrvOiZF92rnTZ4Nj/qn1Eqt qTJFsBByJQtDMceFZdhV3yhzwRLCiZ4jLYgVesf5Ol+lYuAXyrnvygiZx58/1ENzw2mB FOPAYMFBrGsf7V3DP+4H8BXmNO7Zxa30w28+Pwt8g8palLiK/5+Yh6kCUOuZAj1DaX1j xbbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:cc:to:from:dmarc-filter:delivered-to; bh=DTfvS/XjQG9wIToFJYJsRb2GfjQMj7TI7Fi4VZ+Dlwk=; b=xX4almKGF2pzLVNSiTutDuocoOFd7T8W778brDh9nHBKOGf+d/fHK6uDO2olDS+75/ DbuLEq4WVKQulVzufFQSII1plwO00Kabd95i3JiHOGBayoRI28LhFwKAyC70mfhminoH PQ/NwKuLJd29eowWc3fYTa9CYw69Rb6a/duv+SJC/SY4IdINk49Z7VqBWBh3CwGaNVGD IbfXihyRBBGWXxUv9INfzQuuWJW8OprUWhdheuNHeau8ZOUdyHLZJzAXN2mQ+DxGBMCF C9uXhbIZjF9xAkMKa4iDU97S/o/n1cZpnDR7LY4Q041ZK86Ovadww+mQsivcTb3JyC4Q n6QQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id c6-20020aa7c986000000b0051a5954339csi926205edt.348.2023.06.20.02.42.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 02:42:22 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EC3B0385701B for ; Tue, 20 Jun 2023 09:41:41 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from zg8tmty3ljk5ljewns4xndka.icoremail.net (zg8tmty3ljk5ljewns4xndka.icoremail.net [167.99.105.149]) by sourceware.org (Postfix) with ESMTP id 9EBFF3858C41 for ; Tue, 20 Jun 2023 09:41:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9EBFF3858C41 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=eswincomputing.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=eswincomputing.com Received: from localhost.localdomain (unknown [10.12.130.31]) by app1 (Coremail) with SMTP id EwgMCgC3VMQxdJFkSnYoAA--.56000S6; Tue, 20 Jun 2023 17:41:10 +0800 (CST) From: Fei Gao To: gcc-patches@gcc.gnu.org Cc: kito.cheng@gmail.com, palmer@dabbelt.com, jeffreyalaw@gmail.com, sinan.lin@linux.alibaba.com, jiawei@iscas.ac.cn, Fei Gao Subject: [PATCH 2/2] [RISC-V] resolve confilct between zcmp multi push/pop and shrink-wrap-separate Date: Tue, 20 Jun 2023 09:40:52 +0000 Message-Id: <20230620094052.35993-3-gaofei@eswincomputing.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230620094052.35993-1-gaofei@eswincomputing.com> References: <20230620094052.35993-1-gaofei@eswincomputing.com> X-CM-TRANSID: EwgMCgC3VMQxdJFkSnYoAA--.56000S6 X-Coremail-Antispam: 1UD129KBjvJXoWxAF48GF1ftw4rJr4UWr17Jrb_yoWrGr18pF W5ZFW5urZ5ZrnavrZ7tr18XF1rGws3KF43Jry3Z3y8Aan8X3WfKrZ7Ka4YvF45GFykXFnF 9FZxCr1akw45A37anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUB214x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jryl82xGYIkIc2 x26xkF7I0E14v26r4j6ryUM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0 Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY02Avz4vE-syl42xK82IYc2 Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s02 6x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0x vE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE 42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6x kF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjfU8BMNUUUUU X-CM-SenderInfo: xjdrwv3l6h245lqf0zpsxwx03jof0z/ X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H2, 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: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769214199646016494?= X-GMAIL-MSGID: =?utf-8?q?1769214199646016494?= Disable zcmp multi push/pop if shrink-wrap-separate is active. So in -Os that prefers smaller code size, by default shrink-wrap-separate is disabled while zcmp multi push/pop is enabled. And in -O2 and others that prefers speed, by default shrink-wrap-separate is enabled while zcmp multi push/pop is disabled. To force enabling zcmp multi push/pop in this case, -fno-shrink-wrap-separate has to be explictly given. The following TC shows the issues in -O2 before this patch with both shrink-wrap-separate and zcmp multi push/pop active. 1. duplicated store of s regs. 2. cm.push pushes ra, s0-s11 in reverse order than what normal prologue does, causing stack corruption and failure to resotre s regs. TC: zcmp_shrink_wrap_separate.c included in this patch. output asm before this patch: calc_func: cm.push {ra, s0-s3}, -32 ... beq a5,zero,.L2 ... .L2: ... sw s1,20(sp) //issue here sw s3,12(sp) //issue here ... sw s2,16(sp) //issue here output asm after this patch: calc_func: addi sp,sp,-32 sw s0,24(sp) ... beq a5,zero,.L2 ... .L2: ... sw s1,20(sp) sw s3,12(sp) ... sw s2,16(sp) Signed-off-by: Fei Gao Co-Authored-By: Zhangjin Liao gcc/ChangeLog: * config/riscv/riscv.cc (riscv_avoid_shrink_wrapping_separate): wrap the condition check in riscv_avoid_shrink_wrapping_separate. (riscv_avoid_multi_push): avoid multi push if shrink_wrapping_separate is active. (riscv_get_separate_components): call riscv_avoid_shrink_wrapping_separate --- gcc/config/riscv/riscv.cc | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index 26405b5978b..2cca5fbb62d 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -64,6 +64,7 @@ along with GCC; see the file COPYING3. If not see #include "cfghooks.h" #include "cfgloop.h" #include "cfgrtl.h" +#include "shrink-wrap.h" #include "sel-sched.h" #include "fold-const.h" #include "gimple-iterator.h" @@ -389,6 +390,7 @@ static const struct riscv_tune_param optimize_size_tune_info = { false, /* use_divmod_expansion */ }; +static bool riscv_avoid_shrink_wrapping_separate (); static tree riscv_handle_fndecl_attribute (tree *, tree, tree, int, bool *); static tree riscv_handle_type_attribute (tree *, tree, tree, int, bool *); @@ -5032,6 +5034,8 @@ riscv_avoid_multi_push(const struct riscv_frame_info *frame) || cfun->machine->interrupt_handler_p || cfun->machine->varargs_size != 0 || crtl->args.pretend_args_size != 0 + || (use_shrink_wrapping_separate () + && !riscv_avoid_shrink_wrapping_separate ()) || (frame->mask & ~ MULTI_PUSH_GPR_MASK)) return true; @@ -6199,6 +6203,17 @@ riscv_epilogue_uses (unsigned int regno) return false; } +static bool +riscv_avoid_shrink_wrapping_separate () +{ + if (riscv_use_save_libcall (&cfun->machine->frame) + || cfun->machine->interrupt_handler_p + || !cfun->machine->frame.gp_sp_offset.is_constant ()) + return true; + + return false; +} + /* Implement TARGET_SHRINK_WRAP_GET_SEPARATE_COMPONENTS. */ static sbitmap @@ -6208,9 +6223,7 @@ riscv_get_separate_components (void) sbitmap components = sbitmap_alloc (FIRST_PSEUDO_REGISTER); bitmap_clear (components); - if (riscv_use_save_libcall (&cfun->machine->frame) - || cfun->machine->interrupt_handler_p - || !cfun->machine->frame.gp_sp_offset.is_constant ()) + if (riscv_avoid_shrink_wrapping_separate ()) return components; offset = cfun->machine->frame.gp_sp_offset.to_constant ();