From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1851) id A53DF3857C4F; Tue, 31 Aug 2021 14:34:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A53DF3857C4F 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-unswitching-switch)] Clean up switches. X-Act-Checkin: gcc X-Git-Author: Martin Liska X-Git-Refname: refs/users/marxin/heads/loop-unswitching-switch X-Git-Oldrev: 0c4194dab17ccad6993e4f84f01ba4f908f69ab5 X-Git-Newrev: 78d57af41018b0e81a97ac0dcfba1faacfc0d708 Message-Id: <20210831143404.A53DF3857C4F@sourceware.org> Date: Tue, 31 Aug 2021 14:34:04 +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: Tue, 31 Aug 2021 14:34:04 -0000 https://gcc.gnu.org/g:78d57af41018b0e81a97ac0dcfba1faacfc0d708 commit 78d57af41018b0e81a97ac0dcfba1faacfc0d708 Author: Martin Liska Date: Tue Aug 31 16:15:53 2021 +0200 Clean up switches. Diff: --- gcc/tree-ssa-loop-unswitch.c | 52 ++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/gcc/tree-ssa-loop-unswitch.c b/gcc/tree-ssa-loop-unswitch.c index 762c5bde8b2..3e3c226da73 100644 --- a/gcc/tree-ssa-loop-unswitch.c +++ b/gcc/tree-ssa-loop-unswitch.c @@ -86,6 +86,7 @@ static bool used_outside_loop_p (class loop *, tree); static void hoist_guard (class loop *, edge); static bool check_exit_phi (class loop *); static tree get_vop_from_header (class loop *); +static void clean_up_switches (void); /* Main entry point. Perform loop unswitching on all suitable loops. */ @@ -106,22 +107,7 @@ tree_ssa_unswitch_loops (void) if (changed) { - basic_block bb; - edge_iterator ei; - edge e; - - if (dump_file) - dump_function_to_file (cfun->decl, dump_file, dump_flags); - - FOR_EACH_BB_FN (bb, cfun) - FOR_EACH_EDGE (e, ei, bb->succs) - if (e->flags & EDGE_IGNORE) - { - if (dump_file) - fprintf (dump_file, "%d->%d\n", e->src->index, e->dest->index); - } - - + clean_up_switches (); return TODO_cleanup_cfg; } return 0; @@ -1050,6 +1036,40 @@ check_exit_phi (class loop *loop) return true; } +static void +clean_up_switches (void) +{ + basic_block bb; + edge_iterator ei; + edge e; + + FOR_EACH_BB_FN (bb, cfun) + { + gimple *last = last_stmt (bb); + if (gswitch *stmt = safe_dyn_cast (last)) + { + unsigned nlabels = gimple_switch_num_labels (stmt); + unsigned index = 1; + for (unsigned i = 1; i < nlabels; ++i) + { + tree lab = gimple_switch_label (stmt, i); + basic_block dest = label_to_block (cfun, CASE_LABEL (lab)); + edge e = find_edge (gimple_bb (stmt), dest); + if (e->flags & EDGE_IGNORE) + remove_edge (e); + else + { + gimple_switch_set_label (stmt, index, lab); + ++index; + } + } + + if (index != nlabels) + gimple_switch_set_num_labels (stmt, index); + } + } +} + /* Loop unswitching pass. */ namespace {