Skip to content

Commit

Permalink
[AMDGPU] Fix GCNDownwardRPTracker::advanceBeforeNext at the end of MBB
Browse files Browse the repository at this point in the history
The problem with GCNDownwardRPTracker::advanceBeforeNext is that it doesn't allow to get register pressure
after the last instruction in a MBB.

However when we track RP through the boundary of a MBB we need the state that is after the last instruction
of the MBB and before the first instruction of the successor MBB. Currently we stop traking RP in the state
 'at' the last instruction of the MBB which is incorrect.

This patch fixes 27 lit tests with EXPENSIVE_CHECKS enabled.

Reviewed By: rampitec, arsenm

Differential Revision: https://reviews.llvm.org/D136927
  • Loading branch information
vpykhtin committed Nov 3, 2022
1 parent 0fb763e commit 5144133
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
18 changes: 11 additions & 7 deletions llvm/lib/Target/AMDGPU/GCNRegPressure.cpp
Expand Up @@ -325,12 +325,14 @@ bool GCNDownwardRPTracker::reset(const MachineInstr &MI,

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.
Expand All @@ -355,7 +357,9 @@ bool GCNDownwardRPTracker::advanceBeforeNext() {

MaxPressure = max(MaxPressure, CurPressure);

return true;
LastTrackedMI = nullptr;

return NextMI == MBBEnd;
}

void GCNDownwardRPTracker::advanceToNext() {
Expand All @@ -379,9 +383,9 @@ void GCNDownwardRPTracker::advanceToNext() {
}

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;
}
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/AMDGPU/GCNRegPressure.h
Expand Up @@ -172,8 +172,8 @@ class GCNDownwardRPTracker : public GCNRPTracker {
// 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.
Expand Down
1 change: 0 additions & 1 deletion llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp
Expand Up @@ -538,7 +538,6 @@ void GCNScheduleDAGMILive::computeBlockPressure(unsigned RegionIdx,
RPTracker.advanceToNext();
RPTracker.advance(MBB->end());
}
RPTracker.reset(*OnlySucc->begin(), &RPTracker.getLiveRegs());
RPTracker.advanceBeforeNext();
MBBLiveIns[OnlySucc] = RPTracker.moveLiveRegs();
}
Expand Down

0 comments on commit 5144133

Please sign in to comment.