[PATCH] D136927: [AMDGPU] Fix GCNDownwardRPTracker::advanceBeforeNext at the end of MBB

Valery Pykhtin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 28 02:03:48 PDT 2022


vpykhtin created this revision.
vpykhtin added reviewers: rampitec, arsenm.
Herald added subscribers: kosarev, foad, kerbowa, hiraditya, t-tye, tpr, dstuttard, yaxunl, jvesely, kzhuravl.
Herald added a project: All.
vpykhtin requested review of this revision.
Herald added subscribers: llvm-commits, wdng.
Herald added a project: LLVM.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136927

Files:
  llvm/lib/Target/AMDGPU/GCNRegPressure.cpp
  llvm/lib/Target/AMDGPU/GCNRegPressure.h
  llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp


Index: llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp
===================================================================
--- llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp
+++ llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp
@@ -541,7 +541,6 @@
       RPTracker.advanceToNext();
       RPTracker.advance(MBB->end());
     }
-    RPTracker.reset(*OnlySucc->begin(), &RPTracker.getLiveRegs());
     RPTracker.advanceBeforeNext();
     MBBLiveIns[OnlySucc] = RPTracker.moveLiveRegs();
   }
Index: llvm/lib/Target/AMDGPU/GCNRegPressure.h
===================================================================
--- llvm/lib/Target/AMDGPU/GCNRegPressure.h
+++ llvm/lib/Target/AMDGPU/GCNRegPressure.h
@@ -174,7 +174,7 @@
 
   // Move to the state right before the next MI. Returns false if reached
   // end of the block.
-  bool advanceBeforeNext();
+  void advanceBeforeNext();
 
   // Move to the state at the MI, advanceBeforeNext has to be called first.
   void advanceToNext();
Index: llvm/lib/Target/AMDGPU/GCNRegPressure.cpp
===================================================================
--- llvm/lib/Target/AMDGPU/GCNRegPressure.cpp
+++ llvm/lib/Target/AMDGPU/GCNRegPressure.cpp
@@ -339,14 +339,12 @@
   return true;
 }
 
-bool GCNDownwardRPTracker::advanceBeforeNext() {
+void GCNDownwardRPTracker::advanceBeforeNext() {
   assert(MRI && "call reset first");
+  if (!LastTrackedMI)
+    return;
 
-  NextMI = skipDebugInstructionsForward(NextMI, MBBEnd);
-  if (NextMI == MBBEnd)
-    return false;
-
-  SlotIndex SI = LIS.getInstructionIndex(*NextMI).getBaseIndex();
+  SlotIndex SI = LIS.getInstructionIndex(*LastTrackedMI).getDeadSlot();
   assert(SI.isValid());
 
   // Remove dead registers or mask bits.
@@ -371,7 +369,7 @@
 
   MaxPressure = max(MaxPressure, CurPressure);
 
-  return true;
+  LastTrackedMI = nullptr;
 }
 
 void GCNDownwardRPTracker::advanceToNext() {
@@ -396,8 +394,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;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136927.471447.patch
Type: text/x-patch
Size: 2165 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221028/f9689d71/attachment.bin>


More information about the llvm-commits mailing list