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 01356384B83F for ; Thu, 27 Oct 2022 15:10:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 01356384B83F 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.5/8.17.1.5) with ESMTP id 29REgrYC025163 for ; Thu, 27 Oct 2022 08:10:47 -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-type; s=pfpt0220; bh=z/0Lvhyp2IyWyVz6Gpp2c53/DN+65jj0acKrgKYn+nY=; b=ABKh38V+CwuKSVVrF+ykXm1NRFbPZ30OAyFi0fPqgQt+iwD88XDYHF0rlccET5HCq+sf zTVRXhSgsVpxLqJrv7F/preSOTs3Hz8wfn2WxkO7ZMESaezYubqRHGOOVbIVdNKaOqmp W12PnNHowPIXPjBM2gAJz9nW3HqIVz9H7b3Q4O0H1HBMInfB5Xn6WgNMoaTP8u52WPfF aK3m289Lptnrs2UMehlqBuIujgK6LsI19cqkCwO2+raVioHQU0qLw44FdeCefc9T4lvq CsLlSwIO1pbqHA8LCwUrLeUfd2/B6h2Az46EJh+jptqjz8rmuFmRhIfhftxRi92rj93t cw== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3kfv03g4dn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Thu, 27 Oct 2022 08:10:47 -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.2; Thu, 27 Oct 2022 08:10:46 -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.18 via Frontend Transport; Thu, 27 Oct 2022 08:10:46 -0700 Received: from linux.marvell.com (unknown [10.69.242.198]) by maili.marvell.com (Postfix) with ESMTP id DC4F83F7058; Thu, 27 Oct 2022 08:10:45 -0700 (PDT) From: To: CC: Andrew Pinski Subject: [PATCH] Use simple_dce_from_worklist with match_simplify_replacement. Date: Thu, 27 Oct 2022 08:10:39 -0700 Message-ID: <1666883439-7725-1-git-send-email-apinski@marvell.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-GUID: BIE3yjLKlgbyBDiphWSPNdB-Qh495d60 X-Proofpoint-ORIG-GUID: BIE3yjLKlgbyBDiphWSPNdB-Qh495d60 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-10-27_07,2022-10-27_01,2022-06-22_01 X-Spam-Status: No, score=-14.7 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 List-Id: From: Andrew Pinski This is a simple patch to do some DCE after a successful match and simplify replacement in PHI-OPT. match and simplify likes to generate some extra statements which should be cleaned up. OK? Bootstrapped and tested on x86_64-linux with no regressions. Thanks, Andrew Pinski gcc/ChangeLog: * tree-ssa-phiopt.cc: Include tree-ssa-dce.h (replace_phi_edge_with_variable): New argument, dce_ssa_names. Call simple_dce_from_worklist. (match_simplify_replacement): If we inserted a sequence, mark the lhs of the new sequence to be possible dce. Always move the statement and mark the lhs (if it is a name) as possible to remove. --- gcc/tree-ssa-phiopt.cc | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc index 925bd7d..996700b 100644 --- a/gcc/tree-ssa-phiopt.cc +++ b/gcc/tree-ssa-phiopt.cc @@ -53,6 +53,7 @@ along with GCC; see the file COPYING3. If not see #include "gimple-match.h" #include "dbgcnt.h" #include "tree-ssa-propagate.h" +#include "tree-ssa-dce.h" static unsigned int tree_ssa_phiopt_worker (bool, bool, bool); static bool two_value_replacement (basic_block, basic_block, edge, gphi *, @@ -74,7 +75,6 @@ static bool cond_store_replacement (basic_block, basic_block, edge, edge, hash_set *); static bool cond_if_else_store_replacement (basic_block, basic_block, basic_block); static hash_set * get_non_trapping (); -static void replace_phi_edge_with_variable (basic_block, edge, gphi *, tree); static void hoist_adjacent_loads (basic_block, basic_block, basic_block, basic_block); static bool gate_hoist_loads (void); @@ -402,7 +402,8 @@ tree_ssa_phiopt_worker (bool do_store_elim, bool do_hoist_loads, bool early_p) static void replace_phi_edge_with_variable (basic_block cond_block, - edge e, gphi *phi, tree new_tree) + edge e, gphi *phi, tree new_tree, + bitmap dce_ssa_names = auto_bitmap()) { basic_block bb = gimple_bb (phi); gimple_stmt_iterator gsi; @@ -477,6 +478,8 @@ replace_phi_edge_with_variable (basic_block cond_block, gimple_cond_make_true (cond); } + simple_dce_from_worklist (dce_ssa_names); + statistics_counter_event (cfun, "Replace PHI with variable", 1); if (dump_file && (dump_flags & TDF_DETAILS)) @@ -986,6 +989,7 @@ match_simplify_replacement (basic_block cond_bb, basic_block middle_bb, gimple_seq seq = NULL; tree result; gimple *stmt_to_move = NULL; + auto_bitmap inserted_exprs; /* Special case A ? B : B as this will always simplify to B. */ if (operand_equal_for_phi_arg_p (arg0, arg1)) @@ -1060,14 +1064,22 @@ match_simplify_replacement (basic_block cond_bb, basic_block middle_bb, gsi = gsi_last_bb (cond_bb); /* Insert the sequence generated from gimple_simplify_phiopt. */ if (seq) + { + // Mark the lhs of the new statements maybe for dce + gimple_stmt_iterator gsi1 = gsi_start (seq); + for (; !gsi_end_p (gsi1); gsi_next (&gsi1)) + { + gimple *stmt = gsi_stmt (gsi1); + tree name = gimple_get_lhs (stmt); + if (name && TREE_CODE (name) == SSA_NAME) + bitmap_set_bit (inserted_exprs, SSA_NAME_VERSION (name)); + } gsi_insert_seq_before (&gsi, seq, GSI_CONTINUE_LINKING); + } - /* If there was a statement to move and the result of the statement - is going to be used, move it to right before the original - conditional. */ - if (stmt_to_move - && (gimple_assign_lhs (stmt_to_move) == result - || !has_single_use (gimple_assign_lhs (stmt_to_move)))) + /* If there was a statement to move, move it to right before + the original conditional. */ + if (stmt_to_move) { if (dump_file && (dump_flags & TDF_DETAILS)) { @@ -1075,12 +1087,17 @@ match_simplify_replacement (basic_block cond_bb, basic_block middle_bb, print_gimple_stmt (dump_file, stmt_to_move, 0, TDF_VOPS|TDF_MEMSYMS); } + + tree name = gimple_get_lhs (stmt_to_move); + // Mark the name to be renamed if there is one. + if (name && TREE_CODE (name) == SSA_NAME) + bitmap_set_bit (inserted_exprs, SSA_NAME_VERSION (name)); gimple_stmt_iterator gsi1 = gsi_for_stmt (stmt_to_move); gsi_move_before (&gsi1, &gsi); reset_flow_sensitive_info (gimple_assign_lhs (stmt_to_move)); } - replace_phi_edge_with_variable (cond_bb, e1, phi, result); + replace_phi_edge_with_variable (cond_bb, e1, phi, result, inserted_exprs); /* Add Statistic here even though replace_phi_edge_with_variable already does it as we want to be able to count when match-simplify happens vs -- 1.8.3.1