[llvm] [LoopUnroll] Relax fixed non-latch exit probability threshold for runtime multi-exit loop unrolling (PR #224325)

Marek Sedláček via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 29 10:49:26 PDT 2026


================
@@ -585,6 +590,14 @@ static bool canProfitablyRuntimeUnrollMultiExitLoop(
     // If BranchProbability could not be extracted (returns unknown), then
     // don't return and do the check for deopt block.
     if (!BranchProb.isUnknown()) {
+      // Special case for linear scan loop with trip count < ~100, which will
+      // not pass the P < 1/100 check bellow.
+      if (unsigned MinBodies = UnrollRuntimeMultiExitMinBodies) {
+        uint64_t MinIterations = static_cast<uint64_t>(MinBodies) * Count;
+        return BranchProb <=
+               BranchProbability::getBranchProbability(1, MinIterations);
+      }
+
       auto Threshold = TTI->getPredictableBranchThreshold().getCompl();
----------------
mark-sed wrote:

Then again we could change the other one to <= since that one is an arbitrary threshold.

https://github.com/llvm/llvm-project/pull/224325


More information about the llvm-commits mailing list