From patchwork Fri Mar 10 21:53:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 67741 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1116958wrd; Fri, 10 Mar 2023 13:55:04 -0800 (PST) X-Google-Smtp-Source: AK7set9AwPJUCcqfc2XvJyVxL26VB0nTiB5yrogDtuQYq8a9nIyGaQPwJUFfnUEdaUAykkj12iGT X-Received: by 2002:aa7:d546:0:b0:4a2:5652:d8ba with SMTP id u6-20020aa7d546000000b004a25652d8bamr3728756edr.18.1678485304683; Fri, 10 Mar 2023 13:55:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678485304; cv=none; d=google.com; s=arc-20160816; b=tHTtQ81C7ebPBeyk/Shpt/emdjWzJK6dg16HUldofXaVs4ssxcFOEAOOZpW20gBC0v AY5FqRC7uD1Wg+gBgzN9JSqE1622DrnpbFkS4bnoWZcs0MAfZFL1KT40Ew4NvBj1Q+Sc zmm1rdA36Vvn+HecVHV6RENsr1DAobJ8hpQ3xQnvgNBrZoYZG7mReUqq2XtuW7MAertZ nfRZ0hprwfVo5srK6Qt3eGqZt76vY7xpZIkBrY2BivHXi7zmVY7zR9slP5VBoPsV/WSU ouF+rSkjZJrWwBND/J7p99UYCdP7z+zh2KYsJGlRHdmFmIgG5lAubWWON/eFdNynWIUI cHcg== 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=lqgHEYVRZTUumABciYHjEsoLvD5UvhZzWii9cw/TTFI=; b=f1U8NfCE2JQ5h2GUaZShHtwmPJB0HeI9UVaSWYHBC6rPpwRH1FzECU43V9Jxp/LU4b syD7xfhS4wEjqke08AesF6Y5S/VVYZQ2aI3DBUMaiBm/rgHfxRHkMIvzq+lrFWVJuz+k K7OZvlrMLBmME+bkgVholnzUxREutgi9ksKVJalVGqOG6aoqZc6pC+iE6JbZeBE4+Tb6 39nig2RT44CF7i+K7rajuKhWKTOHa2NWiOanEWlVbPtj6tzrqZDQc59SuFC/255W4cdP lXIwUevtijTQxUeDdZuKvkmk3CXPtGNF0UPhDk2EbGm6AYvNDc5LpfMH5+k4uU/vzP1h EPDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=tsyDY29s; 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 sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id qo15-20020a170907212f00b0091eee97c8e4si612332ejb.862.2023.03.10.13.55.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Mar 2023 13:55:04 -0800 (PST) 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=tsyDY29s; 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 B3B0D3858407 for ; Fri, 10 Mar 2023 21:55:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B3B0D3858407 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678485303; bh=lqgHEYVRZTUumABciYHjEsoLvD5UvhZzWii9cw/TTFI=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=tsyDY29s1/mCC19ud85eBuTLt4w3qjTybMJpCsoQwFgK0K3tD5eSVZu6ch3lnEeUN MWSZoDjMryd/AQOuWGlDVufJgQS98HGZ64s3apFnoz5fyyUfAnYOcLXifhzxuS72JQ aU+kH063iiOHnxiYe0/pY1ZbzESFwV1MBraYCdDo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by sourceware.org (Postfix) with ESMTPS id 111813858D1E for ; Fri, 10 Mar 2023 21:54:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 111813858D1E Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32ALg0iM018218; Fri, 10 Mar 2023 13:54:18 -0800 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3p80k7bv3r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Fri, 10 Mar 2023 13:54:16 -0800 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Fri, 10 Mar 2023 13:54:01 -0800 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.42 via Frontend Transport; Fri, 10 Mar 2023 13:54:01 -0800 Received: from vpnclient.wrightpinski.org.com (unknown [10.76.242.80]) by maili.marvell.com (Postfix) with ESMTP id 785943F708D; Fri, 10 Mar 2023 13:54:00 -0800 (PST) To: CC: Andrew Pinski , Andrew Macleod Subject: [COMMITTED/12] tree-optimization: [PR108684] ICE in verify_ssa due to simple_dce_from_worklist Date: Fri, 10 Mar 2023 13:53:51 -0800 Message-ID: <20230310215351.2943914-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-GUID: pMykEt77da75m3YvMrInoX20hRqM3Imj X-Proofpoint-ORIG-GUID: pMykEt77da75m3YvMrInoX20hRqM3Imj X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-10_10,2023-03-10_01,2023-02-09_01 X-Spam-Status: No, score=-14.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, 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: Andrew Pinski via Gcc-patches From: Andrew Pinski Reply-To: Andrew Pinski 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?1760019406919293016?= X-GMAIL-MSGID: =?utf-8?q?1760019406919293016?= In simple_dce_from_worklist, we were removing an inline-asm which had a vdef. We should not be removing inline-asm which have a vdef as this code does not check to the store. This fixes that oversight. This was a latent bug exposed recently by both VRP and removal of stores to static starting to use simple_dce_from_worklist. Backported after bootstrapped and tested on x86_64-linux-gnu with no regressions. PR tree-optimization/108684 gcc/ChangeLog: * tree-ssa-dce.cc (simple_dce_from_worklist): Check all ssa names and not just non-vdef ones before accepting the inline-asm. Call unlink_stmt_vdef on the statement before removing it. gcc/testsuite/ChangeLog: * gcc.c-torture/compile/dce-inline-asm-1.c: New test. * gcc.c-torture/compile/dce-inline-asm-2.c: New test. * gcc.dg/tree-ssa/pr108684-1.c: New test. co-authored-by: Andrew Macleod (cherry picked from commit 6a5cb782d1486b378d70857c8efae558da0eb2cc) --- .../gcc.c-torture/compile/dce-inline-asm-1.c | 15 +++++++++++++++ .../gcc.c-torture/compile/dce-inline-asm-2.c | 16 ++++++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/pr108684-1.c | 18 ++++++++++++++++++ gcc/tree-ssa-dce.cc | 5 +++-- 4 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/compile/dce-inline-asm-1.c create mode 100644 gcc/testsuite/gcc.c-torture/compile/dce-inline-asm-2.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr108684-1.c diff --git a/gcc/testsuite/gcc.c-torture/compile/dce-inline-asm-1.c b/gcc/testsuite/gcc.c-torture/compile/dce-inline-asm-1.c new file mode 100644 index 00000000000..a9f02e44bd7 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/dce-inline-asm-1.c @@ -0,0 +1,15 @@ +/* PR tree-optimization/108684 */ +/* This used to ICE as when we remove the store to + `t`, we also would remove the inline-asm which + had a VDEF on it but we didn't update the + VUSE that was later on. */ +static int t; + +int f (int *a) +{ + int t1; + asm (" " : "=X" (t1) : : "memory"); + t = t1; + return *a; +} + diff --git a/gcc/testsuite/gcc.c-torture/compile/dce-inline-asm-2.c b/gcc/testsuite/gcc.c-torture/compile/dce-inline-asm-2.c new file mode 100644 index 00000000000..a41b16e4bd0 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/dce-inline-asm-2.c @@ -0,0 +1,16 @@ +/* PR tree-optimization/108684 */ +/* This used to ICE as when we removed the + __builtin_unreachable in VRP, as we + would also remove the branch and the + inline-asm. The inline-asm had a VDEF on it, + which we didn't update further along and + not have the VDEF on the return statement + updated. */ + +int f (int a) +{ + asm (" " : "=X" (a) : : "memory"); + if (a) + return 0; + __builtin_unreachable(); +} diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr108684-1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr108684-1.c new file mode 100644 index 00000000000..3ba206f765e --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr108684-1.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + + +static int t; + +int f (int *a) +{ + int t1, t2 = 0; + asm ("shouldshowupstill %1" : "=r" (t1), "=m"(t2) : : ); + t = t1; + return t2; +} + +/* Check to make sure DCE does not remove the inline-asm as it writes to t2. */ +/* We used to DCE this inline-asm when removing the store to t. */ +/* { dg-final { scan-assembler "shouldshowupstill" } } */ +/* { dg-final { scan-tree-dump-times "shouldshowupstill" 1 "optimized" } } */ diff --git a/gcc/tree-ssa-dce.cc b/gcc/tree-ssa-dce.cc index 4b7b664867d..4fa830dffd3 100644 --- a/gcc/tree-ssa-dce.cc +++ b/gcc/tree-ssa-dce.cc @@ -2062,9 +2062,9 @@ simple_dce_from_worklist (bitmap worklist) /* The defining statement needs to be defining only this name. ASM is the only statement that can define more than one - (non-virtual) name. */ + name. */ if (is_a(t) - && !single_ssa_def_operand (t, SSA_OP_DEF)) + && !single_ssa_def_operand (t, SSA_OP_ALL_DEFS)) continue; /* Don't remove statements that are needed for non-call @@ -2094,6 +2094,7 @@ simple_dce_from_worklist (bitmap worklist) remove_phi_node (&gsi, true); else { + unlink_stmt_vdef (t); gsi_remove (&gsi, true); release_defs (t); }