public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Martin Liska <marxin@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/marxin/heads/loop-unswitch-improvement-v7)] WIP xx. Date: Thu, 9 Dec 2021 12:47:51 +0000 (GMT) [thread overview] Message-ID: <20211209124751.58EDF3858426@sourceware.org> (raw) https://gcc.gnu.org/g:76e35cf8716b9281ee7eb5ed6f30ff1c37cae0d4 commit 76e35cf8716b9281ee7eb5ed6f30ff1c37cae0d4 Author: Martin Liska <mliska@suse.cz> Date: Wed Dec 1 10:03:35 2021 +0100 WIP xx. Diff: --- gcc/tree-ssa-loop-unswitch.c | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/gcc/tree-ssa-loop-unswitch.c b/gcc/tree-ssa-loop-unswitch.c index bd71e9d9fbd..1bcbb2ef3b2 100644 --- a/gcc/tree-ssa-loop-unswitch.c +++ b/gcc/tree-ssa-loop-unswitch.c @@ -356,30 +356,40 @@ find_unswitching_predicates_for_bb (basic_block bb, class loop *loop, } static void -combine_range (predicate_vector &predicate_path, tree index, irange &path_range) +merge_last (predicate_vector &predicate_path) { - bool first = true; + unswitch_predicate *last_predicate = predicate_path.last ().first; - for (auto p: predicate_path) + for (int i = predicate_path.length () - 2; i >= 0; i--) { - unswitch_predicate *predicate = p.first; - bool true_edge = p.second; + unswitch_predicate *predicate = predicate_path[i].first; + bool true_edge = predicate_path[i].second; - if (operand_equal_p (predicate->lhs, index, 0)) + if (operand_equal_p (predicate->lhs, last_predicate->lhs, 0)) { irange &other = true_edge ? predicate->true_range : predicate->false_range; - if (first) - { - first = false; - path_range = other; - } - else - path_range.intersect (other); + last_predicate->true_range.intersect (other); + last_predicate->false_range.intersect (other); + return; } } } +void +find_range_for_lhs (predicate_vector &predicate_path, tree lhs, + int_range_max &range) +{ + for (int i = predicate_path.length () - 1; i >= 0; i--) + { + unswitch_predicate *predicate = predicate_path[i].first; + bool true_edge = predicate_path[i].second; + + if (operand_equal_p (predicate->lhs, lhs, 0)) + range = true_edge ? predicate->true_range : predicate->false_range; + } +} + /* Simplifies COND using checks in front of the entry of the LOOP. Utilize both symbolic expressions and value ranges calculated by Ranger. */ @@ -405,7 +415,7 @@ evaluate_control_stmt_using_entry_checks (gimple *stmt, { int_range_max r; int_range_max path_range; - combine_range (predicate_path, lhs, path_range); + find_range_for_lhs (predicate_path, lhs, path_range); if (!path_range.undefined_p () && fold_range (r, stmt, path_range) && r.singleton_p ()) @@ -542,11 +552,13 @@ evaluate_loop_insns_for_predicate (class loop *loop, basic_block *bbs, predicate_path.safe_push (std::make_pair (predicate, true)); unsigned true_loop_cost = evaluate_insns (loop, bbs, predicate_path, reachable_flag); + merge_last (predicate_path); predicate_path.pop (); predicate_path.safe_push (std::make_pair (predicate, false)); unsigned false_loop_cost = evaluate_insns (loop, bbs, predicate_path, reachable_flag); + merge_last (predicate_path); predicate_path.pop (); return true_loop_cost + false_loop_cost; @@ -670,11 +682,13 @@ tree_unswitch_single_loop (class loop *loop, int num, /* Invoke itself on modified loops. */ predicate_path.safe_push (std::make_pair (predicate, false)); + merge_last (predicate_path); changed |= simplify_loop_version (nloop, predicate_path); tree_unswitch_single_loop (nloop, num + 1, predicate_path, budget); predicate_path.pop (); predicate_path.safe_push (std::make_pair (predicate, true)); + merge_last (predicate_path); changed |= simplify_loop_version (loop, predicate_path); tree_unswitch_single_loop (loop, num + 1, predicate_path, budget); predicate_path.pop ();
next reply other threads:[~2021-12-09 12:47 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-12-09 12:47 Martin Liska [this message] -- strict thread matches above, loose matches on Subject: below -- 2021-12-08 18:25 Martin Liska 2021-12-08 10:17 Martin Liska 2021-12-07 16:49 Martin Liska
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20211209124751.58EDF3858426@sourceware.org \ --to=marxin@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).