[PATCH] Loop unswitching: support gswitch statements.

Richard Biener richard.guenther@gmail.com
Fri Nov 26 08:12:54 GMT 2021


On Wed, Nov 24, 2021 at 3:32 PM Martin Liška <mliska@suse.cz> wrote:
>
> On 11/24/21 15:14, Martin Liška wrote:
> > It likely miscompiles gcc.dg/loop-unswitch-5.c, working on that..
>
> Fixed that in the updated version.

Function level comments need updating it seems.

+static unsigned
+evaluate_insns (class loop *loop,  basic_block *bbs,
+               predicate_vector &predicate_path,
+               auto_bb_flag &reachable_flag)
+{
+  auto_vec<basic_block> worklist (loop->num_nodes);
+  worklist.quick_push (bbs[0]);
...

so when adding gswitch support the easiest way to make

+      FOR_EACH_EDGE (e, ei, bb->succs)
+       {
...
+           {
+             worklist.safe_push (dest);
+             dest->flags |= reachable_flag;

work is when the gcond/gswitch simplification would mark
outgoing edges as (non-)executable.  For gswitch this
could be achieved by iterating over the case labels and
intersecting that with the range while for gcond it's a
matter of setting an edge flag instead of returning true/false.
I'd call the common function evaluate_control_stmt_using_entry_checks
or so and invoke it on the last stmt of a block with >= 2 outgoing
edges.

We still seem to do the simplification work twice, once for costing
and once for transform, but that's OK for now I guess.

I think you want to clear_aux_for_blocks at the end of the pass.

Otherwise I like it - it seems you have some TODO around cost
modeling.  Did you try to do gswitch support ontop as I suggested
to see if the general structure keeps working?

Thanks,
Richard.

>
> Martin


More information about the Gcc-patches mailing list