[PATCH] D129322: [AMDGPU][Scheduler] Avoid initializing Register pressure tracker when tracking is disabled

Anshil Gandhi via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 7 12:53:49 PDT 2022


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

When register pressure tracking is disabled, the scheduler attempts to load
pressures at SReg_32 and VGPR_32. This causes an index out of bounds error.
This patch fixes this issue by disabling the initialization of RPTracker
when not needed. NFC


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129322

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


Index: llvm/lib/Target/AMDGPU/GCNSchedStrategy.h
===================================================================
--- llvm/lib/Target/AMDGPU/GCNSchedStrategy.h
+++ llvm/lib/Target/AMDGPU/GCNSchedStrategy.h
@@ -36,10 +36,10 @@
                          const RegPressureTracker &RPTracker,
                          SchedCandidate &Cand);
 
-  void initCandidate(SchedCandidate &Cand, SUnit *SU,
-                     bool AtTop, const RegPressureTracker &RPTracker,
-                     const SIRegisterInfo *SRI,
-                     unsigned SGPRPressure, unsigned VGPRPressure);
+  void initRPTracker(SchedCandidate &Cand, SUnit *SU, bool AtTop,
+                     const RegPressureTracker &RPTracker,
+                     const SIRegisterInfo *SRI, unsigned SGPRPressure,
+                     unsigned VGPRPressure);
 
   std::vector<unsigned> Pressure;
   std::vector<unsigned> MaxPressure;
Index: llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp
===================================================================
--- llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp
+++ llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp
@@ -59,14 +59,12 @@
   VGPRExcessLimit = std::min(VGPRExcessLimit - ErrorMargin, VGPRExcessLimit);
 }
 
-void GCNMaxOccupancySchedStrategy::initCandidate(SchedCandidate &Cand, SUnit *SU,
-                                     bool AtTop, const RegPressureTracker &RPTracker,
-                                     const SIRegisterInfo *SRI,
-                                     unsigned SGPRPressure,
-                                     unsigned VGPRPressure) {
-
-  Cand.SU = SU;
-  Cand.AtTop = AtTop;
+void GCNMaxOccupancySchedStrategy::initRPTracker(
+    SchedCandidate &Cand, SUnit *SU, bool AtTop,
+    const RegPressureTracker &RPTracker, const SIRegisterInfo *SRI,
+    unsigned SGPRPressure, unsigned VGPRPressure) {
+  assert(Pressure.size() >= 3 &&
+         "RegSetPressure array is empty at current position!");
 
   // getDownwardPressure() and getUpwardPressure() make temporary changes to
   // the tracker, so we need to pass those function a non-const copy.
@@ -150,14 +148,17 @@
                                          SchedCandidate &Cand) {
   const SIRegisterInfo *SRI = static_cast<const SIRegisterInfo*>(TRI);
   ArrayRef<unsigned> Pressure = RPTracker.getRegSetPressureAtPos();
-  unsigned SGPRPressure = Pressure[AMDGPU::RegisterPressureSets::SReg_32];
-  unsigned VGPRPressure = Pressure[AMDGPU::RegisterPressureSets::VGPR_32];
   ReadyQueue &Q = Zone.Available;
   for (SUnit *SU : Q) {
-
     SchedCandidate TryCand(ZonePolicy);
-    initCandidate(TryCand, SU, Zone.isTop(), RPTracker, SRI,
-                  SGPRPressure, VGPRPressure);
+    TryCand.SU = SU;
+    TryCand.AtTop = Zone.isTop();
+
+    if (!Pressure.empty())
+      initRPTracker(TryCand, SU, Zone.isTop(), RPTracker, SRI,
+                    Pressure[AMDGPU::RegisterPressureSets::SReg_32],
+                    Pressure[AMDGPU::RegisterPressureSets::VGPR_32]);
+
     // Pass SchedBoundary only when comparing nodes from the same boundary.
     SchedBoundary *ZoneArg = Cand.AtTop == TryCand.AtTop ? &Zone : nullptr;
     GenericScheduler::tryCandidate(Cand, TryCand, ZoneArg);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129322.443033.patch
Type: text/x-patch
Size: 3202 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220707/9b3af4f2/attachment.bin>


More information about the llvm-commits mailing list