diff options
Diffstat (limited to 'gcc/tree-ssa-dce.c')
-rw-r--r-- | gcc/tree-ssa-dce.c | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/gcc/tree-ssa-dce.c b/gcc/tree-ssa-dce.c index 16b9d480a49..30b0ddb23a8 100644 --- a/gcc/tree-ssa-dce.c +++ b/gcc/tree-ssa-dce.c @@ -708,7 +708,10 @@ eliminate_unnecessary_stmts (void) { /* Remove dead PHI nodes. */ remove_dead_phis (bb); + } + FOR_EACH_BB (bb) + { /* Remove dead statements. */ for (i = bsi_start (bb); ! bsi_end_p (i) ; ) { @@ -795,6 +798,7 @@ remove_dead_stmt (block_stmt_iterator *i, basic_block bb) if (is_ctrl_stmt (t)) { basic_block post_dom_bb; + /* The post dominance info has to be up-to-date. */ gcc_assert (dom_computed[CDI_POST_DOMINATORS] == DOM_OK); /* Get the immediate post dominator of bb. */ @@ -808,9 +812,20 @@ remove_dead_stmt (block_stmt_iterator *i, basic_block bb) return; } - /* Redirect the first edge out of BB to reach POST_DOM_BB. */ - redirect_edge_and_branch (EDGE_SUCC (bb, 0), post_dom_bb); - PENDING_STMT (EDGE_SUCC (bb, 0)) = NULL; + /* If the post dominator block has PHI nodes, we might be unable + to compute the right PHI args for them. Since the control + statement is unnecessary, all edges can be regarded as + equivalent, but we have to get rid of the condition, since it + might reference a variable that was determined to be + unnecessary and thus removed. */ + if (phi_nodes (post_dom_bb)) + post_dom_bb = EDGE_SUCC (bb, 0)->dest; + else + { + /* Redirect the first edge out of BB to reach POST_DOM_BB. */ + redirect_edge_and_branch (EDGE_SUCC (bb, 0), post_dom_bb); + PENDING_STMT (EDGE_SUCC (bb, 0)) = NULL; + } EDGE_SUCC (bb, 0)->probability = REG_BR_PROB_BASE; EDGE_SUCC (bb, 0)->count = bb->count; |