On Tue, Jun 10, 2025, 10:03 AM Andrew MacLeod <amacl...@redhat.com> wrote:

> simplify_switch_using_ranges has never been converted over properly to
> use irange.  It still uses get_legacy_range, and as a result, is very
> limited in how it processes cases labels.  In particular it is unable to
> remove cases in the middle which are not possible to call.
>
> This patch rewrites the routine to work in a similar way to how switches
> are processed in the gimple-range-edge component.  It starts with the
> range of the switch operand, uses that as the initial default case, and
> the  walks the labels determining if the case is reachable at all via an
> intersection with the index range.
>
> If the result is UNDEFINED, then the case label is unreachable. If the
> result is something smaller then it was originally, then the lower and
> upper bounds are adjusted.
>
> The range of the case is then removed from the default range, and we
> move on to the next one.
>
> When done, any case labels which are still in use (including the default
> label)  are built into a new vector and a new switch is constructed,
> similar to the way it was handled before.
>
> I had to adjust the testcase tree-ssa/ssa-dom-thread-7.c as the default
> label is now removed in that test, and this changes the thread count.
> aarch64 use to have a different threadcount, presumably all spawned via
> the default case, but now produces the same result on my cross
> compiler.  I left the seperate comparison in the test case just in case
> in the wild it still comes out different.
>
> The testcase that is added shows a case in the middle of the switch
> being removed that we couldn't remove before.
>
> The resulting routine is fairly straightforward and removes a lot of
> complexity, so it is pretty maintainable.   Performance shows an
> insignificant compile time increase across all of GCC.
>
> The second patch in the set focuses on improvements resulting from
> better utilizing the bitmask when it is present.
>
> Have I missed anything tricky about switches?
>


+/* { dg-final { scan-tree-dump-not "foo" "evrp" } } */

May I suggest this be changed to "foo " (adding a space). To avoid maybe
matching on a directory name that contains foo.

I only noticed this today after you pushed thr change sorry.

Thanks,
Andrew


> Bootstraps on x86_64-pc-linux-gnu with no regressions.  OK for trunk?
>
> Andrew
>
>
>

Reply via email to