[llvm] [LoopUnroll] Allow unrolling of multi-exit loops with small trip count (PR #224325)

Marek Sedláček via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 29 00:51:53 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;
----------------
mark-sed wrote:

Since `Count` and `MinBodies` are both `unsigned int` without this cast we would be multiplying on 32 bits and then widen it. Of course this should not really play role since we should not overflow in normal cases, but I don't think it hurts as either.

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


More information about the llvm-commits mailing list