[llvm] [AMDGPU][Scheduler] Prepare remat stage for rematerializer integration (NFC) (PR #189489)

Lucas Ramirez via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 7 06:02:48 PDT 2026


================
@@ -1637,24 +1632,37 @@ bool PreRARematStage::initGCNSchedStage() {
         DAG.deleteMI(Remat.DefRegion, Remat.DefMI);
       }
 
-      unsetSatisfiedRPTargets(Remat.Live);
-    }
-
-    REMAT_DEBUG({
+      // Adjust RP targets. The save is guaranteed in regions in which the
+      // register is live-through and unused but optimistic in all other regions
+      // where the register is live.
+      updateRPTargets(Cand.Live, Cand.RPSave);
+      RecomputeRP |= Cand.UnpredictableRPSave;
+      RescheduleRegions |= Cand.Live;
       if (!TargetRegions.any()) {
-        dbgs() << "** Interrupt round on all targets achieved\n";
-      } else if (RematIdx) {
-        dbgs() << "** Interrupt round on stale score for "
-               << *ScoredRemats[RematIdx - 1].Remat->DefMI;
-      } else {
-        dbgs() << "** Stop on exhausted rematerialization candidates\n";
+        REMAT_DEBUG(dbgs() << "All targets cleared, verifying...\n");
+        break;
       }
-    });
+    }
+
+    if (!updateAndVerifyRPTargets(RecomputeRP) && !TargetRegions.any()) {
+      REMAT_DEBUG(dbgs() << "Objectives achieved!\n");
+      break;
+    }
+
+    // Update the score of remaining candidates.
+    NewCandidateOrder.clear();
----------------
lucas-rami wrote:

Thanks for the catch. My idea was to avoid re-allocating the register at every rematerialization round but the move empties the vector and moves its memory so it's indeed useless to declare it outside the loop and clear it.

I managed to get rid of this temporary vector entirely by exploiting the fact that after each round we simply filter down the list of remaining candidates, so this can be done in-place in `CandidateOrder`.

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


More information about the llvm-commits mailing list