From patchwork Mon Aug 7 12:22:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 131909 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp1412700vqr; Mon, 7 Aug 2023 05:30:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHz2OyJsRauoU8w/Zl25VmIgVayx/l5exSwrceu9hddaZ4H8iDcwWoa6xQmYUL3w0OJi+K1 X-Received: by 2002:a17:906:1ba9:b0:99c:ae06:ffe4 with SMTP id r9-20020a1709061ba900b0099cae06ffe4mr5871071ejg.32.1691411439179; Mon, 07 Aug 2023 05:30:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691411439; cv=none; d=google.com; s=arc-20160816; b=S0vQUBc34gzXkLdm0W+GTawrwibVNalvC1IAmsJlFG6El+PFwDoxeSVGjGYU3QiqrD y8jxLojnZw6Hm250yAZgB2vATYIIQNtfvRwso3XBO4yCHd7MD0H76fpDTKHWZb6jUTWF YBAsvRInO8ywcfsbWvMPqcnw8IQIidyTHvz4jU/8yMyfQJg6ndDvxemJRN6HIs+DTjrL etfcY2YwahLJ1QCQj9NQZvFylUJmSPqblEkpSsLcmLOdL50yk7BBKka9vvIN98qSAk3O DWpukEBbzjvJEFbAWqMPwoQ6206l8ks0q1OjhyGV4fjlV2ZAbJsUXhGUQZmff1cG+zub Jedg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=iSqQK/1gt+WuW8uTMOkEXBzpVyQrgK1vD9Mlqxw+g7A=; fh=e3qckc+Yoo2IRFrgNi2OpdfwrygbVRbDMAYzNjKeDgQ=; b=ig929raik3wZM8u7pmo4RV/CTBRalo412cpjJB4qiJYK+xE35ZAHhSwEsNHarR0q3j A5vDpLIj0ZTLaqAp5keoqSIvW//BJU/QqthnRq3F3dthKhtqrOEGb2OKrnbNRFhYBDJb BNFs4GsIzTP7MPetGkXFgG4aXuojDy3xYBL/dRiwwxkaC7wT/ml1BRyL++DY2HqXAs2s vlVThbui1d3y7YVzWP2IE30S3aahHNGRCrEJSC8ZJZ4dsb8zVbWXkd0XkQXzI+XkZuZc IsxXV7lf2zCca3WdMxO1yYhL1rCyHLmU+HuECZHXKnwjE5dX6fdBYczjjuTcPAY18DoN nOSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=gwPwuEle; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id bu8-20020a170906a14800b00987d26a0998si631824ejb.455.2023.08.07.05.30.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 05:30:39 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=gwPwuEle; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5DA04385DC02 for ; Mon, 7 Aug 2023 12:23:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5DA04385DC02 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1691411019; bh=iSqQK/1gt+WuW8uTMOkEXBzpVyQrgK1vD9Mlqxw+g7A=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=gwPwuElea6QRNUIRiouviXkrIS2scPMr1EEujVcHoFgBLhmiK/Cm4rmWG8NKkZx5a ZaQGM5kSpsyjLeB8z5EOPNosiberGstKytkW+zcoCJJDEh4U13fptBJJVikX2G8bqo Jf6p6prU3dEoRwlXgUK537SgGM4i96i68BelHUEY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.115]) by sourceware.org (Postfix) with ESMTPS id 70D983858280 for ; Mon, 7 Aug 2023 12:22:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 70D983858280 X-IronPort-AV: E=McAfee;i="6600,9927,10794"; a="370530625" X-IronPort-AV: E=Sophos;i="6.01,262,1684825200"; d="scan'208";a="370530625" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Aug 2023 05:22:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10794"; a="820980351" X-IronPort-AV: E=Sophos;i="6.01,262,1684825200"; d="scan'208";a="820980351" Received: from shvmail03.sh.intel.com ([10.239.245.20]) by FMSMGA003.fm.intel.com with ESMTP; 07 Aug 2023 05:22:49 -0700 Received: from pli-ubuntu.sh.intel.com (pli-ubuntu.sh.intel.com [10.239.159.47]) by shvmail03.sh.intel.com (Postfix) with ESMTP id 0A98010079B2; Mon, 7 Aug 2023 20:22:49 +0800 (CST) To: gcc-patches@gcc.gnu.org Cc: juzhe.zhong@rivai.ai, kito.cheng@sifive.com, pan2.li@intel.com, yanzhang.wang@intel.com, jeffreyalaw@gmail.com Subject: [PATCH v1] Mode-Switching: Fix SET_SRC ICE when only one operand Date: Mon, 7 Aug 2023 20:22:47 +0800 Message-Id: <20230807122247.1881775-1-pan2.li@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Pan Li via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: pan2.li@intel.com Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773573441306925913 X-GMAIL-MSGID: 1773573441306925913 From: Pan Li In same cases, like gcc/testsuite/gcc.dg/pr78148.c in RISC-V, there will be only 1 operand when SET_SRC in create_pre_exit. For example as below. (insn 13 9 14 2 (clobber (reg/i:TI 10 a0)) "gcc/testsuite/gcc.dg/pr78148.c":24:1 -1 (expr_list:REG_UNUSED (reg/i:TI 10 a0) (nil))) Unfortunately, SET_SRC requires at least 2 operands and then Segment Fault here. This patch would like to fix this ICE by adding operand length check before SET_SRC. Signed-off-by: Pan Li gcc/ChangeLog: * mode-switching.cc (create_pre_exit): Add operand length check. gcc/testsuite/ChangeLog: * gcc.target/riscv/mode-switch-ice-1.c: New test. --- gcc/mode-switching.cc | 2 ++ .../gcc.target/riscv/mode-switch-ice-1.c | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 gcc/testsuite/gcc.target/riscv/mode-switch-ice-1.c diff --git a/gcc/mode-switching.cc b/gcc/mode-switching.cc index 64ae2bc29c3..cbf03c02159 100644 --- a/gcc/mode-switching.cc +++ b/gcc/mode-switching.cc @@ -411,6 +411,8 @@ create_pre_exit (int n_entities, int *entity_map, const int *num_modes) conflict with address reloads. */ if (copy_start >= ret_start && copy_start + copy_num <= ret_end + && GET_RTX_LENGTH (GET_CODE (return_copy_pat)) >= 2 + /* SET_SRC requires at least 2 operands. */ && OBJECT_P (SET_SRC (return_copy_pat))) forced_late_switch = true; break; diff --git a/gcc/testsuite/gcc.target/riscv/mode-switch-ice-1.c b/gcc/testsuite/gcc.target/riscv/mode-switch-ice-1.c new file mode 100644 index 00000000000..1b34a471904 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/mode-switch-ice-1.c @@ -0,0 +1,22 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +struct A { char e, f; }; + +struct B +{ + int g; + struct A h[4]; +}; + +extern void bar (int, int); + +struct B foo (void) +{ + bar (2, 1); +} + +void baz () +{ + foo (); +}