From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=marvell.com 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=lQYOrG8ouQm542+7SjHPaYeYyOjvHgYPgkLQeBlkRUM=; b=JuGcpliUBfvipN4vT4CvAYCIY/VJ03ADAQGpOMBmhDaSXV8C3/iR2QU018AdVVTc9qKM gfFQfwpZTAw3K7MQAvS8nP8Ek5cbTHBhwgdDJ9btSW38/4M/P7S550iGY+gcQYpIGUgX f11N1/Ijx9fa9OAqTxEV+ZExyb03PBKk4Nsl1j+dYt58TIn98GsLjCJ01F1R72h4rqmF OvZpFyI+emXkWg+/c1ROri6S2av0XtDSVmhu56G/iRakVlfD1DH8rFM71Q0x3a/Vd2mE N8bVavnUL51X1wv/GXnY2K1aFHpD6aNudTAGyBJ1JFzxNxpEF4HoR/A14/mrjBzZ8/Q4 gQ== 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) From: Andrew Pinski 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain 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 List-Id: 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)) -- 2.31.1