From patchwork Thu May 11 15:17:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 92694 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp4456789vqo; Thu, 11 May 2023 08:18:17 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6FRRO2QW9WEICFcztjbqw8kMv+mTDQ43iU/Wydfl7f6x4ahuVwcBrIHZkOSlPhLdmNNDx6 X-Received: by 2002:a17:907:9444:b0:966:5730:c3fe with SMTP id dl4-20020a170907944400b009665730c3femr16366291ejc.52.1683818297820; Thu, 11 May 2023 08:18:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683818297; cv=none; d=google.com; s=arc-20160816; b=MwfZr57GHSLMNc9c3jEGjyAD7WnpaPkrk5GK2nDfkFeSSBcZ1GsCdmGoAIB/jUNSA7 SxVkltmyzxVM4MF22fESLkaMA+gyddRMNzOno8AGBmbHRCGjDcq5qVw6S3bTW+jt8eGN 1MGBJV+RyV18dsp2TzzzCD0dgNnHuFmiQ7Y9TJSMLXBmlIhlCIvMv8nybch4v4MWeXHg 1uIQueSZcdCUBpOV86YF1LDr7Bk50bmgSGzW7ur+LJEH9BGmx9zwemSZcslQBCci0/Lx QKS4bfjGnYeTTxsWa5F+ayWq9wl5K1Fvcf6q0Q0ogYts3QYFx/44DJ5IwAKKDzputDwf ZghA== 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=lQYOrG8ouQm542+7SjHPaYeYyOjvHgYPgkLQeBlkRUM=; b=napsKIx8HzxjPfrWmj6uDE2OuI8AFKgyhBevGhBrsij1bq5dTEKVkEkPMscZXbbwuk Kq/VdzvUL+IFMp0+5rYbtu9jCjM09VLXizubJiAwSCSmEJydVIXGhF87QD9dimoMmQ9w Hc4hFifCDiRn0vee2OYpyRbM+x/rFL8BhdCTl0x7dAnPjgBL/66O+zFVkhOnsChAilOJ KEl34ut8jCCYME05YCxnAgTqErQ4hmu7bVMdMyR6tIlTwpzL2GDt9i0Qq+52sq5sHb5q Ov0/Wi9OxTBA4ZwU2eKJCw4ro6u+svrP7zoSthwoQ2+9HaztkKQj/l7iPyDarg8CDyU9 jNRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="pUsVyP//"; 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 a1-20020a1709064a4100b00965ad3a1932si5509557ejv.282.2023.05.11.08.18.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 May 2023 08:18:17 -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="pUsVyP//"; 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 B8CCF3858434 for ; Thu, 11 May 2023 15:18:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B8CCF3858434 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683818296; bh=lQYOrG8ouQm542+7SjHPaYeYyOjvHgYPgkLQeBlkRUM=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=pUsVyP//aQmcNZprL2sx+Udt1euPBg17YN4UU1D4KnEfXGV+7OW/K3Ze2YEE9AtJ5 1goKQtZfDUe3UM15PQx5/foGN0SW4xQqXH042EYNBrOCeO/Wz6nharWdvCYA+YaCPg HHpow9OuDzf9DlkxmRsaupfVcy1hU3emo2j/CVys= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by sourceware.org (Postfix) with ESMTPS id 3E8843858C54 for ; Thu, 11 May 2023 15:17:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3E8843858C54 Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34B9sSD6020418 for ; Thu, 11 May 2023 08:17:31 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3qgx549ad3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Thu, 11 May 2023 08:17:29 -0700 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.48; Thu, 11 May 2023 08:17:28 -0700 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.48 via Frontend Transport; Thu, 11 May 2023 08:17:28 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 393783F704C; Thu, 11 May 2023 08:17:28 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH] Improve simple_dce for phis that only used in itself Date: Thu, 11 May 2023 08:17:19 -0700 Message-ID: <20230511151719.1394582-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: ELH6kn2TzN2apTamESxhR2BI3wpOa4Do X-Proofpoint-GUID: ELH6kn2TzN2apTamESxhR2BI3wpOa4Do 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-05-11_12,2023-05-05_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, 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: , 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?1765611455482895131?= X-GMAIL-MSGID: =?utf-8?q?1765611455482895131?= While I was looking at differences before and after r14-569-g21e2ef2dc25de3, I noticed that one phi node was not being removed. For an example, while compiling combine.cc, in expand_field_assignment, we would remove `# pos_51 = PHI ` but we don't any more since pos_51 has more than zero users but in this case it is only itself. This patch improves simple_dce_from_worklist to detect that case and now we able to remove this phi statement again. OK? Bootstrapped and tested on x86_64-linux-gnu. gcc/ChangeLog: * tree-ssa-dce.cc (simple_dce_from_worklist): For ssa names defined by a phi node with more than one uses, allow for the only uses are in that same defining statement. --- gcc/tree-ssa-dce.cc | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/gcc/tree-ssa-dce.cc b/gcc/tree-ssa-dce.cc index 6554b5db03e..045c64a9c02 100644 --- a/gcc/tree-ssa-dce.cc +++ b/gcc/tree-ssa-dce.cc @@ -2107,9 +2107,36 @@ simple_dce_from_worklist (bitmap worklist, bitmap need_eh_cleanup) unsigned i = bitmap_clear_first_set_bit (worklist); tree def = ssa_name (i); - /* Removed by somebody else or still in use. */ + /* Removed by somebody else or still in use. + Note use in itself for a phi node is not counted as still in use. */ if (! def || ! has_zero_uses (def)) - continue; + { + + if (!def) + continue; + + gimple *def_stmt = SSA_NAME_DEF_STMT (def); + if (gimple_code (def_stmt) != GIMPLE_PHI) + continue; + + gimple *use_stmt; + imm_use_iterator use_iter; + bool canremove = true; + + FOR_EACH_IMM_USE_STMT (use_stmt, use_iter, def) + { + /* Ignore debug statements. */ + if (is_gimple_debug (use_stmt)) + continue; + if (use_stmt != def_stmt) + { + canremove = false; + break; + } + } + if (!canremove) + continue; + } gimple *t = SSA_NAME_DEF_STMT (def); if (gimple_has_side_effects (t))