From 2f4e45101dd812a6fcc1e5d96efedc60b8735432 Mon Sep 17 00:00:00 2001 From: Jan Hubicka Date: Fri, 21 Apr 2023 15:53:21 +0200 Subject: Fix latent bug in loop header copying which forgets to update the loop header pointer gcc/ChangeLog: 2023-04-21 Jan Hubicka Ondrej Kubanek * tree-ssa-loop-ch.cc (ch_base::copy_headers): Update loop header and latch. --- gcc/tree-ssa-loop-ch.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'gcc/tree-ssa-loop-ch.cc') diff --git a/gcc/tree-ssa-loop-ch.cc b/gcc/tree-ssa-loop-ch.cc index ddf025c..560df39 100644 --- a/gcc/tree-ssa-loop-ch.cc +++ b/gcc/tree-ssa-loop-ch.cc @@ -542,6 +542,17 @@ ch_base::copy_headers (function *fun) } } + /* Update header of the loop. */ + loop->header = header; + /* Find correct latch. We only duplicate chain of conditionals so + there should be precisely two edges to the new header. One entry + edge and one to latch. */ + FOR_EACH_EDGE (e, ei, loop->header->preds) + if (header != e->src) + { + loop->latch = e->src; + break; + } /* Ensure that the latch and the preheader is simple (we know that they are not now, since there was the loop exit condition. */ split_edge (loop_preheader_edge (loop)); @@ -561,6 +572,8 @@ ch_base::copy_headers (function *fun) if (changed) { + if (flag_checking) + verify_loop_structure (); update_ssa (TODO_update_ssa); /* After updating SSA form perform CSE on the loop header copies. This is esp. required for the pass before -- cgit v1.1 From f7b9258e0d4127c1f441440c9a9c794295bbbe0f Mon Sep 17 00:00:00 2001 From: Jan Hubicka Date: Fri, 21 Apr 2023 18:13:35 +0200 Subject: Fix boostrap failure in tree-ssa-loop-ch.cc I managed to mix up patch and its WIP version in previous commit. This patch adds the missing edge iterator and also fixes a side case where new loop header would have multiple latches. gcc/ChangeLog: * tree-ssa-loop-ch.cc (ch_base::copy_headers): Fix previous commit. --- gcc/tree-ssa-loop-ch.cc | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'gcc/tree-ssa-loop-ch.cc') diff --git a/gcc/tree-ssa-loop-ch.cc b/gcc/tree-ssa-loop-ch.cc index 560df39..0025bc1 100644 --- a/gcc/tree-ssa-loop-ch.cc +++ b/gcc/tree-ssa-loop-ch.cc @@ -484,7 +484,10 @@ ch_base::copy_headers (function *fun) /* Ensure that the header will have just the latch as a predecessor inside the loop. */ if (!single_pred_p (exit->dest)) - exit = single_pred_edge (split_edge (exit)); + { + header = split_edge (exit); + exit = single_pred_edge (header); + } entry = loop_preheader_edge (loop); @@ -547,16 +550,17 @@ ch_base::copy_headers (function *fun) /* Find correct latch. We only duplicate chain of conditionals so there should be precisely two edges to the new header. One entry edge and one to latch. */ + edge_iterator ei; + edge e; FOR_EACH_EDGE (e, ei, loop->header->preds) if (header != e->src) { loop->latch = e->src; break; } - /* Ensure that the latch and the preheader is simple (we know that they - are not now, since there was the loop exit condition. */ - split_edge (loop_preheader_edge (loop)); - split_edge (loop_latch_edge (loop)); + /* Ensure that the latch is simple. */ + if (!single_succ_p (loop_latch_edge (loop)->src)) + split_edge (loop_latch_edge (loop)); if (dump_file && (dump_flags & TDF_DETAILS)) { @@ -572,8 +576,6 @@ ch_base::copy_headers (function *fun) if (changed) { - if (flag_checking) - verify_loop_structure (); update_ssa (TODO_update_ssa); /* After updating SSA form perform CSE on the loop header copies. This is esp. required for the pass before -- cgit v1.1 From cda246f8b421ba855a9e5f9d7bfcd0fc49b7bd4b Mon Sep 17 00:00:00 2001 From: Jan Hubicka Date: Sat, 22 Apr 2023 09:20:45 +0200 Subject: Update loop estimate after header duplication Loop header copying implements partial loop peelng. If all exits of the loop are peeled (which is the common case) the number of iterations decreases by 1. Without noting this, for loops iterating zero times, we end up re-peeling them later in the loop peeling pass which is wasteful. This patch commonizes the code for esitmate update and adds logic to detect when all (likely) exits were peeled by loop-ch. We are still wrong about update of estimate however: if the exits behave randomly with given probability, loop peeling does not decrease expected iteration counts, just decreases probability that loop will be executed. In this case we thus incorrectly decrease any_estimate. Doing so however at least help us to not peel or optimize hard the lop later. If the loop iterates precisely the estimated nuner of iterations. the estimate decreases, but we are wrong about decreasing the header frequncy. We already have logic that tries to prove that loop exit will not be taken in peeled out iterations and it may make sense to special case this. I also fixed problem where we had off by one error in iteration count updating. It makes perfect sense to expect loop to have 0 iterations. However if bounds drops to negative, we lose info about the loop behaviour (since we have no profile data reaching the loop body). Bootstrapped/regtested x86_64-linux, comitted. Honza gcc/ChangeLog: 2023-04-22 Jan Hubicka Ondrej Kubanek * cfgloopmanip.h (adjust_loop_info_after_peeling): Declare. * tree-ssa-loop-ch.cc (ch_base::copy_headers): Fix updating of loop profile and bounds after header duplication. * tree-ssa-loop-ivcanon.cc (adjust_loop_info_after_peeling): Break out from try_peel_loop; fix handling of 0 iterations. (try_peel_loop): Use adjust_loop_info_after_peeling. gcc/testsuite/ChangeLog: 2023-04-22 Jan Hubicka Ondrej Kubanek * gcc.dg/tree-ssa/peel1.c: Decrease number of peels by 1. * gcc.dg/unroll-8.c: Decrease loop iteration estimate. * gcc.dg/tree-prof/peel-2.c: New test. --- gcc/tree-ssa-loop-ch.cc | 112 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 102 insertions(+), 10 deletions(-) (limited to 'gcc/tree-ssa-loop-ch.cc') diff --git a/gcc/tree-ssa-loop-ch.cc b/gcc/tree-ssa-loop-ch.cc index 0025bc1..2fad2a3 100644 --- a/gcc/tree-ssa-loop-ch.cc +++ b/gcc/tree-ssa-loop-ch.cc @@ -381,7 +381,7 @@ unsigned int ch_base::copy_headers (function *fun) { basic_block header; - edge exit, entry; + edge exit, nonexit, entry; basic_block *bbs, *copied_bbs; unsigned n_bbs; unsigned bbs_size; @@ -453,8 +453,16 @@ ch_base::copy_headers (function *fun) the header to have just a single successor and copying up to postdominator. */ - exit = NULL; + nonexit = NULL; n_bbs = 0; + int nexits = 0; + profile_count exit_count = profile_count::zero (); + profile_count entry_count = profile_count::zero (); + edge e; + edge_iterator ei; + FOR_EACH_EDGE (e, ei, loop->header->preds) + if (e->src != loop->latch) + entry_count += e->count (); while (should_duplicate_loop_header_p (header, loop, &remaining_limit)) { if (dump_file && (dump_flags & TDF_DETAILS)) @@ -463,15 +471,23 @@ ch_base::copy_headers (function *fun) /* Find a successor of header that is inside a loop; i.e. the new header after the condition is copied. */ if (flow_bb_inside_loop_p (loop, EDGE_SUCC (header, 0)->dest)) - exit = EDGE_SUCC (header, 0); + { + nonexit = EDGE_SUCC (header, 0); + exit = EDGE_SUCC (header, 1); + } else - exit = EDGE_SUCC (header, 1); + { + nonexit = EDGE_SUCC (header, 1); + exit = EDGE_SUCC (header, 0); + } + exit_count += exit->count (); + nexits++; bbs[n_bbs++] = header; gcc_assert (bbs_size > n_bbs); - header = exit->dest; + header = nonexit->dest; } - if (!exit) + if (!nonexit) continue; if (dump_file && (dump_flags & TDF_DETAILS)) @@ -483,9 +499,9 @@ ch_base::copy_headers (function *fun) /* Ensure that the header will have just the latch as a predecessor inside the loop. */ - if (!single_pred_p (exit->dest)) + if (!single_pred_p (nonexit->dest)) { - header = split_edge (exit); + header = split_edge (nonexit); exit = single_pred_edge (header); } @@ -550,8 +566,6 @@ ch_base::copy_headers (function *fun) /* Find correct latch. We only duplicate chain of conditionals so there should be precisely two edges to the new header. One entry edge and one to latch. */ - edge_iterator ei; - edge e; FOR_EACH_EDGE (e, ei, loop->header->preds) if (header != e->src) { @@ -569,7 +583,85 @@ ch_base::copy_headers (function *fun) else fprintf (dump_file, "Loop %d is still not do-while loop.\n", loop->num); + fprintf (dump_file, "Exit count: "); + exit_count.dump (dump_file); + fprintf (dump_file, "\nEntry count: "); + entry_count.dump (dump_file); + fprintf (dump_file, "\n"); + } + + /* We possibly decreased number of itrations by 1. */ + auto_vec exits = get_loop_exit_edges (loop); + bool precise = (nexits == (int) exits.length ()); + if (!get_max_loop_iterations_int (loop)) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, "Loop %d no longer loops.\n", loop->num); + /* TODO: We can unloop like in tree-ssa-loop-ivcanon. */ + precise = false; + } + /* Check that loop may not terminate in other way than via + basic blocks we duplicated. */ + if (precise) + { + basic_block *bbs = get_loop_body (loop); + for (unsigned i = 0; i < loop->num_nodes && precise; ++i) + { + basic_block bb = bbs[i]; + bool found_exit = false; + FOR_EACH_EDGE (e, ei, bb->succs) + if (!flow_bb_inside_loop_p (loop, e->dest)) + { + found_exit = true; + break; + } + /* If BB has exit, it was duplicated. */ + if (found_exit) + continue; + /* Give up on irreducible loops. */ + if (bb->flags & BB_IRREDUCIBLE_LOOP) + { + precise = false; + break; + } + /* Check that inner loops are finite. */ + for (class loop *l = bb->loop_father; l != loop && precise; + l = loop_outer (l)) + if (!l->finite_p) + { + precise = false; + break; + } + /* Verify that there is no statement that may be terminate + execution in a way not visible to CFG. */ + for (gimple_stmt_iterator bsi = gsi_start_bb (bb); + !gsi_end_p (bsi); gsi_next (&bsi)) + if (stmt_can_terminate_bb_p (gsi_stmt (bsi))) + precise = false; + } + } + if (precise) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, + "Peeled all exits:" + " decreased number of iterations of loop %d by 1.\n", + loop->num); + adjust_loop_info_after_peeling (loop, 1, true); } + else if (exit_count >= entry_count.apply_scale (9, 10)) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, + "Peeled likely exits: likely decreased number " + "of iterations of loop %d by 1.\n", loop->num); + adjust_loop_info_after_peeling (loop, 1, false); + } + else if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, + "Not decreased number" + " of iterations of loop %d; likely exits remains.\n", + loop->num); changed = true; } -- cgit v1.1 From db29daa5e627c185aa599aa0dad093ae3a86317c Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Tue, 25 Apr 2023 16:38:44 +0200 Subject: More last_stmt removal This adjusts more users of last_stmt where it is clear that debug stmt skipping is unnecessary. In most cases this also allowed significant code simplification. gcc/c/ * gimple-parser.cc (c_parser_parse_gimple_body): Avoid last_stmt. gcc/ * gimple-range-path.cc (path_range_query::compute_outgoing_relations): Avoid last_stmt. * ipa-pure-const.cc (pass_nothrow::execute): Likewise. * predict.cc (apply_return_prediction): Likewise. * sese.cc (set_ifsese_condition): Likewise. Simplify. * tree-cfg.cc (assert_unreachable_fallthru_edge_p): Avoid last_stmt. (make_edges_bb): Likewise. (make_cond_expr_edges): Likewise. (end_recording_case_labels): Likewise. (make_gimple_asm_edges): Likewise. (cleanup_dead_labels): Likewise. (group_case_labels): Likewise. (gimple_can_merge_blocks_p): Likewise. (gimple_merge_blocks): Likewise. (find_taken_edge): Likewise. Also handle empty fallthru blocks. (gimple_duplicate_sese_tail): Avoid last_stmt. (find_loop_dist_alias): Likewise. (gimple_block_ends_with_condjump_p): Likewise. (gimple_purge_dead_eh_edges): Likewise. (gimple_purge_dead_abnormal_call_edges): Likewise. (pass_warn_function_return::execute): Likewise. (execute_fixup_cfg): Likewise. * tree-eh.cc (redirect_eh_edge_1): Likewise. (pass_lower_resx::execute): Likewise. (pass_lower_eh_dispatch::execute): Likewise. (cleanup_empty_eh): Likewise. * tree-if-conv.cc (if_convertible_bb_p): Likewise. (predicate_bbs): Likewise. (ifcvt_split_critical_edges): Likewise. * tree-loop-distribution.cc (create_edge_for_control_dependence): Likewise. (loop_distribution::transform_reduction_loop): Likewise. * tree-parloops.cc (transform_to_exit_first_loop_alt): Likewise. (try_transform_to_exit_first_loop_alt): Likewise. (transform_to_exit_first_loop): Likewise. (create_parallel_loop): Likewise. * tree-scalar-evolution.cc (get_loop_exit_condition): Likewise. * tree-ssa-dce.cc (mark_last_stmt_necessary): Likewise. (eliminate_unnecessary_stmts): Likewise. * tree-ssa-dom.cc (dom_opt_dom_walker::set_global_ranges_from_unreachable_edges): Likewise. * tree-ssa-ifcombine.cc (ifcombine_ifandif): Likewise. (pass_tree_ifcombine::execute): Likewise. * tree-ssa-loop-ch.cc (entry_loop_condition_is_static): Likewise. (should_duplicate_loop_header_p): Likewise. * tree-ssa-loop-ivcanon.cc (create_canonical_iv): Likewise. (tree_estimate_loop_size): Likewise. (try_unroll_loop_completely): Likewise. * tree-ssa-loop-ivopts.cc (tree_ssa_iv_optimize_loop): Likewise. * tree-ssa-loop-manip.cc (ip_normal_pos): Likewise. (canonicalize_loop_ivs): Likewise. * tree-ssa-loop-niter.cc (determine_value_range): Likewise. (bound_difference): Likewise. (number_of_iterations_popcount): Likewise. (number_of_iterations_cltz): Likewise. (number_of_iterations_cltz_complement): Likewise. (simplify_using_initial_conditions): Likewise. (number_of_iterations_exit_assumptions): Likewise. (loop_niter_by_eval): Likewise. (estimate_numbers_of_iterations): Likewise. --- gcc/tree-ssa-loop-ch.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gcc/tree-ssa-loop-ch.cc') diff --git a/gcc/tree-ssa-loop-ch.cc b/gcc/tree-ssa-loop-ch.cc index 2fad2a3..73b24c9 100644 --- a/gcc/tree-ssa-loop-ch.cc +++ b/gcc/tree-ssa-loop-ch.cc @@ -66,7 +66,7 @@ static bool entry_loop_condition_is_static (class loop *l, gimple_ranger *ranger) { edge e = loop_preheader_edge (l); - gcond *last = safe_dyn_cast (last_stmt (e->dest)); + gcond *last = safe_dyn_cast (*gsi_last_bb (e->dest)); if (!last) return false; @@ -133,7 +133,7 @@ should_duplicate_loop_header_p (basic_block header, class loop *loop, return false; } - gcond *last = safe_dyn_cast (last_stmt (header)); + gcond *last = safe_dyn_cast (*gsi_last_bb (header)); if (!last) { if (dump_file && (dump_flags & TDF_DETAILS)) -- cgit v1.1 From f2d6beb7a4ddf18dd95fdcc336181a8702a9f55f Mon Sep 17 00:00:00 2001 From: Jan Hubicka Date: Thu, 27 Apr 2023 15:49:37 +0200 Subject: Unloop loops that no longer loops in tree-ssa-loop-ch I noticed this after adding sanity check that the upper bound on number of iterations never drop to -1. It seems to be relatively common case (happening few hundred times in testsuite and also during bootstrap) that loop-ch duplicates enough so the loop itself no longer loops. This is later detected in loop unrolling but since we test the number of iterations anyway it seems better to do that earlier. * cfgloopmanip.h (unloop_loops): Export. * tree-ssa-loop-ch.cc (ch_base::copy_headers): Unloop loops that no longer loop. * tree-ssa-loop-ivcanon.cc (unloop_loops): Export; do not free vectors of loops to unloop. (canonicalize_induction_variables): Free vectors here. (tree_unroll_loops_completely): Free vectors here. --- gcc/tree-ssa-loop-ch.cc | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) (limited to 'gcc/tree-ssa-loop-ch.cc') diff --git a/gcc/tree-ssa-loop-ch.cc b/gcc/tree-ssa-loop-ch.cc index 73b24c9..83c2c1c 100644 --- a/gcc/tree-ssa-loop-ch.cc +++ b/gcc/tree-ssa-loop-ch.cc @@ -396,6 +396,8 @@ ch_base::copy_headers (function *fun) auto_vec candidates; auto_vec > copied; + auto_vec loops_to_unloop; + auto_vec loops_to_unloop_nunroll; mark_dfs_back_edges (); gimple_ranger *ranger = new gimple_ranger; @@ -408,6 +410,14 @@ ch_base::copy_headers (function *fun) "Analyzing loop %i\n", loop->num); header = loop->header; + if (!get_max_loop_iterations_int (loop)) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, "Loop %d never loops.\n", loop->num); + loops_to_unloop.safe_push (loop); + loops_to_unloop_nunroll.safe_push (0); + continue; + } /* If the loop is already a do-while style one (either because it was written as such, or because jump threading transformed it into one), @@ -593,13 +603,6 @@ ch_base::copy_headers (function *fun) /* We possibly decreased number of itrations by 1. */ auto_vec exits = get_loop_exit_edges (loop); bool precise = (nexits == (int) exits.length ()); - if (!get_max_loop_iterations_int (loop)) - { - if (dump_file && (dump_flags & TDF_DETAILS)) - fprintf (dump_file, "Loop %d no longer loops.\n", loop->num); - /* TODO: We can unloop like in tree-ssa-loop-ivcanon. */ - precise = false; - } /* Check that loop may not terminate in other way than via basic blocks we duplicated. */ if (precise) @@ -640,7 +643,15 @@ ch_base::copy_headers (function *fun) precise = false; } } - if (precise) + if (precise + && get_max_loop_iterations_int (loop) == 1) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, "Loop %d no longer loops.\n", loop->num); + loops_to_unloop.safe_push (loop); + loops_to_unloop_nunroll.safe_push (0); + } + else if (precise) { if (dump_file && (dump_flags & TDF_DETAILS)) fprintf (dump_file, @@ -688,6 +699,12 @@ ch_base::copy_headers (function *fun) BITMAP_FREE (exit_bbs); } } + if (!loops_to_unloop.is_empty ()) + { + bool irred_invalidated; + unloop_loops (loops_to_unloop, loops_to_unloop_nunroll, NULL, &irred_invalidated); + changed = true; + } free (bbs); free (copied_bbs); -- cgit v1.1 From cb779afeff204fdb278e55006ea7d269a4606d85 Mon Sep 17 00:00:00 2001 From: Aldy Hernandez Date: Thu, 2 Mar 2023 16:34:46 +0100 Subject: Conversion to irange wide_int API. This converts the irange API to use wide_ints exclusively, along with its users. This patch will slow down VRP, as there will be more useless wide_int to tree conversions. However, this slowdown is only temporary, as a follow-up patch will convert the internal representation of iranges to wide_ints for a net overall gain in performance. gcc/ChangeLog: * fold-const.cc (expr_not_equal_to): Convert to irange wide_int API. * gimple-fold.cc (size_must_be_zero_p): Same. * gimple-loop-versioning.cc (loop_versioning::prune_loop_conditions): Same. * gimple-range-edge.cc (gcond_edge_range): Same. (gimple_outgoing_range::calc_switch_ranges): Same. * gimple-range-fold.cc (adjust_imagpart_expr): Same. (adjust_realpart_expr): Same. (fold_using_range::range_of_address): Same. (fold_using_range::relation_fold_and_or): Same. * gimple-range-gori.cc (gori_compute::gori_compute): Same. (range_is_either_true_or_false): Same. * gimple-range-op.cc (cfn_toupper_tolower::get_letter_range): Same. (cfn_clz::fold_range): Same. (cfn_ctz::fold_range): Same. * gimple-range-tests.cc (class test_expr_eval): Same. * gimple-ssa-warn-alloca.cc (alloca_call_type): Same. * ipa-cp.cc (ipa_value_range_from_jfunc): Same. (propagate_vr_across_jump_function): Same. (decide_whether_version_node): Same. * ipa-prop.cc (ipa_get_value_range): Same. * ipa-prop.h (ipa_range_set_and_normalize): Same. * range-op.cc (get_shift_range): Same. (value_range_from_overflowed_bounds): Same. (value_range_with_overflow): Same. (create_possibly_reversed_range): Same. (equal_op1_op2_relation): Same. (not_equal_op1_op2_relation): Same. (lt_op1_op2_relation): Same. (le_op1_op2_relation): Same. (gt_op1_op2_relation): Same. (ge_op1_op2_relation): Same. (operator_mult::op1_range): Same. (operator_exact_divide::op1_range): Same. (operator_lshift::op1_range): Same. (operator_rshift::op1_range): Same. (operator_cast::op1_range): Same. (operator_logical_and::fold_range): Same. (set_nonzero_range_from_mask): Same. (operator_bitwise_or::op1_range): Same. (operator_bitwise_xor::op1_range): Same. (operator_addr_expr::fold_range): Same. (pointer_plus_operator::wi_fold): Same. (pointer_or_operator::op1_range): Same. (INT): Same. (UINT): Same. (INT16): Same. (UINT16): Same. (SCHAR): Same. (UCHAR): Same. (range_op_cast_tests): Same. (range_op_lshift_tests): Same. (range_op_rshift_tests): Same. (range_op_bitwise_and_tests): Same. (range_relational_tests): Same. * range.cc (range_zero): Same. (range_nonzero): Same. * range.h (range_true): Same. (range_false): Same. (range_true_and_false): Same. * tree-data-ref.cc (split_constant_offset_1): Same. * tree-ssa-loop-ch.cc (entry_loop_condition_is_static): Same. * tree-ssa-loop-unswitch.cc (struct unswitch_predicate): Same. (find_unswitching_predicates_for_bb): Same. * tree-ssa-phiopt.cc (value_replacement): Same. * tree-ssa-threadbackward.cc (back_threader::find_taken_edge_cond): Same. * tree-ssanames.cc (ssa_name_has_boolean_range): Same. * tree-vrp.cc (find_case_label_range): Same. * value-query.cc (range_query::get_tree_range): Same. * value-range.cc (irange::set_nonnegative): Same. (frange::contains_p): Same. (frange::singleton_p): Same. (frange::internal_singleton_p): Same. (irange::irange_set): Same. (irange::irange_set_1bit_anti_range): Same. (irange::irange_set_anti_range): Same. (irange::set): Same. (irange::operator==): Same. (irange::singleton_p): Same. (irange::contains_p): Same. (irange::set_range_from_nonzero_bits): Same. (DEFINE_INT_RANGE_INSTANCE): Same. (INT): Same. (UINT): Same. (SCHAR): Same. (UINT128): Same. (UCHAR): Same. (range): New. (tree_range): New. (range_int): New. (range_uint): New. (range_uint128): New. (range_uchar): New. (range_char): New. (build_range3): Convert to irange wide_int API. (range_tests_irange3): Same. (range_tests_int_range_max): Same. (range_tests_strict_enum): Same. (range_tests_misc): Same. (range_tests_nonzero_bits): Same. (range_tests_nan): Same. (range_tests_signed_zeros): Same. * value-range.h (Value_Range::Value_Range): Same. (irange::set): Same. (irange::nonzero_p): Same. (irange::contains_p): Same. (range_includes_zero_p): Same. (irange::set_nonzero): Same. (irange::set_zero): Same. (contains_zero_p): Same. (frange::contains_p): Same. * vr-values.cc (simplify_using_ranges::op_with_boolean_value_range_p): Same. (bounds_of_var_in_loop): Same. (simplify_using_ranges::legacy_fold_cond_overflow): Same. --- gcc/tree-ssa-loop-ch.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'gcc/tree-ssa-loop-ch.cc') diff --git a/gcc/tree-ssa-loop-ch.cc b/gcc/tree-ssa-loop-ch.cc index 83c2c1c..692e8ce 100644 --- a/gcc/tree-ssa-loop-ch.cc +++ b/gcc/tree-ssa-loop-ch.cc @@ -79,15 +79,15 @@ entry_loop_condition_is_static (class loop *l, gimple_ranger *ranger) if (!loop_exit_edge_p (l, true_e) && !loop_exit_edge_p (l, false_e)) return false; - tree desired_static_value; + int_range<1> desired_static_range; if (loop_exit_edge_p (l, true_e)) - desired_static_value = boolean_false_node; + desired_static_range = range_false (); else - desired_static_value = boolean_true_node; + desired_static_range = range_true (); int_range<2> r; edge_range_query (r, e, last, *ranger); - return r == int_range<2> (desired_static_value, desired_static_value); + return r == desired_static_range; } /* Check whether we should duplicate HEADER of LOOP. At most *LIMIT -- 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-ch.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gcc/tree-ssa-loop-ch.cc') diff --git a/gcc/tree-ssa-loop-ch.cc b/gcc/tree-ssa-loop-ch.cc index 692e8ce..7fdef3b 100644 --- a/gcc/tree-ssa-loop-ch.cc +++ b/gcc/tree-ssa-loop-ch.cc @@ -244,7 +244,7 @@ should_duplicate_loop_header_p (basic_block header, class loop *loop, static bool do_while_loop_p (class loop *loop) { - gimple *stmt = last_stmt (loop->latch); + gimple *stmt = last_nondebug_stmt (loop->latch); /* If the latch of the loop is not empty, it is not a do-while loop. */ if (stmt -- cgit v1.1 From 2270f4fdaa0331b5c7fa53baeb7fd0038639a73f Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Tue, 13 Jun 2023 12:39:46 +0200 Subject: Fix memory leak in loop header copying * tree-ssa-loop-ch.cc (ch_base::copy_headers): Free loop BBs. --- gcc/tree-ssa-loop-ch.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'gcc/tree-ssa-loop-ch.cc') diff --git a/gcc/tree-ssa-loop-ch.cc b/gcc/tree-ssa-loop-ch.cc index 7fdef3b..22252be 100644 --- a/gcc/tree-ssa-loop-ch.cc +++ b/gcc/tree-ssa-loop-ch.cc @@ -642,6 +642,7 @@ ch_base::copy_headers (function *fun) if (stmt_can_terminate_bb_p (gsi_stmt (bsi))) precise = false; } + free (bbs); } if (precise && get_max_loop_iterations_int (loop) == 1) -- cgit v1.1