From e6354e586c37bcc3015ceb498dbc340702ea02df Mon Sep 17 00:00:00 2001 From: Scott Linder Date: Thu, 6 Nov 2025 20:46:03 +0000 Subject: [PATCH] [AMDGPU] Handle empty-except-for-DI regions in PreRARematerialize The existing check for this case only comes after a derefence of what can be an iterator sentinel (leading to an assert). This may not be purely NFC in that it also avoids queuing the effectively-empty region for rescheduling, but AFAICT this should be purely an optimization. Testing this seems difficult, as the high-level scheduler avoids scheduling these "empty" regions. This means a reproducer has to depend on behavior of the scheduler passes before PreRARematStage in order to craft a region which triggers the bug. Since this is a release blocker I am posting a PR now, as both Shore Shen and I have manually verified that this resolves the particular crash from SWDEV-564142 but I am still working on making a reasonable test. (cherry picked from commit 004cfea449b2cc073f766f7b43568da966ca7ca1) --- llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp b/llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp index bdc08101c7119..5e5c63c328ef5 100644 --- a/llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp +++ b/llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp @@ -1916,7 +1916,9 @@ void PreRARematStage::rematerialize() { MF.getInfo()->getDynamicVGPRBlockSize(); AchievedOcc = MFI.getMaxWavesPerEU(); for (auto &[I, OriginalRP] : ImpactedRegions) { - bool IsEmptyRegion = DAG.Regions[I].first == DAG.Regions[I].second; + auto NonDbgMBBI = skipDebugInstructionsForward(DAG.Regions[I].first, + DAG.Regions[I].second); + bool IsEmptyRegion = NonDbgMBBI == DAG.Regions[I].second; RescheduleRegions[I] = !IsEmptyRegion; if (!RecomputeRP.contains(I)) continue; @@ -1926,16 +1928,9 @@ void PreRARematStage::rematerialize() { RP = getRegPressure(DAG.MRI, DAG.LiveIns[I]); } else { GCNDownwardRPTracker RPT(*DAG.LIS); - auto *NonDbgMI = &*skipDebugInstructionsForward(DAG.Regions[I].first, - DAG.Regions[I].second); - if (NonDbgMI == DAG.Regions[I].second) { - // Region is non-empty but contains only debug instructions. - RP = getRegPressure(DAG.MRI, DAG.LiveIns[I]); - } else { - RPT.reset(*NonDbgMI, &DAG.LiveIns[I]); - RPT.advance(DAG.Regions[I].second); - RP = RPT.moveMaxPressure(); - } + RPT.reset(*NonDbgMBBI, &DAG.LiveIns[I]); + RPT.advance(DAG.Regions[I].second); + RP = RPT.moveMaxPressure(); } DAG.Pressure[I] = RP; AchievedOcc =