This fixes the BB_VISITED bug in IRA I ran into earlier this year, removing the superfluous clearing in VRP and the SSA propagator as well as removing the now always true do_dce flag from substitute-and-fold.
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk. Richard. 2016-10-18 Richard Biener <rguent...@suse.de> * tree-ssa-propagate.h (substitute_and_fold): Adjust prototype. * tree-ssa-propagate.c (ssa_prop_fini): Remove final BB_VISITED clearing. (substitute_and_fold_dom_walker): Adjust constructor. (substitute_and_fold_dom_walker::before_dom_children): Remove do_dce flag and handling (always true). (substitute_and_fold): Likewise. * tree-vrp.c (vrp_finalize): Adjust. (execute_early_vrp): Remove final BB_VISITED clearing. * tree-ssa-ccp.c (ccp_finalize): Adjust. * tree-ssa-copy.c (fini_copy_prop): Likewise. * ira.c (ira): Call clear_bb_flags. Index: gcc/tree-vrp.c =================================================================== --- gcc/tree-vrp.c (revision 241294) +++ gcc/tree-vrp.c (working copy) @@ -10622,8 +10622,7 @@ vrp_finalize (bool warn_array_bounds_p) vr_value[i]->max); } - substitute_and_fold (op_with_constant_singleton_value_range, - vrp_fold_stmt, true); + substitute_and_fold (op_with_constant_singleton_value_range, vrp_fold_stmt); if (warn_array_bounds && warn_array_bounds_p) check_all_array_refs (); @@ -10954,8 +10953,6 @@ execute_early_vrp () vrp_free_lattice (); scev_finalize (); loop_optimizer_finalize (); - FOR_EACH_BB_FN (bb, cfun) - bb->flags &= ~BB_VISITED; return 0; } Index: gcc/tree-ssa-ccp.c =================================================================== --- gcc/tree-ssa-ccp.c (revision 241294) +++ gcc/tree-ssa-ccp.c (working copy) @@ -953,8 +953,7 @@ ccp_finalize (bool nonzero_p) } /* Perform substitutions based on the known constant values. */ - something_changed = substitute_and_fold (get_constant_value, - ccp_fold_stmt, true); + something_changed = substitute_and_fold (get_constant_value, ccp_fold_stmt); free (const_val); const_val = NULL; Index: gcc/tree-ssa-propagate.c =================================================================== --- gcc/tree-ssa-propagate.c (revision 241294) +++ gcc/tree-ssa-propagate.c (working copy) @@ -479,9 +479,6 @@ ssa_prop_fini (void) free (cfg_order_to_bb); BITMAP_FREE (ssa_edge_worklist); uid_to_stmt.release (); - basic_block bb; - FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (cfun), NULL, next_bb) - bb->flags &= ~BB_VISITED; } @@ -972,10 +969,9 @@ class substitute_and_fold_dom_walker : p public: substitute_and_fold_dom_walker (cdi_direction direction, ssa_prop_get_value_fn get_value_fn_, - ssa_prop_fold_stmt_fn fold_fn_, - bool do_dce_) + ssa_prop_fold_stmt_fn fold_fn_) : dom_walker (direction), get_value_fn (get_value_fn_), - fold_fn (fold_fn_), do_dce (do_dce_), something_changed (false) + fold_fn (fold_fn_), something_changed (false) { stmts_to_remove.create (0); stmts_to_fixup.create (0); @@ -993,7 +989,6 @@ public: ssa_prop_get_value_fn get_value_fn; ssa_prop_fold_stmt_fn fold_fn; - bool do_dce; bool something_changed; vec<gimple *> stmts_to_remove; vec<gimple *> stmts_to_fixup; @@ -1012,8 +1007,7 @@ substitute_and_fold_dom_walker::before_d tree res = gimple_phi_result (phi); if (virtual_operand_p (res)) continue; - if (do_dce - && res && TREE_CODE (res) == SSA_NAME) + if (res && TREE_CODE (res) == SSA_NAME) { tree sprime = get_value_fn (res); if (sprime @@ -1039,8 +1033,7 @@ substitute_and_fold_dom_walker::before_d /* No point propagating into a stmt we have a value for we can propagate into all uses. Mark it for removal instead. */ tree lhs = gimple_get_lhs (stmt); - if (do_dce - && lhs && TREE_CODE (lhs) == SSA_NAME) + if (lhs && TREE_CODE (lhs) == SSA_NAME) { tree sprime = get_value_fn (lhs); if (sprime @@ -1180,8 +1173,7 @@ substitute_and_fold_dom_walker::before_d bool substitute_and_fold (ssa_prop_get_value_fn get_value_fn, - ssa_prop_fold_stmt_fn fold_fn, - bool do_dce) + ssa_prop_fold_stmt_fn fold_fn) { gcc_assert (get_value_fn); @@ -1192,7 +1184,7 @@ substitute_and_fold (ssa_prop_get_value_ calculate_dominance_info (CDI_DOMINATORS); substitute_and_fold_dom_walker walker(CDI_DOMINATORS, - get_value_fn, fold_fn, do_dce); + get_value_fn, fold_fn); walker.walk (ENTRY_BLOCK_PTR_FOR_FN (cfun)); /* We cannot remove stmts during the BB walk, especially not release Index: gcc/tree-ssa-propagate.h =================================================================== --- gcc/tree-ssa-propagate.h (revision 241294) +++ gcc/tree-ssa-propagate.h (working copy) @@ -75,8 +75,7 @@ extern bool update_gimple_call (gimple_s extern bool update_call_from_tree (gimple_stmt_iterator *, tree); extern void ssa_propagate (ssa_prop_visit_stmt_fn, ssa_prop_visit_phi_fn); extern bool stmt_makes_single_store (gimple *); -extern bool substitute_and_fold (ssa_prop_get_value_fn, ssa_prop_fold_stmt_fn, - bool); +extern bool substitute_and_fold (ssa_prop_get_value_fn, ssa_prop_fold_stmt_fn); extern bool may_propagate_copy (tree, tree); extern bool may_propagate_copy_into_stmt (gimple *, tree); extern bool may_propagate_copy_into_asm (tree); Index: gcc/tree-ssa-copy.c =================================================================== --- gcc/tree-ssa-copy.c (revision 241294) +++ gcc/tree-ssa-copy.c (working copy) @@ -550,7 +550,7 @@ fini_copy_prop (void) } } - bool changed = substitute_and_fold (get_value, NULL, true); + bool changed = substitute_and_fold (get_value, NULL); if (changed) { free_numbers_of_iterations_estimates (cfun); Index: gcc/ira.c =================================================================== --- gcc/ira.c (revision 241294) +++ gcc/ira.c (working copy) @@ -5065,6 +5065,8 @@ ira (FILE *f) bool saved_flag_caller_saves = flag_caller_saves; enum ira_region saved_flag_ira_region = flag_ira_region; + clear_bb_flags (); + /* Perform target specific PIC register initialization. */ targetm.init_pic_reg ();