Skip to content

Commit 5961ba0

Browse files
authored
[AMDGPU] Handle empty-except-for-DI regions in PreRARematerialize (#524)
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](https://ontrack-internal.amd.com/browse/SWDEV-564142) but I am still working on making a reasonable test. (cherry picked from commit 004cfea)
1 parent abda683 commit 5961ba0

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1916,7 +1916,9 @@ void PreRARematStage::rematerialize() {
19161916
MF.getInfo<SIMachineFunctionInfo>()->getDynamicVGPRBlockSize();
19171917
AchievedOcc = MFI.getMaxWavesPerEU();
19181918
for (auto &[I, OriginalRP] : ImpactedRegions) {
1919-
bool IsEmptyRegion = DAG.Regions[I].first == DAG.Regions[I].second;
1919+
auto NonDbgMBBI = skipDebugInstructionsForward(DAG.Regions[I].first,
1920+
DAG.Regions[I].second);
1921+
bool IsEmptyRegion = NonDbgMBBI == DAG.Regions[I].second;
19201922
RescheduleRegions[I] = !IsEmptyRegion;
19211923
if (!RecomputeRP.contains(I))
19221924
continue;
@@ -1926,16 +1928,9 @@ void PreRARematStage::rematerialize() {
19261928
RP = getRegPressure(DAG.MRI, DAG.LiveIns[I]);
19271929
} else {
19281930
GCNDownwardRPTracker RPT(*DAG.LIS);
1929-
auto *NonDbgMI = &*skipDebugInstructionsForward(DAG.Regions[I].first,
1930-
DAG.Regions[I].second);
1931-
if (NonDbgMI == DAG.Regions[I].second) {
1932-
// Region is non-empty but contains only debug instructions.
1933-
RP = getRegPressure(DAG.MRI, DAG.LiveIns[I]);
1934-
} else {
1935-
RPT.reset(*NonDbgMI, &DAG.LiveIns[I]);
1936-
RPT.advance(DAG.Regions[I].second);
1937-
RP = RPT.moveMaxPressure();
1938-
}
1931+
RPT.reset(*NonDbgMBBI, &DAG.LiveIns[I]);
1932+
RPT.advance(DAG.Regions[I].second);
1933+
RP = RPT.moveMaxPressure();
19391934
}
19401935
DAG.Pressure[I] = RP;
19411936
AchievedOcc =

0 commit comments

Comments
 (0)