From: Andrew Pinski <apin...@marvell.com> Instead of putting a full blow DCE after execute_fixup_cfg, it makes sense to try to remove the defining statement for the store that is being removed. Right now we only handle PHI node statements as there needs no extra checks except for it is only used once in the store statement.
gcc/ChangeLog: * tree-cfg.c (maybe_remove_writeonly_store): Remove defining (PHI) statement of the store if possible. --- gcc/tree-cfg.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c index dbbf6beb6e4..d9efdc220ca 100644 --- a/gcc/tree-cfg.c +++ b/gcc/tree-cfg.c @@ -9692,6 +9692,41 @@ maybe_remove_writeonly_store (gimple_stmt_iterator &gsi, gimple *stmt) print_gimple_stmt (dump_file, stmt, 0, TDF_VOPS|TDF_MEMSYMS); } + + /* Remove the statement defining the rhs if it was only + used by this statement. */ + if (gimple_assign_single_p (stmt)) + { + tree rhs = gimple_assign_rhs1 (stmt); + gimple *use_stmt; + use_operand_p use_p; + gimple *stmt1; + + + if (TREE_CODE (rhs) == SSA_NAME + && single_imm_use (rhs, &use_p, &use_stmt) + && (stmt1 = SSA_NAME_DEF_STMT (rhs)) + /* For now only handle PHI nodes. + FIXME: this should handle more. */ + && gimple_code (stmt1) == GIMPLE_PHI) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + { + fprintf (dump_file, "Removing defining statement:\n"); + print_gimple_stmt (dump_file, stmt1, 0, + TDF_VOPS|TDF_MEMSYMS); + } + gimple_stmt_iterator gsi_for_def; + gsi_for_def = gsi_for_stmt (stmt1); + if (gimple_code (stmt1) == GIMPLE_PHI) + remove_phi_node (&gsi_for_def, true); + else + { + gsi_remove (&gsi_for_def, true); + release_defs (stmt1); + } + } + } unlink_stmt_vdef (stmt); gsi_remove (&gsi, true); release_defs (stmt); -- 2.17.1