diff --git a/llvm/lib/Target/AMDGPU/GCNRegPressure.cpp b/llvm/lib/Target/AMDGPU/GCNRegPressure.cpp --- a/llvm/lib/Target/AMDGPU/GCNRegPressure.cpp +++ b/llvm/lib/Target/AMDGPU/GCNRegPressure.cpp @@ -354,6 +354,11 @@ bool GCNDownwardRPTracker::advanceBeforeNext() { assert(MRI && "call reset first"); + if (!LastTrackedMI) + return true; + + auto const RegUses = collectVirtualRegUses(*LastTrackedMI, LIS, *MRI); + // each RegUnit is unique in RegUses NextMI = skipDebugInstructionsForward(NextMI, MBBEnd); if (NextMI == MBBEnd) @@ -363,23 +368,29 @@ assert(SI.isValid()); // Remove dead registers or mask bits. - for (auto &It : LiveRegs) { - const LiveInterval &LI = LIS.getInterval(It.first); + for (auto &U : RegUses) { + const LiveInterval &LI = LIS.getInterval(U.RegUnit); if (LI.hasSubRanges()) { + auto It = LiveRegs.end(); for (const auto &S : LI.subranges()) { if (!S.liveAt(SI)) { - auto PrevMask = It.second; - It.second &= ~S.LaneMask; - CurPressure.inc(It.first, PrevMask, It.second, *MRI); + if (It == LiveRegs.end()) { + It = LiveRegs.find(U.RegUnit); + assert(It != LiveRegs.end()); + } + auto PrevMask = It->second; + It->second &= ~S.LaneMask; + CurPressure.inc(U.RegUnit, PrevMask, It->second, *MRI); } } + if (It != LiveRegs.end() && It->second.none()) + LiveRegs.erase(It); } else if (!LI.liveAt(SI)) { - auto PrevMask = It.second; - It.second = LaneBitmask::getNone(); - CurPressure.inc(It.first, PrevMask, It.second, *MRI); + auto It = LiveRegs.find(U.RegUnit); + assert(It != LiveRegs.end()); + CurPressure.inc(U.RegUnit, It->second, LaneBitmask::getNone(), *MRI); + LiveRegs.erase(It); } - if (It.second.none()) - LiveRegs.erase(It.first); } MaxPressure = max(MaxPressure, CurPressure);