@@ -50,6 +50,9 @@ static cl::opt<bool> UnrollRuntimeMultiExit(
50
50
" unroll-runtime-multi-exit" , cl::init(false ), cl::Hidden,
51
51
cl::desc(" Allow runtime unrolling for loops with multiple exits, when "
52
52
" 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" ));
53
56
54
57
// / Connect the unrolling prolog code to the original loop.
55
58
// / The unrolling prolog code contains code to execute the
@@ -493,12 +496,19 @@ static bool canProfitablyUnrollMultiExitLoop(
493
496
if (ExitingBlocks.size () > 2 )
494
497
return false ;
495
498
499
+ // Allow unrolling of loops with no non latch exit blocks.
500
+ if (OtherExits.size () == 0 )
501
+ return true ;
502
+
496
503
// The second heuristic is that L has one exit other than the latchexit and
497
504
// that exit is a deoptimize block. We know that deoptimize blocks are rarely
498
505
// 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.
500
509
return (OtherExits.size () == 1 &&
501
- OtherExits[0 ]->getTerminatingDeoptimizeCall ());
510
+ (UnrollRuntimeOtherExitPredictable ||
511
+ OtherExits[0 ]->getTerminatingDeoptimizeCall ()));
502
512
// TODO: These can be fine-tuned further to consider code size or deopt states
503
513
// that are captured by the deoptimize exit block.
504
514
// Also, we can extend this to support more cases, if we actually
0 commit comments