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-unswitching-switch)] Clean up switches. Date: Tue, 31 Aug 2021 14:34:04 +0000 (GMT) [thread overview] Message-ID: <20210831143404.A53DF3857C4F@sourceware.org> (raw) https://gcc.gnu.org/g:78d57af41018b0e81a97ac0dcfba1faacfc0d708 commit 78d57af41018b0e81a97ac0dcfba1faacfc0d708 Author: Martin Liska <mliska@suse.cz> 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 <gswitch *> (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 {
reply other threads:[~2021-08-31 14:34 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20210831143404.A53DF3857C4F@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).