This is an archive of the discontinued LLVM Phabricator instance.

[RuntimeUnroll] Add heuristic for unrolling multi-exit loop
ClosedPublic

Authored by anna on Jul 13 2017, 1:14 PM.

Details

Summary

Add a profitability heuristic to enable runtime unrolling of multi-exit loop:
There can be atmost two unique exit blocks for the loop and the second
exit block should be a deoptimizing block. Also, there can be one other exiting block
other than the latch exiting block. The reason for the latter is so that we limit the number of
branches in the unrolled code to being at most the unroll factor.
Deoptimizing blocks are rarely taken so these additional number of branches
created due to the unrolling are predictable, since one of their target is the
deopt block.

Diff Detail

Repository
rL LLVM

Event Timeline

anna created this revision.Jul 13 2017, 1:14 PM
reames requested changes to this revision.Jul 18 2017, 1:25 PM
reames added inline comments.
lib/Transforms/Utils/LoopUnrollRuntime.cpp
435 ↗(On Diff #106506)

Code structure wise, I'd recommend splitting this function into two: one which checks *legality* and one which given a legal case, checks profitability. Mixing the two needlessly is just confusing.

This could in fact be done as an NFC change.

467 ↗(On Diff #106506)

Why did you chose this particular heuristic? What other options did you consider? (some of this should be in the code itself)

This revision now requires changes to proceed.Jul 18 2017, 1:25 PM
anna added inline comments.Jul 21 2017, 7:45 AM
lib/Transforms/Utils/LoopUnrollRuntime.cpp
435 ↗(On Diff #106506)

I had thought of this approach, but the main problem is that in the caller, there's the chance the user calls profitability without safety checks being done. Granted we can assert for that in the profitability check, but it's expensive. Perhaps I can place it under an EXPENSIVE_CHECKS option.

467 ↗(On Diff #106506)

will add details.

anna updated this revision to Diff 107694.Jul 21 2017, 11:17 AM
anna edited edge metadata.
anna marked 2 inline comments as done.

addressed review comments.

reames accepted this revision.Aug 25 2017, 4:59 PM

LGTM

This revision is now accepted and ready to land.Aug 25 2017, 4:59 PM
anna edited the summary of this revision. (Show Details)Sep 14 2017, 7:33 AM
This revision was automatically updated to reflect the committed changes.