[llvm] [SandboxVec][Scheduler] Cleanup: Use interval in loop and reset sched state (PR #205465)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 23 18:12:44 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: vporpo (vporpo)

<details>
<summary>Changes</summary>

Replace the for loop that iterates between TopI and LowestI with a range loop over ResetIntvl and move the reset of the scheduling state to this loop.

Even though this is not an NFC as we iterate over the loop in the reverse order than before, the functionality should not change.

---
Full diff: https://github.com/llvm/llvm-project/pull/205465.diff


1 Files Affected:

- (modified) llvm/lib/Transforms/Vectorize/SandboxVectorizer/Scheduler.cpp (+10-12) 


``````````diff
diff --git a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Scheduler.cpp b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Scheduler.cpp
index 82a327719f29f..14614686c2d46 100644
--- a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Scheduler.cpp
+++ b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Scheduler.cpp
@@ -297,26 +297,24 @@ void Scheduler::trimSchedule(ArrayRef<Instruction *> Instrs) {
   Instruction *LowestI = Dir == SchedDirection::BottomUp
                              ? VecUtils::getLowest(Instrs)
                              : &*ScheduleTopItOpt.value();
-
-  // Destroy the singleton schedule bundles from LowestI all the way to the top.
-  for (auto *I = LowestI, *E = TopI->getPrevNode(); I != E;
-       I = I->getPrevNode()) {
-    auto *N = DAG.getNode(I);
+  Interval<Instruction> ResetIntvl(TopI, LowestI);
+  // The DAG Nodes contain state like the number of UnscheduledSuccs and the
+  // Scheduled flag. We need to reset their state. We need to do this for all
+  // nodes in ResetIntvl. Also destroy the singleton schedule bundles from
+  // LowestI all the way to the top.
+  for (auto &I : ResetIntvl) {
+    auto *N = DAG.getNode(&I);
     if (N == nullptr)
       continue;
     auto *SB = N->getSchedBundle();
     if (SB->isSingleton())
       eraseBundle(SB);
+    N->resetScheduleState();
   }
-  // The DAG Nodes contain state like the number of UnscheduledSuccs and the
-  // Scheduled flag. We need to reset their state. We need to do this for all
-  // nodes from LowestI to the top of the schedule. DAG Nodes that are above the
-  // top of schedule that depend on nodes that got reset need to have their
-  // UnscheduledSuccs adjusted.
-  Interval<Instruction> ResetIntvl(TopI, LowestI);
+  // Nodes that depend on the nodes in ResetIntvl also need to have their
+  // UnscheduledSuccs/UnscheduledPreds adjusted.
   for (Instruction &I : ResetIntvl) {
     auto *N = DAG.getNode(&I);
-    N->resetScheduleState();
     if (Dir == SchedDirection::BottomUp) {
       // Recompute UnscheduledSuccs for nodes not only in ResetIntvl but even
       // for nodes above the top of schedule.

``````````

</details>


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


More information about the llvm-commits mailing list