diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc index cb4e2da023d..ff36bb0119b 100644 --- a/gcc/tree-ssa-phiopt.cc +++ b/gcc/tree-ssa-phiopt.cc @@ -767,7 +767,6 @@ match_simplify_replacement (basic_block cond_bb, basic_block middle_bb, tree result; gimple *stmt_to_move = NULL; gimple *stmt_to_move_alt = NULL; - auto_bitmap inserted_exprs; tree arg_true, arg_false; /* Special case A ? B : B as this will always simplify to B. */ @@ -844,6 +843,18 @@ match_simplify_replacement (basic_block cond_bb, basic_block middle_bb, if (!result) return false; + auto_bitmap exprs_maybe_dce; + + /* Mark the cond statements' lhs/rhs as maybe dce. */ + if (TREE_CODE (gimple_cond_lhs (stmt)) == SSA_NAME + && !SSA_NAME_IS_DEFAULT_DEF (gimple_cond_lhs (stmt))) + bitmap_set_bit (exprs_maybe_dce, + SSA_NAME_VERSION (gimple_cond_lhs (stmt))); + if (TREE_CODE (gimple_cond_rhs (stmt)) == SSA_NAME + && !SSA_NAME_IS_DEFAULT_DEF (gimple_cond_rhs (stmt))) + bitmap_set_bit (exprs_maybe_dce, + SSA_NAME_VERSION (gimple_cond_rhs (stmt))); + gsi = gsi_last_bb (cond_bb); /* Insert the sequence generated from gimple_simplify_phiopt. */ if (seq) @@ -855,7 +866,7 @@ match_simplify_replacement (basic_block cond_bb, basic_block middle_bb, 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)); + bitmap_set_bit (exprs_maybe_dce, SSA_NAME_VERSION (name)); } if (dump_file && (dump_flags & TDF_FOLDING)) { @@ -867,10 +878,10 @@ match_simplify_replacement (basic_block cond_bb, basic_block middle_bb, /* If there was a statement to move, move it to right before the original conditional. */ - move_stmt (stmt_to_move, &gsi, inserted_exprs); - move_stmt (stmt_to_move_alt, &gsi, inserted_exprs); + move_stmt (stmt_to_move, &gsi, exprs_maybe_dce); + move_stmt (stmt_to_move_alt, &gsi, exprs_maybe_dce); - replace_phi_edge_with_variable (cond_bb, e1, phi, result, inserted_exprs); + replace_phi_edge_with_variable (cond_bb, e1, phi, result, exprs_maybe_dce); /* 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