[llvm] [AMDGPU] Add user flag to set min/max number of AGPRs. (PR #216800)

via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 18 08:46:03 PDT 2026


https://github.com/carlobertolli updated https://github.com/llvm/llvm-project/pull/216800

>From 9011dd6011a3850bf2a0efec44d4aa5c2ab70cf9 Mon Sep 17 00:00:00 2001
From: Carlo Bertolli <carlo.bertolli at amd.com>
Date: Mon, 17 Aug 2026 17:58:37 +0000
Subject: [PATCH] [AMDGPU] For gfx90a+ avoid using AGPRs when occupancy >=2.
 When occupancy is 2 or more, users might get AGPR used in generated code for
 mfmas. This is generally not ideal, as using AGPRs eats into the VGPRs budget
 and requires extra handling in code gen.

Assisted-By: Cursor (claude).
---
 llvm/lib/Target/AMDGPU/GCNSubtarget.cpp | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Target/AMDGPU/GCNSubtarget.cpp b/llvm/lib/Target/AMDGPU/GCNSubtarget.cpp
index 1c0e718bd8d97..b25eaec6b9770 100644
--- a/llvm/lib/Target/AMDGPU/GCNSubtarget.cpp
+++ b/llvm/lib/Target/AMDGPU/GCNSubtarget.cpp
@@ -675,8 +675,13 @@ GCNSubtarget::getMaxNumVectorRegs(const Function &F) const {
                                         /*OnlyFirstRequired=*/true);
 
     if (MinNumAGPRs == DefaultNumAGPR.first) {
-      // Default to splitting half the registers if AGPRs are required.
-      MinNumAGPRs = MaxNumAGPRs = MaxVectorRegs / 2;
+      if (getWavesPerEU(F).first >= 2) {
+        // At occupancy >= 2, do not use AGPRs.
+        MinNumAGPRs = MaxNumAGPRs = 0;
+      } else {
+        // Default to splitting half the registers if AGPRs are required.
+        MinNumAGPRs = MaxNumAGPRs = MaxVectorRegs / 2;
+      }
     } else {
       // Align to accum_offset's allocation granularity.
       MinNumAGPRs = alignTo(MinNumAGPRs, 4);



More information about the llvm-commits mailing list