This avoids re-computing BB predicates. The more interesting job will be to avoid re-computing post dominators (for the whole function) all the time.
Bootstrap / regtest running on x86_64-unknown-linux-gnu. Richard. 2016-05-19 Richard Biener <rguent...@suse.de> * tree-if-conv.c (add_bb_predicate_gimplified_stmts): Use gimple_seq_add_seq_without_update. (release_bb_predicate): Assert we have no operands to free. (if_convertible_loop_p_1): Calculate post dominators later. Do not free BB predicates here. (combine_blocks): Do not recompute BB predicates. (version_loop_for_if_conversion): Save BB predicates around loop versioning. * gcc.dg/tree-ssa/ifc-cd.c: Adjust. Index: gcc/tree-if-conv.c =================================================================== *** gcc/tree-if-conv.c (revision 236441) --- gcc/tree-if-conv.c (working copy) *************** set_bb_predicate_gimplified_stmts (basic *** 257,263 **** static inline void add_bb_predicate_gimplified_stmts (basic_block bb, gimple_seq stmts) { ! gimple_seq_add_seq (&(((struct bb_predicate *) bb->aux)->predicate_gimplified_stmts), stmts); } --- 257,263 ---- static inline void add_bb_predicate_gimplified_stmts (basic_block bb, gimple_seq stmts) { ! gimple_seq_add_seq_without_update (&(((struct bb_predicate *) bb->aux)->predicate_gimplified_stmts), stmts); } *************** release_bb_predicate (basic_block bb) *** 280,289 **** gimple_seq stmts = bb_predicate_gimplified_stmts (bb); if (stmts) { ! gimple_stmt_iterator i; - for (i = gsi_start (stmts); !gsi_end_p (i); gsi_next (&i)) - free_stmt_operands (cfun, gsi_stmt (i)); set_bb_predicate_gimplified_stmts (bb, NULL); } } --- 280,290 ---- gimple_seq stmts = bb_predicate_gimplified_stmts (bb); if (stmts) { ! if (flag_checking) ! for (gimple_stmt_iterator i = gsi_start (stmts); ! !gsi_end_p (i); gsi_next (&i)) ! gcc_assert (! gimple_use_ops (gsi_stmt (i))); set_bb_predicate_gimplified_stmts (bb, NULL); } } *************** if_convertible_loop_p_1 (struct loop *lo *** 1322,1328 **** return false; calculate_dominance_info (CDI_DOMINATORS); - calculate_dominance_info (CDI_POST_DOMINATORS); /* Allow statements that can be handled during if-conversion. */ ifc_bbs = get_loop_body_in_if_conv_order (loop); --- 1323,1328 ---- *************** if_convertible_loop_p_1 (struct loop *lo *** 1370,1375 **** --- 1370,1376 ---- = new hash_map<innermost_loop_behavior_hash, data_reference_p>; baseref_DR_map = new hash_map<tree_operand_hash, data_reference_p>; + calculate_dominance_info (CDI_POST_DOMINATORS); predicate_bbs (loop); for (i = 0; refs->iterate (i, &dr); i++) *************** if_convertible_loop_p_1 (struct loop *lo *** 1421,1429 **** return false; } - for (i = 0; i < loop->num_nodes; i++) - free_bb_predicate (ifc_bbs[i]); - /* Checking PHIs needs to be done after stmts, as the fact whether there are any masked loads or stores affects the tests. */ for (i = 0; i < loop->num_nodes; i++) --- 1422,1427 ---- *************** combine_blocks (struct loop *loop) *** 2298,2304 **** edge e; edge_iterator ei; - predicate_bbs (loop); remove_conditions_and_labels (loop); insert_gimplified_predicates (loop); predicate_all_scalar_phis (loop); --- 2296,2301 ---- *************** version_loop_for_if_conversion (struct l *** 2428,2440 **** --- 2425,2447 ---- integer_zero_node); gimple_call_set_lhs (g, cond); + /* Save BB->aux around loop_version as that uses the same field. */ + void **saved_preds = XALLOCAVEC (void *, loop->num_nodes); + for (unsigned i = 0; i < loop->num_nodes; i++) + saved_preds[i] = ifc_bbs[i]->aux; + initialize_original_copy_tables (); new_loop = loop_version (loop, cond, &cond_bb, REG_BR_PROB_BASE, REG_BR_PROB_BASE, REG_BR_PROB_BASE, true); free_original_copy_tables (); + + for (unsigned i = 0; i < loop->num_nodes; i++) + ifc_bbs[i]->aux = saved_preds[i]; + if (new_loop == NULL) return false; + new_loop->dont_vectorize = true; new_loop->force_vectorize = false; gsi = gsi_last_bb (cond_bb); Index: gcc/testsuite/gcc.dg/tree-ssa/ifc-cd.c =================================================================== *** gcc/testsuite/gcc.dg/tree-ssa/ifc-cd.c (revision 236441) --- gcc/testsuite/gcc.dg/tree-ssa/ifc-cd.c (working copy) *************** void foo (int *x1, int *x2, int *x3, int *** 25,28 **** } } ! /* { dg-final { scan-tree-dump-times "Use predicate of bb" 8 "ifcvt" } } */ --- 25,28 ---- } } ! /* { dg-final { scan-tree-dump-times "Use predicate of bb" 4 "ifcvt" } } */