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

Valery Pykhtin via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 5 07:51:58 PST 2023


================
@@ -88,9 +108,62 @@ void GCNRegPressure::inc(unsigned Reg,
   }
 }
 
-bool GCNRegPressure::less(const GCNSubtarget &ST,
-                          const GCNRegPressure& O,
+bool GCNRegPressure::less(const MachineFunction &MF, const GCNRegPressure &O,
                           unsigned MaxOccupancy) const {
+  const GCNSubtarget &ST = MF.getSubtarget<GCNSubtarget>();
+
+  unsigned MaxVGPRs = ST.getMaxNumVGPRs(MF);
+  unsigned MaxSGPRs = ST.getMaxNumSGPRs(MF);
+
+  unsigned MaxArchVGPRs = ST.getAddressableNumArchVGPRs();
+
+  // Unified excess pressure conditions
+  unsigned ExcessVGPR =
+      std::max(static_cast<int>(getVGPRNum(ST.hasGFX90AInsts()) - MaxVGPRs), 0);
+  // Arch VGPR excess pressure conditions
+  unsigned ExcessArchVGPR =
+      std::max(static_cast<int>(getVGPRNum(false) - MaxArchVGPRs), 0);
+  // AGPR excess pressure conditions
+  unsigned ExcessAGPR = std::max(
+      static_cast<int>(ST.hasGFX90AInsts() ? (getAGPRNum() - MaxArchVGPRs)
+                                           : (getAGPRNum() - MaxVGPRs)),
+      0);
+  // SGPR excess pressure conditions
+  unsigned ExcessSGPR = std::max(static_cast<int>(getSGPRNum() - MaxSGPRs), 0);
+
+  // Unified excess pressure conditions
+  unsigned OtherExcessVGPR = std::max(
+      static_cast<int>(O.getVGPRNum(ST.hasGFX90AInsts()) - MaxVGPRs), 0);
+  // Arch VGPR excess pressure conditions
+  unsigned OtherExcessArchVGPR =
+      std::max(static_cast<int>(O.getVGPRNum(false) - MaxArchVGPRs), 0);
+  // AGPR excess pressure conditions
+  unsigned OtherExcessAGPR = std::max(
+      static_cast<int>(ST.hasGFX90AInsts() ? (O.getAGPRNum() - MaxArchVGPRs)
+                                           : (O.getAGPRNum() - MaxVGPRs)),
+      0);
+  // SGPR excess pressure conditions
+  unsigned OtherExcessSGPR =
+      std::max(static_cast<int>(O.getSGPRNum() - MaxSGPRs), 0);
+
+  bool ExcessRP = ExcessSGPR || ExcessVGPR || ExcessArchVGPR || ExcessAGPR;
+  bool OtherExcessRP = OtherExcessSGPR || OtherExcessVGPR ||
+                       OtherExcessArchVGPR || OtherExcessAGPR;
+  // In regions with spilling, we give precedence to the schedule with
+  // lower general RP.
+  if (ExcessRP || OtherExcessRP) {
+    std::numeric_limits<uint64_t> Max;
+    uint64_t VGPRDiffBase =
----------------
vpykhtin wrote:

unsigned?

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


More information about the llvm-commits mailing list