public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/marxin/heads/loop-unswitching-switch)] Clean up switches.
@ 2021-08-31 14:34 Martin Liska
0 siblings, 0 replies; only message in thread
From: Martin Liska @ 2021-08-31 14:34 UTC (permalink / raw)
To: gcc-cvs
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 {
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-08-31 14:34 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-31 14:34 [gcc(refs/users/marxin/heads/loop-unswitching-switch)] Clean up switches Martin Liska
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).