Skip to content

Commit 58d531f

Browse files
author
Whitney Tsang
committed
[LoopUnrollRuntime] Add option to assume the non latch exit block to be
predictable. Reviewed By: Meinersbur, bmahjour Differential Revision: https://reviews.llvm.org/D97747
1 parent 60470ac commit 58d531f

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ static cl::opt<bool> UnrollRuntimeMultiExit(
5050
"unroll-runtime-multi-exit", cl::init(false), cl::Hidden,
5151
cl::desc("Allow runtime unrolling for loops with multiple exits, when "
5252
"epilog is generated"));
53+
static cl::opt<bool> UnrollRuntimeOtherExitPredictable(
54+
"unroll-runtime-other-exit-predictable", cl::init(false), cl::Hidden,
55+
cl::desc("Assume the non latch exit block to be predictable"));
5356

5457
/// Connect the unrolling prolog code to the original loop.
5558
/// The unrolling prolog code contains code to execute the
@@ -493,12 +496,19 @@ static bool canProfitablyUnrollMultiExitLoop(
493496
if (ExitingBlocks.size() > 2)
494497
return false;
495498

499+
// Allow unrolling of loops with no non latch exit blocks.
500+
if (OtherExits.size() == 0)
501+
return true;
502+
496503
// The second heuristic is that L has one exit other than the latchexit and
497504
// that exit is a deoptimize block. We know that deoptimize blocks are rarely
498505
// taken, which also implies the branch leading to the deoptimize block is
499-
// highly predictable.
506+
// highly predictable. When UnrollRuntimeOtherExitPredictable is specified, we
507+
// assume the other exit branch is predictable even if it has no deoptimize
508+
// call.
500509
return (OtherExits.size() == 1 &&
501-
OtherExits[0]->getTerminatingDeoptimizeCall());
510+
(UnrollRuntimeOtherExitPredictable ||
511+
OtherExits[0]->getTerminatingDeoptimizeCall()));
502512
// TODO: These can be fine-tuned further to consider code size or deopt states
503513
// that are captured by the deoptimize exit block.
504514
// Also, we can extend this to support more cases, if we actually

0 commit comments

Comments
 (0)