From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1851) id 47BAC3858410; Thu, 6 Jan 2022 16:30:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 47BAC3858410 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/devel/loop-unswitch-support-switches] Apply reviewer's comments. X-Act-Checkin: gcc X-Git-Author: Martin Liska X-Git-Refname: refs/heads/devel/loop-unswitch-support-switches X-Git-Oldrev: 1fdb1e9a24e7535f324a515327e22dd381faf1b8 X-Git-Newrev: 401de0fee5dfd386079caed7e8fb61e9afced477 Message-Id: <20220106163030.47BAC3858410@sourceware.org> Date: Thu, 6 Jan 2022 16:30:30 +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: Thu, 06 Jan 2022 16:30:30 -0000 https://gcc.gnu.org/g:401de0fee5dfd386079caed7e8fb61e9afced477 commit 401de0fee5dfd386079caed7e8fb61e9afced477 Author: Martin Liska Date: Thu Jan 6 17:30:08 2022 +0100 Apply reviewer's comments. Diff: --- gcc/doc/invoke.texi | 3 - gcc/params.opt | 4 -- gcc/tree-ssa-loop-unswitch.c | 143 ++++++++++++++++++++----------------------- 3 files changed, 66 insertions(+), 84 deletions(-) diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 04820656ffa..98589738d62 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -13890,9 +13890,6 @@ The maximum depth of a loop nest suitable for complete peeling. @item max-unswitch-insns The maximum number of insns of an unswitched loop. -@item max-unswitch-level -The maximum number of branches unswitched in a single loop. - @item lim-expensive The minimum cost of an expensive expression in the loop invariant motion. diff --git a/gcc/params.opt b/gcc/params.opt index 665071fbed1..91f845aaae6 100644 --- a/gcc/params.opt +++ b/gcc/params.opt @@ -741,10 +741,6 @@ The maximum number of instructions to consider to unroll in a loop. Common Joined UInteger Var(param_max_unswitch_insns) Init(50) Param Optimization The maximum number of insns of an unswitched loop. --param=max-unswitch-level= -Common Joined UInteger Var(param_max_unswitch_level) Init(3) Param Optimization -The maximum number of unswitchings in a single loop. - -param=max-variable-expansions-in-unroller= Common Joined UInteger Var(param_max_variable_expansions) Init(1) Param Optimization If -fvariable-expansion-in-unroller is used, the maximum number of times that an individual variable will be expanded during loop unrolling. diff --git a/gcc/tree-ssa-loop-unswitch.c b/gcc/tree-ssa-loop-unswitch.c index b21eed5ca51..c164fe2faa0 100644 --- a/gcc/tree-ssa-loop-unswitch.c +++ b/gcc/tree-ssa-loop-unswitch.c @@ -448,29 +448,29 @@ find_unswitching_predicates_for_bb (basic_block bb, class loop *loop, tree lab = gimple_switch_label (stmt, i); basic_block dest = label_to_block (cfun, CASE_LABEL (lab)); edge e2 = find_edge (gimple_bb (stmt), dest); - if (e == e2) + if (e != e2) + continue; + + tree cmp; + if (CASE_HIGH (lab) != NULL_TREE) { - tree cmp; - if (CASE_HIGH (lab) != NULL_TREE) - { - tree cmp1 = build2 (GE_EXPR, boolean_type_node, idx, - CASE_LOW (lab)); - tree cmp2 = build2 (LE_EXPR, boolean_type_node, idx, - CASE_HIGH (lab)); - cmp = build2 (BIT_AND_EXPR, boolean_type_node, cmp1, - cmp2); - } - else - cmp = build2 (EQ_EXPR, boolean_type_node, idx, - CASE_LOW (lab)); - - /* Combine the expression with the existing one. */ - if (expr == NULL_TREE) - expr = cmp; - else - expr = build2 (BIT_IOR_EXPR, boolean_type_node, expr, - cmp); + tree cmp1 = build2 (GE_EXPR, boolean_type_node, idx, + CASE_LOW (lab)); + tree cmp2 = build2 (LE_EXPR, boolean_type_node, idx, + CASE_HIGH (lab)); + cmp = fold_build2 (BIT_AND_EXPR, boolean_type_node, cmp1, + cmp2); } + else + cmp = fold_build2 (EQ_EXPR, boolean_type_node, idx, + CASE_LOW (lab)); + + /* Combine the expression with the existing one. */ + if (expr == NULL_TREE) + expr = cmp; + else + expr = fold_build2 (BIT_IOR_EXPR, boolean_type_node, expr, + cmp); } if (expr != NULL_TREE) @@ -661,52 +661,52 @@ simplify_loop_version (class loop *loop, predicate_vector &predicate_path, for (unsigned i = 0; i != loop->num_nodes; i++) { vec &predicates = get_predicates_for_bb (bbs[i]); - if (!predicates.is_empty ()) + if (predicates.is_empty ()) + continue; + + hash_set ignored_edges; + gimple *stmt = last_stmt (bbs[i]); + tree folded = evaluate_control_stmt_using_entry_checks (stmt, + predicate_path, + ignored_edge_flag, + &ignored_edges); + + gcond *cond = dyn_cast (stmt); + gswitch *swtch = dyn_cast (stmt); + + if (cond != NULL + && folded != NULL_TREE) { - hash_set ignored_edges; - gimple *stmt = last_stmt (bbs[i]); - tree folded = evaluate_control_stmt_using_entry_checks (stmt, - predicate_path, - ignored_edge_flag, - &ignored_edges); - - gcond *cond = dyn_cast (stmt); - gswitch *swtch = dyn_cast (stmt); - - if (cond != NULL - && folded != NULL_TREE) - { - /* Remove path. */ - if (integer_nonzerop (folded)) - gimple_cond_set_condition_from_tree (cond, boolean_true_node); - else - gimple_cond_set_condition_from_tree (cond, boolean_false_node); + /* Remove path. */ + if (integer_nonzerop (folded)) + gimple_cond_set_condition_from_tree (cond, boolean_true_node); + else + gimple_cond_set_condition_from_tree (cond, boolean_false_node); - gimple_set_uid (cond, 0); - update_stmt (cond); - changed = true; - } - else if (swtch != NULL) - { - edge e; - edge_iterator ei; - FOR_EACH_EDGE (e, ei, bbs[i]->succs) - if (ignored_edges.contains (e)) - e->flags = ignored_edge_flag; + gimple_set_uid (cond, 0); + update_stmt (cond); + changed = true; + } + else if (swtch != NULL) + { + edge e; + edge_iterator ei; + FOR_EACH_EDGE (e, ei, bbs[i]->succs) + if (ignored_edges.contains (e)) + e->flags = ignored_edge_flag; - for (unsigned j = 0; j < predicates.length (); j++) - { - edge e = EDGE_SUCC (bbs[i], predicates[j]->edge_index); - if (ignored_edges.contains (e)) - predicates[j]->handled = true; - } + for (unsigned j = 0; j < predicates.length (); j++) + { + edge e = EDGE_SUCC (bbs[i], predicates[j]->edge_index); + if (ignored_edges.contains (e)) + predicates[j]->handled = true; + } - if (folded) - { - gimple_switch_set_index (swtch, folded); - update_stmt (swtch); - changed = true; - } + if (folded) + { + gimple_switch_set_index (swtch, folded); + update_stmt (swtch); + changed = true; } } } @@ -861,13 +861,6 @@ tree_unswitch_single_loop (class loop *loop, int num, unswitch_predicate *predicate = NULL; basic_block bb = NULL; - if (num > param_max_unswitch_level) - { - if (dump_enabled_p ()) - dump_printf_loc (MSG_MISSED_OPTIMIZATION, loc, - "Not unswitching anymore, hit max level\n"); - goto exit; - } bbs = get_loop_body (loop); @@ -1473,6 +1466,8 @@ static void clean_up_after_unswitching (const auto_edge_flag &ignored_edge_flag) { basic_block bb; + edge e; + edge_iterator ei; FOR_EACH_BB_FN (bb, cfun) { @@ -1500,14 +1495,8 @@ clean_up_after_unswitching (const auto_edge_flag &ignored_edge_flag) if (index != nlabels) gimple_switch_set_num_labels (stmt, index); } - } - - /* Clean up the ignored_edge_flag from edges. */ - FOR_EACH_BB_FN (bb, cfun) - { - edge e; - edge_iterator ei; + /* Clean up the ignored_edge_flag from edges. */ FOR_EACH_EDGE (e, ei, bb->succs) e->flags &= ~ignored_edge_flag; }