From 9da4058c1454b279f0b5791100105bf7a6734e9d Mon Sep 17 00:00:00 2001 From: Jeff Law Date: Tue, 5 Jul 2005 23:25:57 -0600 Subject: [PATCH] tree-ssa-dce.c (cfg_altered): New global. * tree-ssa-dce.c (cfg_altered): New global. (tree_dce_init): Initialize cfg_altered. (remove_dead_stmt): If we remove an edge in the CFG, then set CFG_ALTERED. (perform_tree_ssa_dce): If we altered the CFG, then invalidate the dominators. * gcc.c-torture/compile/pr21356.c: New test. From-SVN: r101652 --- gcc/ChangeLog | 9 +++++++ gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.c-torture/compile/pr21356.c | 13 ++++++++++ gcc/tree-ssa-dce.c | 24 ++++++++++++++++++- 4 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr21356.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 14c491245c39..fa01f3162eb0 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2005-07-06 Jeff Law + + * tree-ssa-dce.c (cfg_altered): New global. + (tree_dce_init): Initialize cfg_altered. + (remove_dead_stmt): If we remove an edge in the CFG, then set + CFG_ALTERED. + (perform_tree_ssa_dce): If we altered the CFG, then invalidate + the dominators. + 2005-07-06 Kazu Hirata * Makefile.in (stamp-collect-ld): Use diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e598f6e50886..b70b33024a93 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2005-07-06 Jeff Law + + * gcc.c-torture/compile/pr21356.c: New test. + 2005-07-05 Joseph S. Myers PR c/22013 diff --git a/gcc/testsuite/gcc.c-torture/compile/pr21356.c b/gcc/testsuite/gcc.c-torture/compile/pr21356.c new file mode 100644 index 000000000000..b072b5165188 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr21356.c @@ -0,0 +1,13 @@ +int a; +void* p; + +void foo (void) +{ + switch (a) + { + a0: case 0: p = &&a1; + a1: case 1: p = &&a2; + a2: default: p = &&a1; + } + goto *p; +} diff --git a/gcc/tree-ssa-dce.c b/gcc/tree-ssa-dce.c index 1b5c9f94338e..abd4d7ae77a7 100644 --- a/gcc/tree-ssa-dce.c +++ b/gcc/tree-ssa-dce.c @@ -96,6 +96,13 @@ static bitmap *control_dependence_map; processed that it is control dependent on. */ static sbitmap visited_control_parents; +/* TRUE if this pass alters the CFG (by removing control statements). + FALSE otherwise. + + If this pass alters the CFG, then it will arrange for the dominators + to be recomputed. */ +static bool cfg_altered; + /* Execute CODE for each edge (given number EDGE_NUMBER within the CODE) for which the block with index N is control dependent. */ #define EXECUTE_IF_CONTROL_DEPENDENT(N, EDGE_NUMBER, CODE) \ @@ -774,7 +781,15 @@ remove_dead_stmt (block_stmt_iterator *i, basic_block bb) /* Remove the remaining the outgoing edges. */ while (!single_succ_p (bb)) - remove_edge (EDGE_SUCC (bb, 1)); + { + /* FIXME. When we remove the edge, we modify the CFG, which + in turn modifies the dominator and post-dominator tree. + Is it safe to postpone recomputing the dominator and + post-dominator tree until the end of this pass given that + the post-dominators are used above? */ + cfg_altered = true; + remove_edge (EDGE_SUCC (bb, 1)); + } } FOR_EACH_SSA_DEF_OPERAND (def_p, t, iter, SSA_OP_VIRTUAL_DEFS) @@ -833,6 +848,7 @@ tree_dce_init (bool aggressive) sbitmap_zero (processed); worklist = VEC_alloc (tree, heap, 64); + cfg_altered = false; } /* Cleanup after this pass. */ @@ -903,6 +919,12 @@ perform_tree_ssa_dce (bool aggressive) if (aggressive) free_dominance_info (CDI_POST_DOMINATORS); + /* If we removed paths in the CFG, then we need to update + dominators as well. I haven't investigated the possibility + of incrementally updating dominators. */ + if (cfg_altered) + free_dominance_info (CDI_DOMINATORS); + /* Debugging dumps. */ if (dump_file) print_stats (); -- 2.47.2