From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1314) id C35DF384B808; Thu, 27 Oct 2022 18:37:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C35DF384B808 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666895874; bh=dUXqEWu6F677ncJiN6+B2MGjBEhAKLmpU5b2vUOFKMw=; h=From:To:Subject:Date:From; b=XsHzjh9xG+RyyxAVfwNxQX1An6DtV0Cyyf2+m+psuXRI1NK7YdpuKhLsjgm+MnusG jp+/wpqOwxd19sNNWHrRTUM6FYFMB5iWM95rNLIf34Kk9dk6d9V8TuO0KBXWscgFWv hW1V2e+lBHPjoX8e5kaT1uh9zrFQxDbpaEQdA9K4= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Andrew Pinski To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-3529] Use simple_dce_from_worklist with match_simplify_replacement. X-Act-Checkin: gcc X-Git-Author: Andrew Pinski X-Git-Refname: refs/heads/trunk X-Git-Oldrev: a33d623d2d3a78f5ef6f9e854946303e063eef63 X-Git-Newrev: 1c2b53ce8bbf5bbe1ddb13bb6005f432726518ae Message-Id: <20221027183754.C35DF384B808@sourceware.org> Date: Thu, 27 Oct 2022 18:37:54 +0000 (GMT) List-Id: https://gcc.gnu.org/g:1c2b53ce8bbf5bbe1ddb13bb6005f432726518ae commit r13-3529-g1c2b53ce8bbf5bbe1ddb13bb6005f432726518ae Author: Andrew Pinski Date: Thu Oct 27 04:37:01 2022 +0000 Use simple_dce_from_worklist with match_simplify_replacement. 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. Diff: --- 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 925bd7d8853..996700baaf3 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