[llvm] 58d531f - [LoopUnrollRuntime] Add option to assume the non latch exit block to be
Whitney Tsang via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 3 12:43:52 PST 2021
Author: Whitney Tsang
Date: 2021-03-03T20:43:31Z
New Revision: 58d531fd6f04bf240755ca3f274cfefb20121e85
URL: https://github.com/llvm/llvm-project/commit/58d531fd6f04bf240755ca3f274cfefb20121e85
DIFF: https://github.com/llvm/llvm-project/commit/58d531fd6f04bf240755ca3f274cfefb20121e85.diff
LOG: [LoopUnrollRuntime] Add option to assume the non latch exit block to be
predictable.
Reviewed By: Meinersbur, bmahjour
Differential Revision: https://reviews.llvm.org/D97747
Added:
Modified:
llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp b/llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp
index 0abf62be156f..5105c53e74bd 100644
--- a/llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp
+++ b/llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp
@@ -50,6 +50,9 @@ static cl::opt<bool> UnrollRuntimeMultiExit(
"unroll-runtime-multi-exit", cl::init(false), cl::Hidden,
cl::desc("Allow runtime unrolling for loops with multiple exits, when "
"epilog is generated"));
+static cl::opt<bool> UnrollRuntimeOtherExitPredictable(
+ "unroll-runtime-other-exit-predictable", cl::init(false), cl::Hidden,
+ cl::desc("Assume the non latch exit block to be predictable"));
/// Connect the unrolling prolog code to the original loop.
/// The unrolling prolog code contains code to execute the
@@ -493,12 +496,19 @@ static bool canProfitablyUnrollMultiExitLoop(
if (ExitingBlocks.size() > 2)
return false;
+ // Allow unrolling of loops with no non latch exit blocks.
+ if (OtherExits.size() == 0)
+ return true;
+
// The second heuristic is that L has one exit other than the latchexit and
// that exit is a deoptimize block. We know that deoptimize blocks are rarely
// taken, which also implies the branch leading to the deoptimize block is
- // highly predictable.
+ // highly predictable. When UnrollRuntimeOtherExitPredictable is specified, we
+ // assume the other exit branch is predictable even if it has no deoptimize
+ // call.
return (OtherExits.size() == 1 &&
- OtherExits[0]->getTerminatingDeoptimizeCall());
+ (UnrollRuntimeOtherExitPredictable ||
+ OtherExits[0]->getTerminatingDeoptimizeCall()));
// TODO: These can be fine-tuned further to consider code size or deopt states
// that are captured by the deoptimize exit block.
// Also, we can extend this to support more cases, if we actually
More information about the llvm-commits
mailing list