[llvm] [AMDGPU] Prefer lower total register usage in regions with spilling (PR #71882)

Valery Pykhtin via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 30 04:50:29 PST 2023


================
@@ -102,20 +102,56 @@ bool GCNRegPressure::less(const GCNSubtarget &ST,
     std::min(MaxOccupancy,
              ST.getOccupancyWithNumVGPRs(O.getVGPRNum(ST.hasGFX90AInsts())));
 
+  unsigned MaxVGPRs = ST.getMaxNumVGPRs(MF);
+  unsigned MaxSGPRs = ST.getMaxNumSGPRs(MF);
+
+  bool ExcessVGPR = getVGPRNum(false) > MaxVGPRs || getAGPRNum() > MaxVGPRs;
+  bool ExcessSGPR = getSGPRNum() > MaxSGPRs;
+  bool OtherExcessVGPR =
+      O.getVGPRNum(false) > MaxVGPRs || O.getAGPRNum() > MaxVGPRs;
+  bool OtherExcessSGPR = O.getSGPRNum() > MaxSGPRs;
+
+  bool ExcessRP = ExcessSGPR || ExcessVGPR;
+  bool OtherExcessRP = OtherExcessSGPR || OtherExcessVGPR;
+  // In regions with spilling, we give precedence to the schedule with
+  // lower general RP.
+  if (ExcessRP || OtherExcessRP) {
+    // If the current RP doesn't have excess, then the other must have excess.
+    // Current RP is better.
+    if (!ExcessRP)
+      return true;
+    // If the other didn't have excess, but the current does, then current RP is
+    // worse.
+    else if (!OtherExcessRP)
+      return false;
+    else {
+      bool SGPRImportant = OtherExcessSGPR && ExcessSGPR;
+      unsigned GPRPressure =
+          SGPRImportant ? getSGPRNum() : getVGPRNum(ST.hasGFX90AInsts());
+      unsigned OtherGPRPressure =
+          SGPRImportant ? O.getSGPRNum() : O.getVGPRNum(ST.hasGFX90AInsts());
+      // If the pressures are the same, fall through to the subsequent checks
+      if (GPRPressure != OtherGPRPressure)
+        return GPRPressure < OtherGPRPressure;
+    }
----------------
vpykhtin wrote:

This seems reasonable. So in the case when both sides has SGPR and VGPR excess we prefer SGPR?
What if both sides have equal SGPR excess, should we compare VGPR excess then, or vice versa?

https://github.com/llvm/llvm-project/pull/71882


More information about the llvm-commits mailing list