From a1ac9ffb5a7f44b2e2633b7265c21ce803c8e854 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Thu, 6 May 2021 11:29:25 +0200 Subject: Avoid update_ssa quadraticness in loop splitting We already take care to not apply loop splitting to IL produced by splitting so we should be able to delay updating SSA and loop-closed SSA that was left broken after loop versioning until after we processed all opportunities. 2021-05-06 Richard Biener * tree-ssa-loop-split.c (split_loop): Delay updating SSA form. Output an opt-info message. (do_split_loop_on_cond): Likewise. (tree_ssa_split_loops): Update SSA form here. --- gcc/tree-ssa-loop-split.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'gcc/tree-ssa-loop-split.c') diff --git a/gcc/tree-ssa-loop-split.c b/gcc/tree-ssa-loop-split.c index b80b6a7..3a09bbc 100644 --- a/gcc/tree-ssa-loop-split.c +++ b/gcc/tree-ssa-loop-split.c @@ -589,7 +589,6 @@ split_loop (class loop *loop1) profile_probability::always (), true); gcc_assert (loop2); - update_ssa (TODO_update_ssa); edge new_e = connect_loops (loop1, loop2); connect_loop_phis (loop1, loop2, new_e); @@ -621,14 +620,13 @@ split_loop (class loop *loop1) free_original_copy_tables (); - /* We destroyed LCSSA form above. Eventually we might be able - to fix it on the fly, for now simply punt and use the helper. */ - rewrite_into_loop_closed_ssa_1 (NULL, 0, SSA_OP_USE, loop1); - changed = true; if (dump_file && (dump_flags & TDF_DETAILS)) fprintf (dump_file, ";; Loop split.\n"); + if (dump_enabled_p ()) + dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, guard_stmt, "loop split\n"); + /* Only deal with the first opportunity. */ break; } @@ -1532,8 +1530,6 @@ do_split_loop_on_cond (struct loop *loop1, edge invar_branch) to_loop1->flags |= true_invar ? EDGE_FALSE_VALUE : EDGE_TRUE_VALUE; to_loop2->flags |= true_invar ? EDGE_TRUE_VALUE : EDGE_FALSE_VALUE; - update_ssa (TODO_update_ssa); - /* Due to introduction of a control flow edge from loop1 latch to loop2 pre-header, we should update PHIs in loop2 to reflect this connection between loop1 and loop2. */ @@ -1541,8 +1537,6 @@ do_split_loop_on_cond (struct loop *loop1, edge invar_branch) free_original_copy_tables (); - rewrite_into_loop_closed_ssa_1 (NULL, 0, SSA_OP_USE, loop1); - return true; } @@ -1644,7 +1638,10 @@ tree_ssa_split_loops (void) free_dominance_info (CDI_POST_DOMINATORS); if (changed) - return TODO_cleanup_cfg; + { + rewrite_into_loop_closed_ssa (NULL, TODO_update_ssa); + return TODO_cleanup_cfg; + } return 0; } -- cgit v1.1 From e41ba804ba5f5ca433e09238d561b1b4c8b10985 Mon Sep 17 00:00:00 2001 From: Kewen Lin Date: Thu, 29 Jul 2021 22:26:25 -0500 Subject: Use range-based for loops for traversing loops This patch follows Martin's suggestion here[1], to support range based loop for iterating loops, analogously to the patch for vec[2]. For example, use below range-based for loop for (auto loop : loops_list (cfun, 0)) to replace the previous macro FOR_EACH_LOOP FOR_EACH_LOOP (loop, 0) [1] https://gcc.gnu.org/pipermail/gcc-patches/2021-June/573424.html [2] https://gcc.gnu.org/pipermail/gcc-patches/2021-June/572315.html gcc/ChangeLog: * cfgloop.h (as_const): New function. (class loop_iterator): Rename to ... (class loops_list): ... this. (loop_iterator::next): Rename to ... (loops_list::Iter::fill_curr_loop): ... this and adjust. (loop_iterator::loop_iterator): Rename to ... (loops_list::loops_list): ... this and adjust. (loops_list::Iter): New class. (loops_list::iterator): New type. (loops_list::const_iterator): New type. (loops_list::begin): New function. (loops_list::end): Likewise. (loops_list::begin const): Likewise. (loops_list::end const): Likewise. (FOR_EACH_LOOP): Remove. (FOR_EACH_LOOP_FN): Remove. * cfgloop.c (flow_loops_dump): Adjust FOR_EACH_LOOP* with range-based for loop with loops_list instance. (sort_sibling_loops): Likewise. (disambiguate_loops_with_multiple_latches): Likewise. (verify_loop_structure): Likewise. * cfgloopmanip.c (create_preheaders): Likewise. (force_single_succ_latches): Likewise. * config/aarch64/falkor-tag-collision-avoidance.c (execute_tag_collision_avoidance): Likewise. * config/mn10300/mn10300.c (mn10300_scan_for_setlb_lcc): Likewise. * config/s390/s390.c (s390_adjust_loops): Likewise. * doc/loop.texi: Likewise. * gimple-loop-interchange.cc (pass_linterchange::execute): Likewise. * gimple-loop-jam.c (tree_loop_unroll_and_jam): Likewise. * gimple-loop-versioning.cc (loop_versioning::analyze_blocks): Likewise. (loop_versioning::make_versioning_decisions): Likewise. * gimple-ssa-split-paths.c (split_paths): Likewise. * graphite-isl-ast-to-gimple.c (graphite_regenerate_ast_isl): Likewise. * graphite.c (canonicalize_loop_form): Likewise. (graphite_transform_loops): Likewise. * ipa-fnsummary.c (analyze_function_body): Likewise. * ipa-pure-const.c (analyze_function): Likewise. * loop-doloop.c (doloop_optimize_loops): Likewise. * loop-init.c (loop_optimizer_finalize): Likewise. (fix_loop_structure): Likewise. * loop-invariant.c (calculate_loop_reg_pressure): Likewise. (move_loop_invariants): Likewise. * loop-unroll.c (decide_unrolling): Likewise. (unroll_loops): Likewise. * modulo-sched.c (sms_schedule): Likewise. * predict.c (predict_loops): Likewise. (pass_profile::execute): Likewise. * profile.c (branch_prob): Likewise. * sel-sched-ir.c (sel_finish_pipelining): Likewise. (sel_find_rgns): Likewise. * tree-cfg.c (replace_loop_annotate): Likewise. (replace_uses_by): Likewise. (move_sese_region_to_fn): Likewise. * tree-if-conv.c (pass_if_conversion::execute): Likewise. * tree-loop-distribution.c (loop_distribution::execute): Likewise. * tree-parloops.c (parallelize_loops): Likewise. * tree-predcom.c (tree_predictive_commoning): Likewise. * tree-scalar-evolution.c (scev_initialize): Likewise. (scev_reset): Likewise. * tree-ssa-dce.c (find_obviously_necessary_stmts): Likewise. * tree-ssa-live.c (remove_unused_locals): Likewise. * tree-ssa-loop-ch.c (ch_base::copy_headers): Likewise. * tree-ssa-loop-im.c (analyze_memory_references): Likewise. (tree_ssa_lim_initialize): Likewise. * tree-ssa-loop-ivcanon.c (canonicalize_induction_variables): Likewise. * tree-ssa-loop-ivopts.c (tree_ssa_iv_optimize): Likewise. * tree-ssa-loop-manip.c (get_loops_exits): Likewise. * tree-ssa-loop-niter.c (estimate_numbers_of_iterations): Likewise. (free_numbers_of_iterations_estimates): Likewise. * tree-ssa-loop-prefetch.c (tree_ssa_prefetch_arrays): Likewise. * tree-ssa-loop-split.c (tree_ssa_split_loops): Likewise. * tree-ssa-loop-unswitch.c (tree_ssa_unswitch_loops): Likewise. * tree-ssa-loop.c (gate_oacc_kernels): Likewise. (pass_scev_cprop::execute): Likewise. * tree-ssa-propagate.c (clean_up_loop_closed_phi): Likewise. * tree-ssa-sccvn.c (do_rpo_vn): Likewise. * tree-ssa-threadupdate.c (jump_thread_path_registry::thread_through_all_blocks): Likewise. * tree-vectorizer.c (vectorize_loops): Likewise. * tree-vrp.c (vrp_asserts::find_assert_locations): Likewise. --- gcc/tree-ssa-loop-split.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'gcc/tree-ssa-loop-split.c') diff --git a/gcc/tree-ssa-loop-split.c b/gcc/tree-ssa-loop-split.c index 3a09bbc..3f6ad04 100644 --- a/gcc/tree-ssa-loop-split.c +++ b/gcc/tree-ssa-loop-split.c @@ -1598,18 +1598,17 @@ split_loop_on_cond (struct loop *loop) static unsigned int tree_ssa_split_loops (void) { - class loop *loop; bool changed = false; gcc_assert (scev_initialized_p ()); calculate_dominance_info (CDI_POST_DOMINATORS); - FOR_EACH_LOOP (loop, LI_INCLUDE_ROOT) + for (auto loop : loops_list (cfun, LI_INCLUDE_ROOT)) loop->aux = NULL; /* Go through all loops starting from innermost. */ - FOR_EACH_LOOP (loop, LI_FROM_INNERMOST) + for (auto loop : loops_list (cfun, LI_FROM_INNERMOST)) { if (loop->aux) { @@ -1630,7 +1629,7 @@ tree_ssa_split_loops (void) } } - FOR_EACH_LOOP (loop, LI_INCLUDE_ROOT) + for (auto loop : loops_list (cfun, LI_INCLUDE_ROOT)) loop->aux = NULL; clear_aux_for_blocks (); -- cgit v1.1