From patchwork Fri Feb 10 01:43:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 55183 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp690527wrn; Thu, 9 Feb 2023 17:47:09 -0800 (PST) X-Google-Smtp-Source: AK7set+yMQgGcWQP3+dq3olQHHYkMPNpTsqa8G/tJXSe0uAD/lASaSnshKBfgt3M+u/OniQNpAgk X-Received: by 2002:a17:907:988e:b0:884:fdb:6c41 with SMTP id ja14-20020a170907988e00b008840fdb6c41mr15809631ejc.43.1675993629762; Thu, 09 Feb 2023 17:47:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675993629; cv=none; d=google.com; s=arc-20160816; b=ueUDjWAwNeTpNf3KaP4P3j+1HW5bk9jve6tPj9yc9LpwvAsiR8Mwanw6A3NwZ9H1eR zyfewTrUc6T5rsBZh7x7MXqkLfsS1/OO6JHV5BW1XKPCnlhQCTVKvRpEFazLKYL3SHA6 pUupuY/XrPMrYzyv/OsDK4Vhezy25iAyCPj4qi60eKW6f1OSeon5mF5VeYySOWKA0vIH LvufbdEAG2F2WGe7O1NeCLtAi8hXpKrT7YCbG5ekCly3BW94Vx5KKevVghjDythor/TD 9xiG+Y3m81EriA70p40GubD+l+7+7UHRNDnA3IchJy/sHhRL4wiosDxByyIFxDoJOYi9 loUA== 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=seNTOCmmvknvFg9gvtm8pX9GU3pJerbdxB4ZuSgJtvo=; b=xx3nVbD4YiHIy8qOWuqB17wXD7hU9B9N0f3HhaIDmo+myh/JWYTaBxsl7PQxCG5pXD sU43farp6roHNbPPHJCDzJmDCZ7NmJHmjHTMTIInyX3LFNLfPPYVc/RWL9+opVJ8WE0n fdBoXMLyftWw49NnIXti0iDrnDgQaegV1ly7WsCOYJrC4LsFGF67OoJcGRTinpNMNFnP 8hXmlgiu12eOd8uJcJxW7StYIE5a85qKBlqwMN5MIPuHGqbkzsDygbv+k8w1Th0GOCcv Sec8ZHPoj5+itTenJI02urgVmmaatmKyq49YumQwDaKK8rMgOy24Uhv4i354QCP8j3MW gvVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=o8L+Ess8; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id t26-20020a170906c39a00b007b889a69895si3584251ejz.589.2023.02.09.17.47.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Feb 2023 17:47:09 -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=o8L+Ess8; 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 B57953858428 for ; Fri, 10 Feb 2023 01:47:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B57953858428 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675993628; bh=seNTOCmmvknvFg9gvtm8pX9GU3pJerbdxB4ZuSgJtvo=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=o8L+Ess8yJawQLiUYY/ONz5tjAtbElm8w3SK7G1KQzFi/C3s07x35aK5gcP03Ljga kdi7GliXwyWov7df8iv9u1kDky25OI3FkoMjaersw6OdbJrKUEvhgmYm0WWmFH9XB1 9gRmQo4L2eAOP/5SFtqeyHuvYRy5JOi0fpByBBUw= 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 ECB3C3858C50 for ; Fri, 10 Feb 2023 01:46:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ECB3C3858C50 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 319JTSWc010916; Thu, 9 Feb 2023 17:46:22 -0800 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3nn71chqpj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Thu, 09 Feb 2023 17:46:21 -0800 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Thu, 9 Feb 2023 17:46:19 -0800 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.42 via Frontend Transport; Thu, 9 Feb 2023 17:46:19 -0800 Received: from vpnclient.wrightpinski.org.com (unknown [10.76.242.80]) by maili.marvell.com (Postfix) with ESMTP id 94C3F3F705A; Thu, 9 Feb 2023 17:46:17 -0800 (PST) To: CC: Andrew Pinski , Andrew Macleod Subject: [COMMITTED] tree-optimization: [PR108684] ICE in verify_ssa due to simple_dce_from_worklist Date: Thu, 9 Feb 2023 17:43:11 -0800 Message-ID: <20230210014311.1626049-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: j7t-3gZwhNqssVBABiVut7jmglvDPfU1 X-Proofpoint-GUID: j7t-3gZwhNqssVBABiVut7jmglvDPfU1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.170.22 definitions=2023-02-09_17,2023-02-09_03,2023-02-09_01 X-Spam-Status: No, score=-14.5 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?1757291410745422450?= X-GMAIL-MSGID: =?utf-8?q?1757406696787720518?= 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. Committed as approved. 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 --- .../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 b2fe9f4f55e..1f1ec2c8710 100644 --- a/gcc/tree-ssa-dce.cc +++ b/gcc/tree-ssa-dce.cc @@ -2108,9 +2108,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 @@ -2140,6 +2140,7 @@ simple_dce_from_worklist (bitmap worklist) remove_phi_node (&gsi, true); else { + unlink_stmt_vdef (t); gsi_remove (&gsi, true); release_defs (t); }