Skip to content

Conversation

@jrbyrnes
Copy link
Contributor

Adds new entries in the GCNPressure array for AVGPR pressure. In this PR, AVGPR pressure is added to pure VGPR pressure under all the pressure queries, so it is NFC.

Separating out this pseudo RC will help us make more informed decisions in future work. This RC can be assigned as either VGPR or AGPR, so tracking them as pure VGPR pressure is not accurate.

Change-Id: Ifcd242c111b139f62109b12b588bb6af764fe4df
@llvmbot
Copy link
Member

llvmbot commented Jul 21, 2025

@llvm/pr-subscribers-backend-amdgpu

Author: Jeffrey Byrnes (jrbyrnes)

Changes

Adds new entries in the GCNPressure array for AVGPR pressure. In this PR, AVGPR pressure is added to pure VGPR pressure under all the pressure queries, so it is NFC.

Separating out this pseudo RC will help us make more informed decisions in future work. This RC can be assigned as either VGPR or AGPR, so tracking them as pure VGPR pressure is not accurate.


Full diff: https://github.com/llvm/llvm-project/pull/149863.diff

2 Files Affected:

  • (modified) llvm/lib/Target/AMDGPU/GCNRegPressure.cpp (+5-1)
  • (modified) llvm/lib/Target/AMDGPU/GCNRegPressure.h (+28-13)
