This is an archive of the discontinued LLVM Phabricator instance.

[LoopUnroll] Allow loops with multiple exiting blocks where loop latch is not necessary one of them.
ClosedPublic

Authored by Whitney on Jun 2 2020, 9:52 PM.

Details

Summary

Currently LoopUnrollPass already allow loops with multiple exiting blocks, but it is only allowed when the loop latch is one of the exiting blocks.
When the loop latch is not an exiting block, then only single exiting block is supported.
When possible, the single loop latch or the single exiting block terminator is optimized to an unconditional branch in the unrolled loop.

This patch allows loops with multiple exiting blocks even if the loop latch is not one of them. However, the optimization of exiting block terminator to unconditional branch is not done when there exists more than one exiting block.

Diff Detail

Event Timeline

Whitney created this revision.Jun 2 2020, 9:52 PM
Whitney updated this revision to Diff 268249.Jun 3 2020, 10:22 AM

Obtain ContinueOnTrue and LoopExit before modifying loop latch branch.

etiotto added inline comments.Jun 4 2020, 8:38 AM
llvm/test/Transforms/LoopUnroll/nonlatchcondbr.ll
217

Would be better IMO to have conditional branch that isn't foldable here.

efriedma added inline comments.Jun 4 2020, 9:10 AM
llvm/lib/Transforms/Utils/LoopUnroll.cpp
797

We should probably rewrite the latch here even if ExitingBI is null.

Meinersbur added inline comments.Jun 4 2020, 10:01 AM
llvm/lib/Transforms/Utils/LoopUnroll.cpp
310

[typo] conditional

Whitney updated this revision to Diff 268526.Jun 4 2020, 10:46 AM
Whitney marked 3 inline comments as done.

Addressed review comments.

This revision is now accepted and ready to land.Jun 4 2020, 12:20 PM
This revision was automatically updated to reflect the committed changes.