[llvm] [AMDGPU] Improved register pressure estimates for rescheduling (PR #213116)
Lucas Ramirez via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 31 04:57:54 PDT 2026
================
@@ -2216,6 +2214,105 @@ bool MemoryClauseInitialScheduleStage::shouldRevertScheduling(
return mayCauseSpilling(WavesAfter);
}
+static cl::opt<bool> EnableLiveIntervalRPReschedule(
+ "amdgpu-lirp-reschedule", cl::Hidden,
+ cl::desc("Enable live interval RP reschedule stage"), cl::init(true));
+
+static cl::opt<unsigned> LiveIntervalRPThreshold(
+ "amdgpu-lirp-threshold", cl::Hidden,
+ cl::desc("Percent increase of live interval RP over instant pressure to "
+ "trigger rescheduling"),
+ cl::init(10));
+
+static cl::opt<unsigned> LiveIntervalRPVGPRReduction(
+ "amdgpu-lirp-vgpr-reduction", cl::Hidden,
+ cl::desc(
+ "Reduction factor (percent) for VGPR threshold during live interval RP "
+ "reschedule stage"),
+ cl::init(90));
+
+static cl::opt<unsigned> LiveIntervalRPVGPRReductionEpilogue(
+ "amdgpu-lirp-vgpr-reduction-epilogue", cl::Hidden,
+ cl::desc(
+ "Reduction factor (percent) for VGPR threshold during live interval RP "
+ "reschedule stage for exit blocks"),
+ cl::init(70));
+
+bool LiveIntervalRPStage::initGCNSchedStage() {
+ if (!EnableLiveIntervalRPReschedule)
+ return false;
+
+ if (!GCNSchedStage::initGCNSchedStage())
+ return false;
+
+ if (!S.VGPRThresholdPercent) {
+ LLVM_DEBUG(dbgs() << "LIRP: expected VGPRThresholdPercent to be enabled, "
+ "not using live interval RP reschedule stage\n");
+ return false;
+ }
+
+ return true;
+}
+
+bool LiveIntervalRPStage::initGCNRegion() {
+ unsigned InstantRP = DAG.Pressure[RegionIdx].getArchVGPRNum();
+ auto [RegionBegin, RegionEnd] = DAG.Regions[RegionIdx];
+ if (RegionBegin == RegionEnd)
+ return false;
+
+ unsigned LIRP = estimateGreedyVGPRPressure(
+ RegionBegin, RegionEnd, DAG.LiveIns[RegionIdx], *DAG.getLIS(),
+ DAG.MF.getRegInfo(), static_cast<const SIRegisterInfo &>(*DAG.TRI));
+
+ bool IsReturnBlock = RegionBegin->getParent()->isReturnBlock();
+ // Use a tighter VGPRExcessLimit by reducing VGPRThresholdPercent
+ unsigned BlockReduction = IsReturnBlock ? LiveIntervalRPVGPRReductionEpilogue
+ : LiveIntervalRPVGPRReduction;
+ unsigned NewVGPRThresholdPercent =
+ (S.VGPRThresholdPercent * BlockReduction + 99) / 100;
+
+ LLVM_DEBUG(dbgs() << "LIRP: Region " << RegionIdx
+ << ", VGPRThresholdPercent: " << S.VGPRThresholdPercent
+ << " -> " << NewVGPRThresholdPercent
+ << ", VGPRExcessLimit=" << S.VGPRExcessLimit
+ << ", VGPRCriticalLimit=" << S.VGPRCriticalLimit
+ << ", InstantRP=" << InstantRP << ", LIRP=" << LIRP);
+
+ bool DoRescheduling = false;
+ // Lower bound on InstantRP to skip over tiny regions
+ unsigned InstantRPLB = S.VGPRExcessLimit / 10;
+ if (LIRP > S.VGPRExcessLimit) {
+ LLVM_DEBUG(dbgs() << " [LIRP exceeds the limit (" << S.VGPRExcessLimit
+ << "), rescheduling]");
+ DoRescheduling = true;
+ } else if (LIRP > InstantRP && InstantRP > InstantRPLB) {
+ unsigned IncreasePercent = ((LIRP - InstantRP) * 100) / InstantRP;
+ if (IncreasePercent > LiveIntervalRPThreshold) {
+ LLVM_DEBUG(dbgs() << " [" << IncreasePercent << "% > "
+ << LiveIntervalRPThreshold << "%, rescheduling]");
+ DoRescheduling = true;
+ }
+ }
+ LLVM_DEBUG(dbgs() << "\n");
----------------
lucas-rami wrote:
```suggestion
LLVM_DEBUG(dbgs() << '\n');
```
https://github.com/llvm/llvm-project/pull/213116
More information about the llvm-commits
mailing list