[llvm] [LoopPeel] Implement initial peeling off the last loop iteration. (PR #139551)

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Tue May 13 07:57:06 PDT 2025


================
@@ -609,6 +668,23 @@ void llvm::computePeelCount(Loop *L, unsigned LoopSize,
                         << " some Phis into invariants.\n");
       PP.PeelCount = DesiredPeelCount;
       PP.PeelProfiledIterations = false;
+      PP.PeelLast = false;
+      return;
+    }
+  }
+
+  if (CountToEliminateCmpsLast > 0) {
+    unsigned DesiredPeelCountLast =
+        std::min(CountToEliminateCmpsLast, MaxPeelCount);
+    // Consider max peel count limitation.
+    assert(DesiredPeelCountLast > 0 && "Wrong loop size estimation?");
+    if (DesiredPeelCountLast + AlreadyPeeled <= UnrollPeelMaxCount) {
+      LLVM_DEBUG(dbgs() << "Peel " << DesiredPeelCount
+                        << " iteration(s) to turn"
+                        << " some Phis into invariants.\n");
+      PP.PeelCount = DesiredPeelCountLast;
+      PP.PeelProfiledIterations = false;
+      PP.PeelLast = true;
----------------
preames wrote:

As a follow up, it would be nice if we could peel both first and last iteration off a single loop if profitable.  

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


More information about the llvm-commits mailing list