diff --git a/llvm/lib/Target/AMDGPU/GCNRegPressure.cpp b/llvm/lib/Target/AMDGPU/GCNRegPressure.cpp
index 7d6723a6108be..334afd3a2a5b4 100644
--- a/llvm/lib/Target/AMDGPU/GCNRegPressure.cpp
+++ b/llvm/lib/Target/AMDGPU/GCNRegPressure.cpp
@@ -38,7 +38,11 @@ bool llvm::isEqual(const GCNRPTracker::LiveRegSet &S1,
 
 unsigned GCNRegPressure::getRegKind(const TargetRegisterClass *RC,
                                     const SIRegisterInfo *STI) {
-  return STI->isSGPRClass(RC) ? SGPR : (STI->isAGPRClass(RC) ? AGPR : VGPR);
+  return STI->isSGPRClass(RC)
+             ? SGPR
+             : (STI->isAGPRClass(RC)
+                    ? AGPR
+                    : (STI->isVectorSuperClass(RC) ? AVGPR : VGPR));
 }
 
 void GCNRegPressure::inc(unsigned Reg,
diff --git a/llvm/lib/Target/AMDGPU/GCNRegPressure.h b/llvm/lib/Target/AMDGPU/GCNRegPressure.h
index 3749b6d1efc63..5ec898351f922 100644
--- a/llvm/lib/Target/AMDGPU/GCNRegPressure.h
+++ b/llvm/lib/Target/AMDGPU/GCNRegPressure.h
@@ -29,43 +29,58 @@ class raw_ostream;
 class SlotIndex;
 
 struct GCNRegPressure {
-  enum RegKind { SGPR, VGPR, AGPR, TOTAL_KINDS };
+  enum RegKind { SGPR, VGPR, AGPR, AVGPR, TOTAL_KINDS };
 
   GCNRegPressure() {
     clear();
   }
 
-  bool empty() const { return !Value[SGPR] && !Value[VGPR] && !Value[AGPR]; }
+  bool empty() const {
+    return !Value[SGPR] && !Value[VGPR] && !Value[AGPR] && !Value[AVGPR];
+  }
 
   void clear() { std::fill(&Value[0], &Value[ValueArraySize], 0); }
 
   /// \returns the SGPR32 pressure
   unsigned getSGPRNum() const { return Value[SGPR]; }
-  /// \returns the aggregated ArchVGPR32, AccVGPR32 pressure dependent upon \p
-  /// UnifiedVGPRFile
+  /// \returns the aggregated ArchVGPR32, AccVGPR32, and Pseudo AVGPR pressure
+  /// dependent upon \p UnifiedVGPRFile
   unsigned getVGPRNum(bool UnifiedVGPRFile) const {
     if (UnifiedVGPRFile) {
-      return Value[AGPR] ? getUnifiedVGPRNum(Value[VGPR], Value[AGPR])
-                         : Value[VGPR];
+      return Value[AGPR]
+                 ? getUnifiedVGPRNum(Value[VGPR], Value[AGPR], Value[AVGPR])
+                 : Value[VGPR] + Value[AVGPR];
     }
-    return std::max(Value[VGPR], Value[AGPR]);
+    // Until we hit the VGPRThreshold, we will assign AV as VGPR. After that
+    // point, we will assign as AGPR.
+    return std::max(Value[VGPR] + Value[AVGPR], Value[AGPR]);
   }
 
   /// Returns the aggregated VGPR pressure, assuming \p NumArchVGPRs ArchVGPRs
-  /// and \p NumAGPRs AGPRS, for a target with a unified VGPR file.
+  /// \p NumAGPRs AGPRS, and \p NumAVGPRs AVGPRs for a target with a unified
+  /// VGPR file.
   inline static unsigned getUnifiedVGPRNum(unsigned NumArchVGPRs,
-                                           unsigned NumAGPRs) {
-    return alignTo(NumArchVGPRs, AMDGPU::IsaInfo::getArchVGPRAllocGranule()) +
+                                           unsigned NumAGPRs,
+                                           unsigned NumAVGPRs) {
+
+    // Until we hit the VGPRThreshold, we will assign AV as VGPR. After that
+    // point, we will assign as AGPR.
+    return alignTo(NumArchVGPRs + NumAVGPRs,
+                   AMDGPU::IsaInfo::getArchVGPRAllocGranule()) +
            NumAGPRs;
   }
 
-  /// \returns the ArchVGPR32 pressure
-  unsigned getArchVGPRNum() const { return Value[VGPR]; }
+  /// \returns the ArchVGPR32 pressure, plus the AVGPRS which we assume will be
+  /// allocated as VGPR
+  unsigned getArchVGPRNum() const { return Value[VGPR] + Value[AVGPR]; }
   /// \returns the AccVGPR32 pressure
   unsigned getAGPRNum() const { return Value[AGPR]; }
+  /// \returns the AVGPR32 pressure
+  unsigned getAVGPRNum() const { return Value[AVGPR]; }
 
   unsigned getVGPRTuplesWeight() const {
-    return std::max(Value[TOTAL_KINDS + VGPR], Value[TOTAL_KINDS + AGPR]);
+    return std::max(Value[TOTAL_KINDS + VGPR] + Value[TOTAL_KINDS + AVGPR],
+                    Value[TOTAL_KINDS + AGPR]);
   }
   unsigned getSGPRTuplesWeight() const { return Value[TOTAL_KINDS + SGPR]; }
 

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: another mention of VGPRThreshold to remove

@lucas-rami
Copy link
Contributor

The last commit added changes to the scheduler, is this expected or meant to be part of a future change? Asking since it no longer seems NFC with the scheduler/lit test changes.

jrbyrnes added 2 commits July 22, 2025 08:55
Change-Id: I40b174912ad90652dcd5f59a4e4b37300408f6d2
Change-Id: I4a99d3a729a6927d63a7c4fb939fc3a32cde74e0
@jrbyrnes jrbyrnes force-pushed the AVPressureRebase0 branch from 2d5adf9 to ffbb962 Compare July 22, 2025 15:56
@jrbyrnes
Copy link
Contributor Author

The last commit added changes to the scheduler, is this expected or meant to be part of a future change? Asking since it no longer seems NFC with the scheduler/lit test changes.

Oops -- that is going to be a different PR.

@jrbyrnes jrbyrnes merged commit c29094d into llvm:main Jul 25, 2025
9 checks passed
mahesh-attarde pushed a commit to mahesh-attarde/llvm-project that referenced this pull request Jul 28, 2025
Adds new entries in the GCNPressure array for AVGPR pressure. In this
PR, AVGPR pressure is added to pure VGPR pressure under all the pressure
queries, so it is NFC.

Separating out this pseudo RC will help us make more informed decisions
in future work. This RC can be assigned as either VGPR or AGPR, so
tracking them as pure VGPR pressure is not accurate.
jrbyrnes added a commit to jrbyrnes/llvm-project that referenced this pull request Aug 8, 2025
Adds new entries in the GCNPressure array for AVGPR pressure. In this
PR, AVGPR pressure is added to pure VGPR pressure under all the pressure
queries, so it is NFC.

Separating out this pseudo RC will help us make more informed decisions
in future work. This RC can be assigned as either VGPR or AGPR, so
tracking them as pure VGPR pressure is not accurate.
jrbyrnes added a commit to jrbyrnes/llvm-project that referenced this pull request Aug 13, 2025
Adds new entries in the GCNPressure array for AVGPR pressure. In this
PR, AVGPR pressure is added to pure VGPR pressure under all the pressure
queries, so it is NFC.

Separating out this pseudo RC will help us make more informed decisions
in future work. This RC can be assigned as either VGPR or AGPR, so
tracking them as pure VGPR pressure is not accurate.
searlmc1 pushed a commit to ROCm/llvm-project that referenced this pull request Oct 9, 2025
Adds new entries in the GCNPressure array for AVGPR pressure. In this
PR, AVGPR pressure is added to pure VGPR pressure under all the pressure
queries, so it is NFC.

Separating out this pseudo RC will help us make more informed decisions
in future work. This RC can be assigned as either VGPR or AGPR, so
tracking them as pure VGPR pressure is not accurate.
searlmc1 pushed a commit to ROCm/llvm-project that referenced this pull request Oct 9, 2025
…lvm#4095)

This patch fixes a performance regression in rocrand.  See JIRA SWDEV-538318
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants