[PATCH] D47683: [PM/LoopUnswitch] Teach the new unswitch to handle nontrivial unswitching of switches.
Chandler Carruth via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 3 03:06:15 PDT 2018
chandlerc created this revision.
chandlerc added reviewers: asbirlea, fedor.sergeev, sanjoy.
Herald added subscribers: hiraditya, kristof.beyls, mcrosier.
Herald added a reviewer: javed.absar.
This works much like trivial unswitching of switches in that it reliably
moves the switch out of the loop. Here we potentially clone the entire
loop into each successor of the switch and re-point the cases at these
clones.
Due to the complexity of actually doing nontrivial unswitching, this
patch doesn't create a dedicated routine for handling switches -- it
would duplicate far too much code. Instead, it generalizes the existing
routine to handle both branches and switches as it largely reduces to
looping in a few places instead of doing something once. This actually
improves the results in some cases with branches due to being much more
careful about how dead regions of code are managed. With branches,
because exactly one clone is created and there are exactly two edges
considered, somewhat sloppy handling of the dead regions of code was
sufficient in most cases. But with switches, there are much more
complicated patterns of dead code and so I've had to move to a more
robust model generally. We still do as much pruning of the dead code
early as possible because that allows us to avoid even cloning the code.
This also surfaced another problem with nontrivial unswitching before
which is that we weren't as precise in reconstructing loops as we could
have been. This seems to have been mostly harmless, but resulted in
pointless LCSSA PHI nodes and other unnecessary cruft. With switches, we
have to get this *right*, and everything benefits from it.
While the testing may seem a bit light here because we only have two
real cases with actual switches, they do a surprisingly good job of
exercising numerous edge cases here. Also, because we share the logic
with branches, most of the changes in this patch are reasonably well
covered by existing tests. Still, I'm going to look at some potentially
more interesting test coverage as well but didn't want to delay sending
this out.
The new unswitch now has all of the same fundamental power as the old
one with the exception of the single unsound case of *partial* switch
unswitching -- that really is just loop specialization and not
unswitching at all. It doesn't fit into the canonicalization model in
any way. We can add a loop specialization pass that runs late based on
profile data if important test cases ever come up here.
Depends on https://reviews.llvm.org/D47522.
Repository:
rL LLVM
https://reviews.llvm.org/D47683
Files:
llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47683.149630.patch
Type: text/x-patch
Size: 38802 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180603/b9febb11/attachment.bin>
More information about the llvm-commits
mailing list