[LoopUnroll] Simplify latch/header block handling (NFC).
authorFlorian Hahn <flo@fhahn.com>
Tue, 26 May 2020 20:50:15 +0000 (21:50 +0100)
committerFlorian Hahn <flo@fhahn.com>
Tue, 26 May 2020 20:54:12 +0000 (21:54 +0100)
commit5cf90d6cf1b811a6693383c487f79d24d5b306bb
tree84dda247f94c63e4ed7239cf49aa3f9bcfd5d8a2
parent01fee8aa24a6070542cfa55b2c32036d1d5869b8
[LoopUnroll] Simplify latch/header block handling (NFC).

I think the current code dealing with connecting the unrolled iterations
is a bit more complicated than necessary currently. To connect the
unrolled iterations, we have to update the unrolled latch blocks to
branch to the header of the next unrolled iteration.

We need to do this regardless whether the latch is exiting or not.

Additionally, we try to turn the conditional branch in the exiting block
to an unconditional one. This is an optimization only; alternatively we
could leave the conditional branches in place and rely on other passes
to simplify the conditions.

Logically, this is a separate step from connecting the latches to the
headers, but it is convenient to fold them into the same loop, if the
latch is also exiting. For headers (or other non-latch exiting blocks,
this is done separately).

Hopefully the patch with additional comments makes things a bit clearer.

Reviewers: efriedma, dmgreen, hfinkel, Whitney

Reviewed By: efriedma

Differential Revision: https://reviews.llvm.org/D80544
llvm/lib/Transforms/Utils/LoopUnroll.cpp