From patchwork Sat Jan 28 22:24:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 49915 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1520289wrn; Sat, 28 Jan 2023 14:25:29 -0800 (PST) X-Google-Smtp-Source: AK7set9s3BBClgJen476cCEprWZ8kGeXb489FYImiYimlerpzUzFah2BluIaDNHYedx1lU7Z524s X-Received: by 2002:a17:907:20b0:b0:87b:d376:b850 with SMTP id pw16-20020a17090720b000b0087bd376b850mr6665611ejb.10.1674944729862; Sat, 28 Jan 2023 14:25:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674944729; cv=none; d=google.com; s=arc-20160816; b=vaGUE3EWK1PU5sz9ZX2qTgORSWp3BiFYBLDElcmMiTxOu37xz5PnJkkUeiaR2W1jTt E83U6p6P2ZamxmhnSyOXyrs8N59X0QtDbam9FMFhgyWVj9BY2v0bmbhQvh38L43kqOV7 PcP+DcOSYgSUHfAvx31Kq2md0QyEAgZMbBoA6K0c4OLqWyovGmuhsA5/I1ApxbuC4vAk 8mpstZaRdwrg6LCxUhe74zfA0pY+zmZBhoNKgoG5n2k3LiFI7U8khRhJoWpYbPjX8Ddi X96vkbBJkaEgqRtV/EEIjGYmsviBBsM43VlHuLaqt7I4o4O/vclpQ9ZuN7dynys89aBE gJwg== 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=Fo5kTo1Ph81iECUtJOB8ihu0sDQVG+f/Clt+jhNxXY0=; b=axgQ+sg8IlxCvjZw7+UG8AdMAdBkkkBtayamzYJoG4qTndKjafkGQDBe1WVey71hY5 5fYHvWfEe5COWwVyRS/f1DM089DM0H34/IXXnU9BntBs20IpSc+mr7nVa5KZ7B+RBT1/ ECPKWKJaSOZ/VixLrg2yKi1nlYx+dVUo8F5W5gaJKr9Lc7bIRgda1QUcaVuwyaf8qbfI OAZbmu5JtccPcyp7dpACpvsOkfYEQINY0ALxFNq+u1BnNM90gY/cP7aKCPH+ywJ+XjOG wutwiP++N1n8tHNvKWpH6Xxh3Hx+QRVfNWBU/9LO4Muaw+FjroZFkD4+Lh3gF8cLjoAh ZMaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=kCTs2fEj; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id fw32-20020a170907502000b0086faeaaf796si9560760ejc.319.2023.01.28.14.25.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Jan 2023 14:25:29 -0800 (PST) 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; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=kCTs2fEj; 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"; 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 858663858D38 for ; Sat, 28 Jan 2023 22:25:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 858663858D38 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674944726; bh=Fo5kTo1Ph81iECUtJOB8ihu0sDQVG+f/Clt+jhNxXY0=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=kCTs2fEjdpWYOMweN3d9Lodix3/sm9Rmqv2zm/pJY8Gor1ttyjY3ni7XDN3iQhd3E drIiS2QtLfWNyyE4h2d1kBUN3M5ij5VVZ4awf+ibuNTd6ob+sAYKK8EUCg7FM2y46b Uy0P/jHkF7FI2FKq3WZ5hGIayhzuahqVRjVHzvqE= 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 7431E3858D20 for ; Sat, 28 Jan 2023 22:24:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7431E3858D20 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 30SLs3Mb005761 for ; Sat, 28 Jan 2023 14:24:41 -0800 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3nd4429rb2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sat, 28 Jan 2023 14:24:41 -0800 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Sat, 28 Jan 2023 14:24:33 -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; Sat, 28 Jan 2023 14:24:33 -0800 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.67]) by maili.marvell.com (Postfix) with ESMTP id 71EEB3F7099; Sat, 28 Jan 2023 14:24:33 -0800 (PST) To: CC: Andrew Pinski Subject: [PATCH] Fix PR 108582: ICE due to PHI-OPT removing a still in use ssa_name. Date: Sat, 28 Jan 2023 14:24:25 -0800 Message-ID: <20230128222425.1185711-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-GUID: lioO7mZF5vErw0_ODEOHbNee9dWGpT4A X-Proofpoint-ORIG-GUID: lioO7mZF5vErw0_ODEOHbNee9dWGpT4A X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-01-28_13,2023-01-27_01,2022-06-22_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?1756306845269309584?= X-GMAIL-MSGID: =?utf-8?q?1756306845269309584?= This patch adds a check in match_simplify_replacement to make sure the middlebb does not have any phi-nodes as we don't currently move those. This was just a thinko from before. Ok? Bootstrapped and tested on x86_64-linux-gnu with no regressions? PR tree-optimization/108582 gcc/ChangeLog: * tree-ssa-phiopt.cc (match_simplify_replacement): Add check for middlebb to have no phi nodes. gcc/testsuite/ChangeLog: * gcc.dg/pr108582-1.c: New test. --- gcc/testsuite/gcc.dg/pr108582-1.c | 58 +++++++++++++++++++++++++++++++ gcc/tree-ssa-phiopt.cc | 5 +++ 2 files changed, 63 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/pr108582-1.c diff --git a/gcc/testsuite/gcc.dg/pr108582-1.c b/gcc/testsuite/gcc.dg/pr108582-1.c new file mode 100644 index 00000000000..88c2de369ad --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr108582-1.c @@ -0,0 +1,58 @@ +/* { dg-do compile } */ +/* { dg-options "-O3 -fno-tree-ccp -fno-tree-dce" } */ + +/* + PHI-OPT via match_simplify_replacement used to transform: + if (_25 != 0) + goto ; [25.00%] + else + goto ; [75.00%] + + [local count: 11649864]: + # iftmp.5_13 = PHI <2(7)> + k_22 = k_11 | iftmp.5_13; + + [local count: 105655256]: + # g_9 = PHI <1(2), 0(8), g_8(7)> + # k_12 = PHI + +into: + + _15 = (int) _25; + _28 = -_15; + _4 = _13 & _28; + _6 = _4 | k_11; + + [local count: 105655256]: + # g_9 = PHI <1(2), g_8(7)> + # k_12 = PHI + +Removing the phi-node/assignment of _13. + + */ + +int a, c, d, e, f; +char b; +int main() { + int g = 1; + char h[1] = {0}; + while (a) { + if (f) { + b = 0; + if (d) + continue; + } + if (a < 1) { + g = 0; + goto L; + } + } + while (c) { + char *j = h; + int k; + L: + if (e && !g) + k |= 2 | (*j < 0); + } + return 0; +} diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc index c3a889dc593..a7ab6ce4ad9 100644 --- a/gcc/tree-ssa-phiopt.cc +++ b/gcc/tree-ssa-phiopt.cc @@ -1002,6 +1002,11 @@ match_simplify_replacement (basic_block cond_bb, basic_block middle_bb, if (!single_pred_p (middle_bb)) return false; + /* The middle bb cannot have phi nodes as we don't + move those assignments yet. */ + if (!gimple_seq_empty_p (phi_nodes (middle_bb))) + return false; + stmt_to_move = last_and_only_stmt (middle_bb); if (!stmt_to_move) return false;