From 64780df27b41d73689cd12dfda780d75fb80d743 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Wed, 3 May 2023 13:24:45 +0200 Subject: More last_stmt removal This is the last set of changes removing calls to last_stmt in favor of *gsi_last_bb where this is obviously correct. As with the last changes I tried to cleanup the code as far as dependences are concerned. * tree-ssa-loop-split.cc (split_at_bb_p): Avoid last_stmt. (patch_loop_exit): Likewise. (connect_loops): Likewise. (split_loop): Likewise. (control_dep_semi_invariant_p): Likewise. (do_split_loop_on_cond): Likewise. (split_loop_on_cond): Likewise. * tree-ssa-loop-unswitch.cc (find_unswitching_predicates_for_bb): Likewise. (simplify_loop_version): Likewise. (evaluate_bbs): Likewise. (find_loop_guard): Likewise. (clean_up_after_unswitching): Likewise. * tree-ssa-math-opts.cc (maybe_optimize_guarding_check): Likewise. (optimize_spaceship): Take a gcond * argument, avoid last_stmt. (math_opts_dom_walker::after_dom_children): Adjust call to optimize_spaceship. * tree-vrp.cc (maybe_set_nonzero_bits): Avoid last_stmt. * value-pointer-equiv.cc (pointer_equiv_analyzer::visit_edge): Likewise. --- gcc/tree-ssa-loop-split.cc | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) (limited to 'gcc/tree-ssa-loop-split.cc') diff --git a/gcc/tree-ssa-loop-split.cc b/gcc/tree-ssa-loop-split.cc index fca6781..e5e6aa8 100644 --- a/gcc/tree-ssa-loop-split.cc +++ b/gcc/tree-ssa-loop-split.cc @@ -76,15 +76,13 @@ along with GCC; see the file COPYING3. If not see static tree split_at_bb_p (class loop *loop, basic_block bb, tree *border, affine_iv *iv) { - gimple *last; gcond *stmt; affine_iv iv2; /* BB must end in a simple conditional jump. */ - last = last_stmt (bb); - if (!last || gimple_code (last) != GIMPLE_COND) + stmt = safe_dyn_cast (*gsi_last_bb (bb)); + if (!stmt) return NULL_TREE; - stmt = as_a (last); enum tree_code code = gimple_cond_code (stmt); @@ -158,7 +156,7 @@ patch_loop_exit (class loop *loop, gcond *guard, tree nextval, tree newbound, bool initial_true) { edge exit = single_exit (loop); - gcond *stmt = as_a (last_stmt (exit->src)); + gcond *stmt = as_a (*gsi_last_bb (exit->src)); gimple_cond_set_condition (stmt, gimple_cond_code (guard), nextval, newbound); update_stmt (stmt); @@ -335,7 +333,7 @@ connect_loops (class loop *loop1, class loop *loop2) gimple_stmt_iterator gsi; edge new_e, skip_e; - gimple *stmt = last_stmt (exit->src); + gcond *stmt = as_a (*gsi_last_bb (exit->src)); skip_stmt = gimple_build_cond (gimple_cond_code (stmt), gimple_cond_lhs (stmt), gimple_cond_rhs (stmt), @@ -571,7 +569,7 @@ split_loop (class loop *loop1) gphi *phi = find_or_create_guard_phi (loop1, guard_iv, &iv); if (!phi) continue; - gcond *guard_stmt = as_a (last_stmt (bbs[i])); + gcond *guard_stmt = as_a (*gsi_last_bb (bbs[i])); tree guard_init = PHI_ARG_DEF_FROM_EDGE (phi, loop_preheader_edge (loop1)); enum tree_code guard_code = gimple_cond_code (guard_stmt); @@ -655,8 +653,8 @@ split_loop (class loop *loop1) /* Finally patch out the two copies of the condition to be always true/false (or opposite). */ - gcond *force_true = as_a (last_stmt (bbs[i])); - gcond *force_false = as_a (last_stmt (get_bb_copy (bbs[i]))); + gcond *force_true = as_a (*gsi_last_bb (bbs[i])); + gcond *force_false = as_a (*gsi_last_bb (get_bb_copy (bbs[i]))); if (!initial_true) std::swap (force_true, force_false); gimple_cond_make_true (force_true); @@ -1148,8 +1146,7 @@ control_dep_semi_invariant_p (struct loop *loop, basic_block bb, for (hash_set::iterator iter = dep_bbs->begin (); iter != dep_bbs->end (); ++iter) { - gimple *last = last_stmt (*iter); - + gimple *last = *gsi_last_bb (*iter); if (!last) return false; @@ -1520,7 +1517,7 @@ do_split_loop_on_cond (struct loop *loop1, edge invar_branch) { basic_block cond_bb = invar_branch->src; bool true_invar = !!(invar_branch->flags & EDGE_TRUE_VALUE); - gcond *cond = as_a (last_stmt (cond_bb)); + gcond *cond = as_a (*gsi_last_bb (cond_bb)); gcc_assert (cond_bb->loop_father == loop1); @@ -1544,7 +1541,7 @@ do_split_loop_on_cond (struct loop *loop1, edge invar_branch) } basic_block cond_bb_copy = get_bb_copy (cond_bb); - gcond *cond_copy = as_a (last_stmt (cond_bb_copy)); + gcond *cond_copy = as_a (*gsi_last_bb (cond_bb_copy)); /* Replace the condition in loop2 with a bool constant to let PassManager remove the variant branch after current pass completes. */ @@ -1628,12 +1625,10 @@ split_loop_on_cond (struct loop *loop) if (!dominated_by_p (CDI_DOMINATORS, loop->latch, bb)) continue; - gimple *last = last_stmt (bb); - - if (!last || gimple_code (last) != GIMPLE_COND) + gcond *cond = safe_dyn_cast (*gsi_last_bb (bb)); + if (!cond) continue; - gcond *cond = as_a (last); edge branch_edge = get_cond_branch_to_split_loop (loop, cond); if (branch_edge) -- cgit v1.1 From fe8ac82fc05b0ba60f50f94f702da9e154731aeb Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Wed, 3 May 2023 13:29:22 +0200 Subject: Rename last_stmt to last_nondebug_stmt The following renames last_stmt to last_nondebug_stmt which is what it really does. * tree-cfg.h (last_stmt): Rename to ... (last_nondebug_stmt): ... this. * tree-cfg.cc (last_stmt): Rename to ... (last_nondebug_stmt): ... this. (assign_discriminators): Adjust. (group_case_labels_stmt): Likewise. (gimple_can_duplicate_bb_p): Likewise. (execute_fixup_cfg): Likewise. * auto-profile.cc (afdo_propagate_circuit): Likewise. * gimple-range.cc (gimple_ranger::range_on_exit): Likewise. * omp-expand.cc (workshare_safe_to_combine_p): Likewise. (determine_parallel_type): Likewise. (adjust_context_and_scope): Likewise. (expand_task_call): Likewise. (remove_exit_barrier): Likewise. (expand_omp_taskreg): Likewise. (expand_omp_for_init_counts): Likewise. (expand_omp_for_init_vars): Likewise. (expand_omp_for_static_chunk): Likewise. (expand_omp_simd): Likewise. (expand_oacc_for): Likewise. (expand_omp_for): Likewise. (expand_omp_sections): Likewise. (expand_omp_atomic_fetch_op): Likewise. (expand_omp_atomic_cas): Likewise. (expand_omp_atomic): Likewise. (expand_omp_target): Likewise. (expand_omp): Likewise. (omp_make_gimple_edges): Likewise. * trans-mem.cc (tm_region_init): Likewise. * tree-inline.cc (redirect_all_calls): Likewise. * tree-parloops.cc (gen_parallel_loop): Likewise. * tree-ssa-loop-ch.cc (do_while_loop_p): Likewise. * tree-ssa-loop-ivcanon.cc (canonicalize_loop_induction_variables): Likewise. * tree-ssa-loop-ivopts.cc (stmt_after_ip_normal_pos): Likewise. (may_eliminate_iv): Likewise. * tree-ssa-loop-manip.cc (standard_iv_increment_position): Likewise. * tree-ssa-loop-niter.cc (do_warn_aggressive_loop_optimizations): Likewise. (estimate_numbers_of_iterations): Likewise. * tree-ssa-loop-split.cc (compute_added_num_insns): Likewise. * tree-ssa-loop-unswitch.cc (get_predicates_for_bb): Likewise. (set_predicates_for_bb): Likewise. (init_loop_unswitch_info): Likewise. (hoist_guard): Likewise. * tree-ssa-phiopt.cc (match_simplify_replacement): Likewise. (minmax_replacement): Likewise. * tree-ssa-reassoc.cc (update_range_test): Likewise. (optimize_range_tests_to_bit_test): Likewise. (optimize_range_tests_var_bound): Likewise. (optimize_range_tests): Likewise. (no_side_effect_bb): Likewise. (suitable_cond_bb): Likewise. (maybe_optimize_range_tests): Likewise. (reassociate_bb): Likewise. * tree-vrp.cc (rvrp_folder::pre_fold_bb): Likewise. --- gcc/tree-ssa-loop-split.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gcc/tree-ssa-loop-split.cc') diff --git a/gcc/tree-ssa-loop-split.cc b/gcc/tree-ssa-loop-split.cc index e5e6aa8..b41b5e6 100644 --- a/gcc/tree-ssa-loop-split.cc +++ b/gcc/tree-ssa-loop-split.cc @@ -1390,7 +1390,7 @@ compute_added_num_insns (struct loop *loop, const_edge branch_edge) auto_vec worklist; hash_set removed; - gimple *stmt = last_stmt (cond_bb); + gimple *stmt = last_nondebug_stmt (cond_bb); worklist.safe_push (stmt); removed.add (stmt); -- cgit v1.1