This is an archive of the discontinued LLVM Phabricator instance.

[LoopUnroll] Simplify latch/header block handling (NFC).
ClosedPublic

Authored by fhahn on May 26 2020, 3:15 AM.

Details

Summary

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.

Diff Detail

Event Timeline

fhahn created this revision.May 26 2020, 3:15 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 26 2020, 3:15 AM

Makes sense.

llvm/lib/Transforms/Utils/LoopUnroll.cpp
719

While you're here, can you change this so the "LoopExit" and "ContinueOnTrue" are passed in as arguments? I think changing the meaning based on LatchIsExiting is confusing.

fhahn updated this revision to Diff 266306.May 26 2020, 1:02 PM

Move ContinueOnTrue, LoopExit captures to explicit argument list. Also turned LoopExit into a bool (IsDestLoopExit), which makes it clear that this is always false in the Header case.

fhahn marked 2 inline comments as done.May 26 2020, 1:03 PM
fhahn added inline comments.
llvm/lib/Transforms/Utils/LoopUnroll.cpp
719

Done thanks. I've turned LoopExit into a bool (IsDestLoopExit). That should make the fact it is always false for the header case more explicit.

This revision is now accepted and ready to land.May 26 2020, 1:35 PM
Whitney accepted this revision.May 26 2020, 2:02 PM
This revision was automatically updated to reflect the committed changes.
fhahn marked an inline comment as done.