diff --git a/llvm/lib/Target/AMDGPU/GCNRegPressure.h b/llvm/lib/Target/AMDGPU/GCNRegPressure.h --- a/llvm/lib/Target/AMDGPU/GCNRegPressure.h +++ b/llvm/lib/Target/AMDGPU/GCNRegPressure.h @@ -172,8 +172,8 @@ // Returns false if block is empty except debug values. bool reset(const MachineInstr &MI, const LiveRegSet *LiveRegs = nullptr); - // Move to the state right before the next MI. Returns false if reached - // end of the block. + // Move to the state right before the next MI or after the end of MBB. + // Returns false if reached end of the block. bool advanceBeforeNext(); // Move to the state at the MI, advanceBeforeNext has to be called first. 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 @@ -325,12 +325,14 @@ bool GCNDownwardRPTracker::advanceBeforeNext() { assert(MRI && "call reset first"); + if (!LastTrackedMI) + return NextMI == MBBEnd; - NextMI = skipDebugInstructionsForward(NextMI, MBBEnd); - if (NextMI == MBBEnd) - return false; + assert(NextMI == MBBEnd || !NextMI->isDebugInstr()); - SlotIndex SI = LIS.getInstructionIndex(*NextMI).getBaseIndex(); + SlotIndex SI = NextMI == MBBEnd + ? LIS.getInstructionIndex(*LastTrackedMI).getDeadSlot() + : LIS.getInstructionIndex(*NextMI).getBaseIndex(); assert(SI.isValid()); // Remove dead registers or mask bits. @@ -355,7 +357,9 @@ MaxPressure = max(MaxPressure, CurPressure); - return true; + LastTrackedMI = nullptr; + + return NextMI == MBBEnd; } void GCNDownwardRPTracker::advanceToNext() { @@ -379,9 +383,9 @@ } bool GCNDownwardRPTracker::advance() { - // If we have just called reset live set is actual. - if ((NextMI == MBBEnd) || (LastTrackedMI && !advanceBeforeNext())) + if (NextMI == MBBEnd) return false; + advanceBeforeNext(); advanceToNext(); return true; } diff --git a/llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp b/llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp --- a/llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp +++ b/llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp @@ -538,7 +538,6 @@ RPTracker.advanceToNext(); RPTracker.advance(MBB->end()); } - RPTracker.reset(*OnlySucc->begin(), &RPTracker.getLiveRegs()); RPTracker.advanceBeforeNext(); MBBLiveIns[OnlySucc] = RPTracker.moveLiveRegs(); }