From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1851) id 16BA43858016; Wed, 8 Dec 2021 18:25:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 16BA43858016 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Martin Liska To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/marxin/heads/loop-unswitch-improvement-v7)] WIP xx. X-Act-Checkin: gcc X-Git-Author: Martin Liska X-Git-Refname: refs/users/marxin/heads/loop-unswitch-improvement-v7 X-Git-Oldrev: 0dcb29168804c2e4f7162b4c623574e89bcee770 X-Git-Newrev: f42f79712b44eb5b6076cfc9dfb653427c015c85 Message-Id: <20211208182547.16BA43858016@sourceware.org> Date: Wed, 8 Dec 2021 18:25:47 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Dec 2021 18:25:47 -0000 https://gcc.gnu.org/g:f42f79712b44eb5b6076cfc9dfb653427c015c85 commit f42f79712b44eb5b6076cfc9dfb653427c015c85 Author: Martin Liska 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 ();