[llvm] [AMDGPU] Capping max number of registers for indirect calls (PR #199765)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 4 13:53:22 PDT 2026


https://github.com/JoshuaGrindstaff updated https://github.com/llvm/llvm-project/pull/199765

>From 567b5e6ab7091b77efdb184e119a16b656feb018 Mon Sep 17 00:00:00 2001
From: JoshuaGrindstaff <jgrindst at amd.com>
Date: Tue, 26 May 2026 13:05:16 -0500
Subject: [PATCH 01/13] Added min operation for AMDGPUMCExprs

---
 llvm/docs/AMDGPUUsage.rst                     |  3 +
 .../AMDGPU/AsmParser/AMDGPUAsmParser.cpp      |  4 +-
 .../AMDGPU/MCTargetDesc/AMDGPUMCExpr.cpp      | 15 +++++
 .../Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.h |  8 ++-
 llvm/test/MC/AMDGPU/mcexpr_amd.s              | 63 ++++++++++++++++++-
 llvm/test/MC/AMDGPU/mcexpr_amd_err.s          | 11 ++++
 6 files changed, 101 insertions(+), 3 deletions(-)

diff --git a/llvm/docs/AMDGPUUsage.rst b/llvm/docs/AMDGPUUsage.rst
index 61841716792ef..2d2419a5479d7 100644
--- a/llvm/docs/AMDGPUUsage.rst
+++ b/llvm/docs/AMDGPUUsage.rst
@@ -2626,6 +2626,9 @@ As part of the AMDGPU MC layer, AMDGPU provides the following target-specific
      ``max(arg, ...)``   1 or more         Variadic signed operation that returns the maximum
                                            value of all its arguments.
 
+     ``min(arg, ...)``   1 or more         Variadic signed operation that returns the minimum
+                                           value of all its arguments
+
      ``or(arg, ...)``    1 or more         Variadic signed operation that returns the bitwise-or
                                            result of all its arguments.
 
diff --git a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
index c27b96adf7d04..2a9a31e732a6e 100644
--- a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
+++ b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
@@ -9372,7 +9372,8 @@ void AMDGPUAsmParser::onBeginOfFile() {
 /// Parse AMDGPU specific expressions.
 ///
 ///  expr ::= or(expr, ...) |
-///           max(expr, ...)
+///           max(expr, ...) |
+///           min(expr, ...)
 ///
 bool AMDGPUAsmParser::parsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc) {
   using AGVK = AMDGPUMCExpr::VariantKind;
@@ -9381,6 +9382,7 @@ bool AMDGPUAsmParser::parsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc) {
     StringRef TokenId = getTokenStr();
     AGVK VK = StringSwitch<AGVK>(TokenId)
                   .Case("max", AGVK::AGVK_Max)
+                  .Case("min", AGVK::AGVK_Min)
                   .Case("or", AGVK::AGVK_Or)
                   .Case("extrasgprs", AGVK::AGVK_ExtraSGPRs)
                   .Case("totalnumvgprs", AGVK::AGVK_TotalNumVGPRs)
diff --git a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.cpp b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.cpp
index 08871f43a42b5..90ac9147b9eeb 100644
--- a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.cpp
+++ b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.cpp
@@ -65,6 +65,9 @@ void AMDGPUMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
   case AGVK_Max:
     OS << "max(";
     break;
+  case AGVK_Min:
+    OS << "min(";
+    break;
   case AGVK_ExtraSGPRs:
     OS << "extrasgprs(";
     break;
@@ -103,6 +106,8 @@ static int64_t op(AMDGPUMCExpr::VariantKind Kind, int64_t Arg1, int64_t Arg2) {
     return std::max(Arg1, Arg2);
   case AMDGPUMCExpr::AGVK_Or:
     return Arg1 | Arg2;
+  case AMDGPUMCExpr::AGVK_Min:
+    return std::min(Arg1, Arg2);
   }
 }
 
@@ -499,6 +504,16 @@ static void targetOpKnownBitsMapHelper(const MCExpr *Expr, KnownBitsMap &KBM,
     KBM[Expr] = std::move(KB);
     return;
   }
+  case AMDGPUMCExpr::VariantKind::AGVK_Min: {
+    knownBitsMapHelper(AGVK->getSubExpr(0), KBM, Depth + 1);
+    KnownBits KB = KBM[AGVK->getSubExpr(0)];
+    for (const MCExpr *Arg : AGVK->getArgs()) {
+      knownBitsMapHelper(Arg, KBM, Depth + 1);
+      KB = KnownBits::umin(KB, KBM[Arg]);
+    }
+    KBM[Expr] = std::move(KB);
+    return;
+  }
   case AMDGPUMCExpr::VariantKind::AGVK_ExtraSGPRs:
   case AMDGPUMCExpr::VariantKind::AGVK_TotalNumVGPRs:
   case AMDGPUMCExpr::VariantKind::AGVK_AlignTo:
diff --git a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.h b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.h
index 66b6fdb4b0042..33a8f5d21af4c 100644
--- a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.h
+++ b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.h
@@ -24,8 +24,9 @@ enum class LitModifier { None, Lit, Lit64 };
 /// operations are:
 ///   - (bitwise) or
 ///   - max
+///   - min
 ///
-/// \note If the 'or'/'max' operations are provided only a single argument, the
+/// \note If the 'or'/'max'/'min' operations are provided only a single argument, the
 /// operation will act as a no-op and simply resolve as the provided argument.
 ///
 class AMDGPUMCExpr : public MCTargetExpr {
@@ -41,6 +42,7 @@ class AMDGPUMCExpr : public MCTargetExpr {
     AGVK_InstPrefSize,
     AGVK_Lit,
     AGVK_Lit64,
+    AGVK_Min,
   };
 
   // Relocation specifiers.
@@ -85,6 +87,10 @@ class AMDGPUMCExpr : public MCTargetExpr {
                                        MCContext &Ctx) {
     return create(VariantKind::AGVK_Max, Args, Ctx);
   }
+  static const AMDGPUMCExpr *createMin(ArrayRef<const MCExpr *> Args, 
+                                      MCContext &Ctx) {
+    return create(VariantKind::AGVK_Min, Args, Ctx);
+                                      }
 
   static const AMDGPUMCExpr *createExtraSGPRs(const MCExpr *VCCUsed,
                                               const MCExpr *FlatScrUsed,
diff --git a/llvm/test/MC/AMDGPU/mcexpr_amd.s b/llvm/test/MC/AMDGPU/mcexpr_amd.s
index d7340bb5fd2ed..4423d56f50397 100644
--- a/llvm/test/MC/AMDGPU/mcexpr_amd.s
+++ b/llvm/test/MC/AMDGPU/mcexpr_amd.s
@@ -17,7 +17,6 @@
 // OBJDUMP-NEXT: 000000000000000a l       *ABS*  0000000000000000 max_literals
 // OBJDUMP-NEXT: 000000000000000f l       *ABS*  0000000000000000 max_with_max_sym
 // OBJDUMP-NEXT: 000000000000000f l       *ABS*  0000000000000000 max
-// OBJDUMP-NEXT: ffffffffffffffff l       *ABS*  0000000000000000 neg_one
 // OBJDUMP-NEXT: ffffffffffffffff l       *ABS*  0000000000000000 max_neg_numbers
 // OBJDUMP-NEXT: ffffffffffffffff l       *ABS*  0000000000000000 max_neg_number
 // OBJDUMP-NEXT: 0000000000000003 l       *ABS*  0000000000000000 max_with_subexpr
@@ -29,6 +28,24 @@
 // OBJDUMP-NEXT: 8000000000000000 l       *ABS*  0000000000000000 max_expr_one_min
 // OBJDUMP-NEXT: 0000000000000003 l       *ABS*  0000000000000000 max_expr_two_min
 // OBJDUMP-NEXT: 0000000000989680 l       *ABS*  0000000000000000 max_expr_three_min
+// OBJDUMP-NEXT: 0000000000000001 l       *ABS*  0000000000000000 min_expression_all
+// OBJDUMP-NEXT: 0000000000000001 l       *ABS*  0000000000000000 min_expression_two
+// OBJDUMP-NEXT: 0000000000000003 l       *ABS*  0000000000000000 min_expression_one
+// OBJDUMP-NEXT: 0000000000000001 l       *ABS*  0000000000000000 min_literals
+// OBJDUMP-NEXT: 0000000000000000 l       *ABS*  0000000000000000 min_with_min_sym
+// OBJDUMP-NEXT: 0000000000000000 l       *ABS*  0000000000000000 min
+// OBJDUMP-NEXT: ffffffffffffffff l       *ABS*  0000000000000000 neg_one
+// OBJDUMP-NEXT: fffffffffffffffb l       *ABS*  0000000000000000 min_neg_numbers
+// OBJDUMP-NEXT: ffffffffffffffff l       *ABS*  0000000000000000 min_neg_number
+// OBJDUMP-NEXT: 0000000000000003 l       *ABS*  0000000000000000 min_with_subexpr
+// OBJDUMP-NEXT: 0000000000000004 l       *ABS*  0000000000000000 min_as_subexpr
+// OBJDUMP-NEXT: 0000000000000001 l       *ABS*  0000000000000000 min_recursive_subexpr
+// OBJDUMP-NEXT: 7fffffffffffffff l       *ABS*  0000000000000000 min_expr_one_max
+// OBJDUMP-NEXT: 0000000000000003 l       *ABS*  0000000000000000 min_expr_two_max
+// OBJDUMP-NEXT: ffffffffff676980 l       *ABS*  0000000000000000 min_expr_three_max
+// OBJDUMP-NEXT: 8000000000000000 l       *ABS*  0000000000000000 min_expr_one_min
+// OBJDUMP-NEXT: 8000000000000000 l       *ABS*  0000000000000000 min_expr_two_min
+// OBJDUMP-NEXT: 8000000000000000 l       *ABS*  0000000000000000 min_expr_three_min
 // OBJDUMP-NEXT: 0000000000000007 l       *ABS*  0000000000000000 or_expression_all
 // OBJDUMP-NEXT: 0000000000000003 l       *ABS*  0000000000000000 or_expression_two
 // OBJDUMP-NEXT: 0000000000000001 l       *ABS*  0000000000000000 or_expression_one
@@ -97,6 +114,49 @@
 .set max_expr_two_min, max(i64_min, three)
 .set max_expr_three_min, max(i64_min, three, 10000000)
 
+// ASM: .set min_expression_all, min(1, 2, five, 3, four)
+// ASM: .set min_expression_two, 1
+// ASM: .set min_expression_one, 3
+// ASM: .set min_literals, 1
+// ASM: .set min_with_min_sym, min(min, 4, 3, 1, 2)
+
+.set min_expression_all, min(one, two, five, three, four)
+.set min_expression_two, min(one, three)
+.set min_expression_one, min(three)
+.set min_literals, min(1,2,3,4,5,6,7,8,9,10)
+.set min_with_min_sym, min(min, 4, 3, one, two)
+
+// ASM: .set min_neg_numbers, -5
+// ASM: .set min_neg_number, -1
+
+.set neg_one, -1
+.set min_neg_numbers, min(-5, -4, -3, -2, neg_one)
+.set min_neg_number, min(neg_one)
+
+// ASM: .set min_with_subexpr, 3
+// ASM: .set min_as_subexpr, 1+min(4, 3, five)
+// ASM: .set min_recursive_subexpr, min(min(1, four), 3, min_expression_all)
+
+.set min_with_subexpr, min(((one | 3) << 3) / 8)
+.set min_as_subexpr, 1 + min(4, 3, five)
+.set min_recursive_subexpr, min(min(one, four), three, min_expression_all)
+
+// ASM: .set min_expr_one_max, 9223372036854775807
+// ASM: .set min_expr_two_max, 3
+// ASM: .set min_expr_three_max, -10000000
+
+.set min_expr_one_max, min(i64_max)
+.set min_expr_two_max, min(i64_max, three)
+.set min_expr_three_max, min(i64_max, three, -10000000)
+
+// ASM: .set min_expr_one_min, -9223372036854775808
+// ASM: .set min_expr_two_min, min(-9223372036854775808, five)
+// ASM: .set min_expr_three_min, min(-9223372036854775808, five, 10000000)
+
+.set min_expr_one_min, min(i64_min)
+.set min_expr_two_min, min(i64_min, five)
+.set min_expr_three_min, min(i64_min, five, 10000000)
+
 // ASM: .set or_expression_all, or(1, 2, five, 3, four)
 // ASM: .set or_expression_two, 3
 // ASM: .set or_expression_one, 1
@@ -127,4 +187,5 @@
 .set four, 4
 .set five, 5
 .set max, 0xF
+.set min, 0x0
 .set or, 0xFF
diff --git a/llvm/test/MC/AMDGPU/mcexpr_amd_err.s b/llvm/test/MC/AMDGPU/mcexpr_amd_err.s
index 834c6eee8c31f..e97479688c5fe 100644
--- a/llvm/test/MC/AMDGPU/mcexpr_amd_err.s
+++ b/llvm/test/MC/AMDGPU/mcexpr_amd_err.s
@@ -8,6 +8,10 @@
 // ASM: :[[@LINE-1]]:{{[0-9]+}}: error: empty max expression
 // ASM: :[[@LINE-2]]:{{[0-9]+}}: error: missing expression
 
+.set min_empty, min()
+// ASM: :[[@LINE-1]]:{{[0-9]+}}: error: empty min expression
+// ASM: :[[@LINE-2]]:{{[0-9]+}}: error: missing expression
+
 .set or_empty, or()
 // ASM: :[[@LINE-1]]:{{[0-9]+}}: error: empty or expression
 // ASM: :[[@LINE-2]]:{{[0-9]+}}: error: missing expression
@@ -40,6 +44,10 @@
 // ASM: :[[@LINE-1]]:{{[0-9]+}}: error: unexpected token in or expression
 // ASM: :[[@LINE-2]]:{{[0-9]+}}: error: missing expression
 
+.set min_expression_one, min(four,five
+// ASM: :[[@LINE-1]]:{{[0-9]+}}: error: unexpected token in min expression
+// ASM: :[[@LINE-2]]:{{[0-9]+}}: error: missing expression
+
 .set max_no_lparen, max four, five)
 // ASM: :[[@LINE-1]]:{{[0-9]+}}: error: expected newline
 
@@ -49,5 +57,8 @@
 .set max_rparen_only, max)
 // ASM: :[[@LINE-1]]:{{[0-9]+}}: error: expected newline
 
+.set min_no_lparen, min four, five)
+// ASM: :[[@LINE-1]]:{{[0-9]+}}: error: expected newline
+
 .set four, 4
 .set five, 5

>From ea2bceb1113d76d50ac8877452dc6409b1ceaa86 Mon Sep 17 00:00:00 2001
From: JoshuaGrindstaff <jgrindst at amd.com>
Date: Tue, 26 May 2026 14:31:14 -0500
Subject: [PATCH 02/13] Changed SetMaxReg calculation to cap at function max

---
 .../Target/AMDGPU/AMDGPUMCResourceInfo.cpp    | 17 +++++--
 .../CodeGen/AMDGPU/agpr-register-count.ll     |  4 +-
 .../amdpal-metadata-agpr-register-count.ll    |  2 +-
 ...-amdgpu-flat-work-group-size-vgpr-limit.ll | 44 +++++++++----------
 .../AMDGPU/call-graph-register-usage.ll       |  6 +--
 .../CodeGen/AMDGPU/function-resource-usage.ll | 28 ++++++------
 ...-knownbits-assign-crash-gh-issue-110930.ll | 12 ++---
 .../AMDGPU/object-linking-local-resources.ll  |  4 +-
 8 files changed, 64 insertions(+), 53 deletions(-)

diff --git a/llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.cpp b/llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.cpp
index 1731b0463a099..c529219692e9c 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.cpp
@@ -20,6 +20,7 @@
 #include "llvm/MC/MCContext.h"
 #include "llvm/MC/MCSymbol.h"
 #include "llvm/Target/TargetMachine.h"
+#include "GCNSubtarget.h"
 
 #define DEBUG_TYPE "amdgpu-mc-resource-usage"
 
@@ -308,6 +309,8 @@ void MCResourceInfo::gatherResourceInfo(
     }
   });
 
+  const GCNSubtarget &ST = MF.getSubtarget<GCNSubtarget>();
+  auto [MaxAllowedVGPRs, MaxAllowedAGPRs] = ST.getMaxNumVectorRegs(MF.getFunction());
   auto SetMaxReg = [&](MCSymbol *MaxSym, int32_t numRegs,
                        ResourceInfoKind RIK) {
     if (!FRI.HasIndirectCall) {
@@ -316,11 +319,19 @@ void MCResourceInfo::gatherResourceInfo(
     } else {
       const MCExpr *SymRef = MCSymbolRefExpr::create(MaxSym, OutContext);
       MCSymbol *LocalNumSym = getSymbol(FnSym->getName(), RIK, OutContext);
-      const MCExpr *MaxWithLocal = AMDGPUMCExpr::createMax(
+      const MCExpr *RegExpr = AMDGPUMCExpr::createMax(
           {MCConstantExpr::create(numRegs, OutContext), SymRef}, OutContext);
-      LocalNumSym->setVariableValue(MaxWithLocal);
+      if(RIK == RIK_NumVGPR) {
+        RegExpr = AMDGPUMCExpr::createMin(
+          {MCConstantExpr::create(MaxAllowedVGPRs, OutContext),RegExpr},OutContext);
+      }
+      else if (RIK == RIK_NumAGPR) {
+        RegExpr = AMDGPUMCExpr::createMin(
+          {MCConstantExpr::create(MaxAllowedAGPRs, OutContext),RegExpr},OutContext);
+      }
+      LocalNumSym->setVariableValue(RegExpr);
       LLVM_DEBUG(dbgs() << "MCResUse:   " << LocalNumSym->getName()
-                        << ": Indirect callee within, using module maximum\n");
+                        << ": Indirect callee within, using minimum of module maximum and function maximum\n");
     }
   };
 
diff --git a/llvm/test/CodeGen/AMDGPU/agpr-register-count.ll b/llvm/test/CodeGen/AMDGPU/agpr-register-count.ll
index dffde8d25c5f6..46b449514c8bc 100644
--- a/llvm/test/CodeGen/AMDGPU/agpr-register-count.ll
+++ b/llvm/test/CodeGen/AMDGPU/agpr-register-count.ll
@@ -156,8 +156,8 @@ declare void @undef_func()
 ; GCN-LABEL: {{^}}kernel_call_undef_func:
 ; GCN:    .amdhsa_next_free_vgpr max(totalnumvgprs(.Lkernel_call_undef_func.num_agpr, .Lkernel_call_undef_func.num_vgpr), 1, 0)
 ; GFX90A: .amdhsa_accum_offset (((((alignto(max(1, .Lkernel_call_undef_func.num_vgpr), 4)/4)-1)&~65536)&63)+1)*4
-; GCN:    .set .Lkernel_call_undef_func.num_vgpr, max(32, amdgpu.max_num_vgpr)
-; GCN:    .set .Lkernel_call_undef_func.num_agpr, max(0, amdgpu.max_num_agpr)
+; GCN:    .set .Lkernel_call_undef_func.num_vgpr, min(128, max(32, amdgpu.max_num_vgpr))
+; GCN:    .set .Lkernel_call_undef_func.num_agpr, min(128, max(0, amdgpu.max_num_agpr))
 ; GCN:    NumVgprs: .Lkernel_call_undef_func.num_vgpr
 ; GCN:    NumAgprs: .Lkernel_call_undef_func.num_agpr
 ; GCN:    TotalNumVgprs: totalnumvgprs(.Lkernel_call_undef_func.num_agpr, .Lkernel_call_undef_func.num_vgpr)
diff --git a/llvm/test/CodeGen/AMDGPU/amdpal-metadata-agpr-register-count.ll b/llvm/test/CodeGen/AMDGPU/amdpal-metadata-agpr-register-count.ll
index b05c65e73d734..f4c5ec78d23a7 100644
--- a/llvm/test/CodeGen/AMDGPU/amdpal-metadata-agpr-register-count.ll
+++ b/llvm/test/CodeGen/AMDGPU/amdpal-metadata-agpr-register-count.ll
@@ -60,7 +60,7 @@ bb:
 declare void @undef_func()
 
 ; CHECK:      .type          kernel_call_undef_func
-; CHECK:      .set .Lkernel_call_undef_func.num_agpr, max(0, amdgpu.max_num_agpr)
+; CHECK:      .set .Lkernel_call_undef_func.num_agpr, min(128, max(0, amdgpu.max_num_agpr))
 ; CHECK:      NumAgprs: .Lkernel_call_undef_func.num_agpr
 ; CHECK:      .set amdgpu.max_num_agpr, 32
 define amdgpu_kernel void @kernel_call_undef_func() #0 {
diff --git a/llvm/test/CodeGen/AMDGPU/attr-amdgpu-flat-work-group-size-vgpr-limit.ll b/llvm/test/CodeGen/AMDGPU/attr-amdgpu-flat-work-group-size-vgpr-limit.ll
index 57784651591b8..4ea5b04b12641 100644
--- a/llvm/test/CodeGen/AMDGPU/attr-amdgpu-flat-work-group-size-vgpr-limit.ll
+++ b/llvm/test/CodeGen/AMDGPU/attr-amdgpu-flat-work-group-size-vgpr-limit.ll
@@ -547,17 +547,17 @@ define amdgpu_kernel void @f256() #256 {
 attributes #256 = { nounwind "amdgpu-flat-work-group-size"="256,256" }
 
 ; GCN-LABEL: {{^}}f512:
-; GFX9:             .set .Lf512.num_vgpr, max(128, amdgpu.max_num_vgpr)
-; GFX90A:           .set .Lf512.num_vgpr, max(128, amdgpu.max_num_vgpr)
-; GFX90A:           .set .Lf512.num_agpr, max(128, amdgpu.max_num_agpr)
-; GFX10WGP-WAVE32:  .set .Lf512.num_vgpr, max(256, amdgpu.max_num_vgpr)
-; GFX10WGP-WAVE64:  .set .Lf512.num_vgpr, max(256, amdgpu.max_num_vgpr)
-; GFX10CU-WAVE32:   .set .Lf512.num_vgpr, max(128, amdgpu.max_num_vgpr)
-; GFX10CU-WAVE64:   .set .Lf512.num_vgpr, max(128, amdgpu.max_num_vgpr)
-; GFX11WGP-WAVE32:  .set .Lf512.num_vgpr, max(256, amdgpu.max_num_vgpr)
-; GFX11WGP-WAVE64:  .set .Lf512.num_vgpr, max(256, amdgpu.max_num_vgpr)
-; GFX11CU-WAVE32:   .set .Lf512.num_vgpr, max(192, amdgpu.max_num_vgpr)
-; GFX11CU-WAVE64:   .set .Lf512.num_vgpr, max(192, amdgpu.max_num_vgpr)
+; GFX9:             .set .Lf512.num_vgpr, min(128, max(128, amdgpu.max_num_vgpr))
+; GFX90A:           .set .Lf512.num_vgpr, min(128, max(128, amdgpu.max_num_vgpr))
+; GFX90A:           .set .Lf512.num_agpr, min(128, max(128, amdgpu.max_num_agpr))
+; GFX10WGP-WAVE32:  .set .Lf512.num_vgpr, min(256, max(256, amdgpu.max_num_vgpr))
+; GFX10WGP-WAVE64:  .set .Lf512.num_vgpr, min(256, max(256, amdgpu.max_num_vgpr))
+; GFX10CU-WAVE32:   .set .Lf512.num_vgpr, min(128, max(128, amdgpu.max_num_vgpr))
+; GFX10CU-WAVE64:   .set .Lf512.num_vgpr, min(128, max(128, amdgpu.max_num_vgpr))
+; GFX11WGP-WAVE32:  .set .Lf512.num_vgpr, min(256, max(256, amdgpu.max_num_vgpr))
+; GFX11WGP-WAVE64:  .set .Lf512.num_vgpr, min(256, max(256, amdgpu.max_num_vgpr))
+; GFX11CU-WAVE32:   .set .Lf512.num_vgpr, min(192, max(192, amdgpu.max_num_vgpr))
+; GFX11CU-WAVE64:   .set .Lf512.num_vgpr, min(192, max(192, amdgpu.max_num_vgpr))
 ; GCN:              NumVgprs: .Lf512.num_vgpr
 ; GFX90A:           NumAgprs: .Lf512.num_agpr
 ; GFX90A:           TotalNumVgprs: totalnumvgprs(.Lf512.num_agpr, .Lf512.num_vgpr)
@@ -569,17 +569,17 @@ define amdgpu_kernel void @f512() #512 {
 attributes #512 = { nounwind "amdgpu-flat-work-group-size"="512,512" }
 
 ; GCN-LABEL: {{^}}f1024:
-; GFX9:             .set .Lf1024.num_vgpr, max(64, amdgpu.max_num_vgpr)
-; GFX90A:           .set .Lf1024.num_vgpr, max(64, amdgpu.max_num_vgpr)
-; GFX90A:           .set .Lf1024.num_agpr, max(64, amdgpu.max_num_agpr)
-; GFX10WGP-WAVE32:  .set .Lf1024.num_vgpr, max(128, amdgpu.max_num_vgpr)
-; GFX10WGP-WAVE64:  .set .Lf1024.num_vgpr, max(128, amdgpu.max_num_vgpr)
-; GFX10CU-WAVE32:   .set .Lf1024.num_vgpr, max(64, amdgpu.max_num_vgpr)
-; GFX10CU-WAVE64:   .set .Lf1024.num_vgpr, max(64, amdgpu.max_num_vgpr)
-; GFX11WGP-WAVE32:  .set .Lf1024.num_vgpr, max(192, amdgpu.max_num_vgpr)
-; GFX11WGP-WAVE64:  .set .Lf1024.num_vgpr, max(192, amdgpu.max_num_vgpr)
-; GFX11CU-WAVE32:   .set .Lf1024.num_vgpr, max(96, amdgpu.max_num_vgpr)
-; GFX11CU-WAVE64:   .set .Lf1024.num_vgpr, max(96, amdgpu.max_num_vgpr)
+; GFX9:             .set .Lf1024.num_vgpr, min(64, max(64, amdgpu.max_num_vgpr))
+; GFX90A:           .set .Lf1024.num_vgpr, min(64, max(64, amdgpu.max_num_vgpr))
+; GFX90A:           .set .Lf1024.num_agpr, min(64, max(64, amdgpu.max_num_agpr))
+; GFX10WGP-WAVE32:  .set .Lf1024.num_vgpr, min(128, max(128, amdgpu.max_num_vgpr))
+; GFX10WGP-WAVE64:  .set .Lf1024.num_vgpr, min(128, max(128, amdgpu.max_num_vgpr))
+; GFX10CU-WAVE32:   .set .Lf1024.num_vgpr, min(64, max(64, amdgpu.max_num_vgpr))
+; GFX10CU-WAVE64:   .set .Lf1024.num_vgpr, min(64, max(64, amdgpu.max_num_vgpr))
+; GFX11WGP-WAVE32:  .set .Lf1024.num_vgpr, min(192, max(192, amdgpu.max_num_vgpr))
+; GFX11WGP-WAVE64:  .set .Lf1024.num_vgpr, min(192, max(192, amdgpu.max_num_vgpr))
+; GFX11CU-WAVE32:   .set .Lf1024.num_vgpr, min(96, max(96, amdgpu.max_num_vgpr))
+; GFX11CU-WAVE64:   .set .Lf1024.num_vgpr, min(96, max(96, amdgpu.max_num_vgpr))
 ; GCN:              NumVgprs: .Lf1024.num_vgpr
 ; GFX90A:           NumAgprs: .Lf1024.num_agpr
 ; GFX90A:           TotalNumVgprs: totalnumvgprs(.Lf1024.num_agpr, .Lf1024.num_vgpr)
diff --git a/llvm/test/CodeGen/AMDGPU/call-graph-register-usage.ll b/llvm/test/CodeGen/AMDGPU/call-graph-register-usage.ll
index 1d6299b5fc177..2395b317f7988 100644
--- a/llvm/test/CodeGen/AMDGPU/call-graph-register-usage.ll
+++ b/llvm/test/CodeGen/AMDGPU/call-graph-register-usage.ll
@@ -239,7 +239,7 @@ define amdgpu_kernel void @usage_direct_recursion(i32 %n) #0 {
 ; Make sure there's no assert when a sgpr96 is used.
 ; GCN-LABEL: {{^}}count_use_sgpr96_external_call
 ; GCN: ; sgpr96 s[{{[0-9]+}}:{{[0-9]+}}]
-; GCN: .set .Lcount_use_sgpr96_external_call.num_vgpr, max(0, amdgpu.max_num_vgpr)
+; GCN: .set .Lcount_use_sgpr96_external_call.num_vgpr, min(64, max(0, amdgpu.max_num_vgpr))
 ; GCN: .set .Lcount_use_sgpr96_external_call.numbered_sgpr, max(33, amdgpu.max_num_sgpr)
 ; CI: TotalNumSgprs: .Lcount_use_sgpr96_external_call.numbered_sgpr+4
 ; VI-BUG: TotalNumSgprs: 96
@@ -254,7 +254,7 @@ entry:
 ; Make sure there's no assert when a sgpr160 is used.
 ; GCN-LABEL: {{^}}count_use_sgpr160_external_call
 ; GCN: ; sgpr160 s[{{[0-9]+}}:{{[0-9]+}}]
-; GCN: .set .Lcount_use_sgpr160_external_call.num_vgpr, max(0, amdgpu.max_num_vgpr)
+; GCN: .set .Lcount_use_sgpr160_external_call.num_vgpr, min(64, max(0, amdgpu.max_num_vgpr))
 ; GCN: .set .Lcount_use_sgpr160_external_call.numbered_sgpr, max(33, amdgpu.max_num_sgpr)
 ; CI: TotalNumSgprs: .Lcount_use_sgpr160_external_call.numbered_sgpr+4
 ; VI-BUG: TotalNumSgprs: 96
@@ -269,7 +269,7 @@ entry:
 ; Make sure there's no assert when a vgpr160 is used.
 ; GCN-LABEL: {{^}}count_use_vgpr160_external_call
 ; GCN: ; vgpr160 v[{{[0-9]+}}:{{[0-9]+}}]
-; GCN: .set .Lcount_use_vgpr160_external_call.num_vgpr, max(5, amdgpu.max_num_vgpr)
+; GCN: .set .Lcount_use_vgpr160_external_call.num_vgpr, min(64, max(5, amdgpu.max_num_vgpr))
 ; GCN: .set .Lcount_use_vgpr160_external_call.numbered_sgpr, max(33, amdgpu.max_num_sgpr)
 ; CI: TotalNumSgprs: .Lcount_use_vgpr160_external_call.numbered_sgpr+4
 ; VI-BUG: TotalNumSgprs: 96
diff --git a/llvm/test/CodeGen/AMDGPU/function-resource-usage.ll b/llvm/test/CodeGen/AMDGPU/function-resource-usage.ll
index 2c9778e1db5e5..d7fe355f9cf4f 100644
--- a/llvm/test/CodeGen/AMDGPU/function-resource-usage.ll
+++ b/llvm/test/CodeGen/AMDGPU/function-resource-usage.ll
@@ -356,8 +356,8 @@ define amdgpu_kernel void @multi_call_use_use_stack() #0 {
 declare void @external() #0
 
 ; GCN-LABEL: {{^}}multi_call_with_external:
-; GCN:	.set .Lmulti_call_with_external.num_vgpr, max(41, amdgpu.max_num_vgpr)
-; GCN:	.set .Lmulti_call_with_external.num_agpr, max(0, amdgpu.max_num_agpr)
+; GCN:	.set .Lmulti_call_with_external.num_vgpr, min(64, max(41, amdgpu.max_num_vgpr))
+; GCN:	.set .Lmulti_call_with_external.num_agpr, min(0, max(0, amdgpu.max_num_agpr))
 ; GCN:	.set .Lmulti_call_with_external.numbered_sgpr, max(52, amdgpu.max_num_sgpr)
 ; GCN:	.set .Lmulti_call_with_external.private_seg_size, 0+max(.Luse_stack0.private_seg_size, .Luse_stack1.private_seg_size)
 ; GCN:	.set .Lmulti_call_with_external.uses_vcc, 1
@@ -376,8 +376,8 @@ define amdgpu_kernel void @multi_call_with_external() #0 {
 }
 
 ; GCN-LABEL: {{^}}multi_call_with_external_and_duplicates:
-; GCN:	.set .Lmulti_call_with_external_and_duplicates.num_vgpr, max(41, amdgpu.max_num_vgpr)
-; GCN:	.set .Lmulti_call_with_external_and_duplicates.num_agpr, max(0, amdgpu.max_num_agpr)
+; GCN:	.set .Lmulti_call_with_external_and_duplicates.num_vgpr, min(64, max(41, amdgpu.max_num_vgpr))
+; GCN:	.set .Lmulti_call_with_external_and_duplicates.num_agpr, min(0, max(0, amdgpu.max_num_agpr))
 ; GCN:	.set .Lmulti_call_with_external_and_duplicates.numbered_sgpr, max(54, amdgpu.max_num_sgpr)
 ; GCN:	.set .Lmulti_call_with_external_and_duplicates.private_seg_size, 0+max(.Luse_stack0.private_seg_size, .Luse_stack1.private_seg_size)
 ; GCN:	.set .Lmulti_call_with_external_and_duplicates.uses_vcc, 1
@@ -399,8 +399,8 @@ define amdgpu_kernel void @multi_call_with_external_and_duplicates() #0 {
 }
 
 ; GCN-LABEL: {{^}}usage_external:
-; GCN:	.set .Lusage_external.num_vgpr, max(32, amdgpu.max_num_vgpr)
-; GCN:	.set .Lusage_external.num_agpr, max(0, amdgpu.max_num_agpr)
+; GCN:	.set .Lusage_external.num_vgpr, min(64, max(32, amdgpu.max_num_vgpr))
+; GCN:	.set .Lusage_external.num_agpr, min(0, max(0, amdgpu.max_num_agpr))
 ; GCN:	.set .Lusage_external.numbered_sgpr, max(33, amdgpu.max_num_sgpr)
 ; GCN:	.set .Lusage_external.private_seg_size, 0
 ; GCN:	.set .Lusage_external.uses_vcc, 1
@@ -419,8 +419,8 @@ define amdgpu_kernel void @usage_external() #0 {
 declare void @external_recurse() #2
 
 ; GCN-LABEL: {{^}}usage_external_recurse:
-; GCN:	.set .Lusage_external_recurse.num_vgpr, max(32, amdgpu.max_num_vgpr)
-; GCN:	.set .Lusage_external_recurse.num_agpr, max(0, amdgpu.max_num_agpr)
+; GCN:	.set .Lusage_external_recurse.num_vgpr, min(64, max(32, amdgpu.max_num_vgpr))
+; GCN:	.set .Lusage_external_recurse.num_agpr, min(0, max(0, amdgpu.max_num_agpr))
 ; GCN:	.set .Lusage_external_recurse.numbered_sgpr, max(33, amdgpu.max_num_sgpr)
 ; GCN:	.set .Lusage_external_recurse.private_seg_size, 0
 ; GCN:	.set .Lusage_external_recurse.uses_vcc, 1
@@ -614,8 +614,8 @@ define amdgpu_kernel void @multi_call_with_multi_stage_recurse(i32 %n) #0 {
 
 ; Make sure there's no assert when a sgpr96 is used.
 ; GCN-LABEL: {{^}}count_use_sgpr96_external_call
-; GCN:	.set .Lcount_use_sgpr96_external_call.num_vgpr, max(32, amdgpu.max_num_vgpr)
-; GCN:	.set .Lcount_use_sgpr96_external_call.num_agpr, max(0, amdgpu.max_num_agpr)
+; GCN:	.set .Lcount_use_sgpr96_external_call.num_vgpr, min(64, max(32, amdgpu.max_num_vgpr))
+; GCN:	.set .Lcount_use_sgpr96_external_call.num_agpr, min(0, max(0, amdgpu.max_num_agpr))
 ; GCN:	.set .Lcount_use_sgpr96_external_call.numbered_sgpr, max(33, amdgpu.max_num_sgpr)
 ; GCN:	.set .Lcount_use_sgpr96_external_call.private_seg_size, 0
 ; GCN:	.set .Lcount_use_sgpr96_external_call.uses_vcc, 1
@@ -635,8 +635,8 @@ entry:
 
 ; Make sure there's no assert when a sgpr160 is used.
 ; GCN-LABEL: {{^}}count_use_sgpr160_external_call
-; GCN:	.set .Lcount_use_sgpr160_external_call.num_vgpr, max(32, amdgpu.max_num_vgpr)
-; GCN:	.set .Lcount_use_sgpr160_external_call.num_agpr, max(0, amdgpu.max_num_agpr)
+; GCN:	.set .Lcount_use_sgpr160_external_call.num_vgpr, min(64, max(32, amdgpu.max_num_vgpr))
+; GCN:	.set .Lcount_use_sgpr160_external_call.num_agpr, min(0, max(0, amdgpu.max_num_agpr))
 ; GCN:	.set .Lcount_use_sgpr160_external_call.numbered_sgpr, max(33, amdgpu.max_num_sgpr)
 ; GCN:	.set .Lcount_use_sgpr160_external_call.private_seg_size, 0
 ; GCN:	.set .Lcount_use_sgpr160_external_call.uses_vcc, 1
@@ -656,8 +656,8 @@ entry:
 
 ; Make sure there's no assert when a vgpr160 is used.
 ; GCN-LABEL: {{^}}count_use_vgpr160_external_call
-; GCN:	.set .Lcount_use_vgpr160_external_call.num_vgpr, max(32, amdgpu.max_num_vgpr)
-; GCN:	.set .Lcount_use_vgpr160_external_call.num_agpr, max(0, amdgpu.max_num_agpr)
+; GCN:	.set .Lcount_use_vgpr160_external_call.num_vgpr, min(64, max(32, amdgpu.max_num_vgpr))
+; GCN:	.set .Lcount_use_vgpr160_external_call.num_agpr, min(0, max(0, amdgpu.max_num_agpr))
 ; GCN:	.set .Lcount_use_vgpr160_external_call.numbered_sgpr, max(33, amdgpu.max_num_sgpr)
 ; GCN:	.set .Lcount_use_vgpr160_external_call.private_seg_size, 0
 ; GCN:	.set .Lcount_use_vgpr160_external_call.uses_vcc, 1
diff --git a/llvm/test/CodeGen/AMDGPU/mcexpr-knownbits-assign-crash-gh-issue-110930.ll b/llvm/test/CodeGen/AMDGPU/mcexpr-knownbits-assign-crash-gh-issue-110930.ll
index cd9a18571815e..1753a88e40cc5 100644
--- a/llvm/test/CodeGen/AMDGPU/mcexpr-knownbits-assign-crash-gh-issue-110930.ll
+++ b/llvm/test/CodeGen/AMDGPU/mcexpr-knownbits-assign-crash-gh-issue-110930.ll
@@ -6,8 +6,8 @@
 ; use-after-free if the assignment operator invokes a DenseMap growth.
 
 ; CHECK-LABEL: I_Quit:
-; CHECK: .set .LI_Quit.num_vgpr, max(41, amdgpu.max_num_vgpr)
-; CHECK: .set .LI_Quit.num_agpr, max(0, amdgpu.max_num_agpr)
+; CHECK: .set .LI_Quit.num_vgpr, min(128, max(41, amdgpu.max_num_vgpr))
+; CHECK: .set .LI_Quit.num_agpr, min(0, max(0, amdgpu.max_num_agpr))
 ; CHECK: .set .LI_Quit.numbered_sgpr, max(56, amdgpu.max_num_sgpr)
 ; CHECK: .set .LI_Quit.private_seg_size, 16
 ; CHECK: .set .LI_Quit.uses_vcc, 1
@@ -78,8 +78,8 @@ define void @P_SetThingPosition() {
 }
 
 ; CHECK-LABEL: P_SetupPsprites:
-; CHECK: .set .LP_SetupPsprites.num_vgpr, max(41, amdgpu.max_num_vgpr)
-; CHECK: .set .LP_SetupPsprites.num_agpr, max(0, amdgpu.max_num_agpr)
+; CHECK: .set .LP_SetupPsprites.num_vgpr, min(128, max(41, amdgpu.max_num_vgpr))
+; CHECK: .set .LP_SetupPsprites.num_agpr, min(0, max(0, amdgpu.max_num_agpr))
 ; CHECK: .set .LP_SetupPsprites.numbered_sgpr, max(56, amdgpu.max_num_sgpr)
 ; CHECK: .set .LP_SetupPsprites.private_seg_size, 16
 ; CHECK: .set .LP_SetupPsprites.uses_vcc, 1
@@ -126,8 +126,8 @@ define void @P_SpawnPlayer() {
 }
 
 ; CHECK-LABEL: I_Error:
-; CHECK: .set .LI_Error.num_vgpr, max(41, amdgpu.max_num_vgpr)
-; CHECK: .set .LI_Error.num_agpr, max(0, amdgpu.max_num_agpr)
+; CHECK: .set .LI_Error.num_vgpr, min(128, max(41, amdgpu.max_num_vgpr))
+; CHECK: .set .LI_Error.num_agpr, min(0, max(0, amdgpu.max_num_agpr))
 ; CHECK: .set .LI_Error.numbered_sgpr, max(56, amdgpu.max_num_sgpr)
 ; CHECK: .set .LI_Error.private_seg_size, 16
 ; CHECK: .set .LI_Error.uses_vcc, 1
diff --git a/llvm/test/CodeGen/AMDGPU/object-linking-local-resources.ll b/llvm/test/CodeGen/AMDGPU/object-linking-local-resources.ll
index 95214bcf7c06d..5d604705e0d25 100644
--- a/llvm/test/CodeGen/AMDGPU/object-linking-local-resources.ll
+++ b/llvm/test/CodeGen/AMDGPU/object-linking-local-resources.ll
@@ -28,8 +28,8 @@ define amdgpu_kernel void @my_kernel(ptr %fptr) {
 ; COM: callee" path. Register/stack-size symbols include the module-level
 ; COM: sinks; boolean flags are all forced to 1; HasIndirectCall is set too
 ; COM: (IsIndirect covers calls to declarations).
-; DEFAULT:       .set .Lcalls_extern.num_vgpr, max({{[0-9]+}}, amdgpu.max_num_vgpr)
-; DEFAULT:       .set .Lcalls_extern.num_agpr, max({{[0-9]+}}, amdgpu.max_num_agpr)
+; DEFAULT:       .set .Lcalls_extern.num_vgpr, min(64, max({{[0-9]+}}, amdgpu.max_num_vgpr))
+; DEFAULT:       .set .Lcalls_extern.num_agpr, min(0, max({{[0-9]+}}, amdgpu.max_num_agpr))
 ; DEFAULT:       .set .Lcalls_extern.numbered_sgpr, max({{[0-9]+}}, amdgpu.max_num_sgpr)
 ; DEFAULT:       .set .Lcalls_extern.num_named_barrier, max({{[0-9]+}}, amdgpu.max_num_named_barrier)
 ; DEFAULT:       .set .Lcalls_extern.uses_vcc, 1

>From 48e4122f348c9ecbcd49a894fec1c6f9bd6f26c5 Mon Sep 17 00:00:00 2001
From: JoshuaGrindstaff <jgrindst at amd.com>
Date: Wed, 27 May 2026 15:17:14 -0500
Subject: [PATCH 03/13] Fix Formating

---
 llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.h | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.h b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.h
index 33a8f5d21af4c..369545fa79cea 100644
--- a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.h
+++ b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.h
@@ -26,8 +26,9 @@ enum class LitModifier { None, Lit, Lit64 };
 ///   - max
 ///   - min
 ///
-/// \note If the 'or'/'max'/'min' operations are provided only a single argument, the
-/// operation will act as a no-op and simply resolve as the provided argument.
+/// \note If the 'or'/'max'/'min' operations are provided only a single
+/// argument, the operation will act as a no-op and simply resolve as the
+/// provided argument.
 ///
 class AMDGPUMCExpr : public MCTargetExpr {
 public:
@@ -87,10 +88,10 @@ class AMDGPUMCExpr : public MCTargetExpr {
                                        MCContext &Ctx) {
     return create(VariantKind::AGVK_Max, Args, Ctx);
   }
-  static const AMDGPUMCExpr *createMin(ArrayRef<const MCExpr *> Args, 
-                                      MCContext &Ctx) {
+  static const AMDGPUMCExpr *createMin(ArrayRef<const MCExpr *> Args,
+                                       MCContext &Ctx) {
     return create(VariantKind::AGVK_Min, Args, Ctx);
-                                      }
+  }
 
   static const AMDGPUMCExpr *createExtraSGPRs(const MCExpr *VCCUsed,
                                               const MCExpr *FlatScrUsed,

>From eff9e301a8c5910b187e06f2a9b1eef1a94a35c5 Mon Sep 17 00:00:00 2001
From: JoshuaGrindstaff <jgrindst at amd.com>
Date: Fri, 29 May 2026 15:47:51 -0500
Subject: [PATCH 04/13] Changing umin and umax to smin and smax for known bits

---
 llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.cpp b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.cpp
index 90ac9147b9eeb..9a4c4ebddd50b 100644
--- a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.cpp
+++ b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.cpp
@@ -499,7 +499,7 @@ static void targetOpKnownBitsMapHelper(const MCExpr *Expr, KnownBitsMap &KBM,
     KnownBits KB = KBM[AGVK->getSubExpr(0)];
     for (const MCExpr *Arg : AGVK->getArgs()) {
       knownBitsMapHelper(Arg, KBM, Depth + 1);
-      KB = KnownBits::umax(KB, KBM[Arg]);
+      KB = KnownBits::smax(KB, KBM[Arg]);
     }
     KBM[Expr] = std::move(KB);
     return;
@@ -509,7 +509,7 @@ static void targetOpKnownBitsMapHelper(const MCExpr *Expr, KnownBitsMap &KBM,
     KnownBits KB = KBM[AGVK->getSubExpr(0)];
     for (const MCExpr *Arg : AGVK->getArgs()) {
       knownBitsMapHelper(Arg, KBM, Depth + 1);
-      KB = KnownBits::umin(KB, KBM[Arg]);
+      KB = KnownBits::smin(KB, KBM[Arg]);
     }
     KBM[Expr] = std::move(KB);
     return;

>From d81903472f31b2be86d97d61cbacacf5dc160693 Mon Sep 17 00:00:00 2001
From: JoshuaGrindstaff <jgrindst at amd.com>
Date: Mon, 1 Jun 2026 16:49:15 -0500
Subject: [PATCH 05/13] Added unit tests for AMDGPUExpr folding for negative
 numbers

---
 .../Target/AMDGPU/AMDGPUMCExprTest.cpp        | 109 ++++++++++++++++++
 llvm/unittests/Target/AMDGPU/CMakeLists.txt   |   1 +
 2 files changed, 110 insertions(+)
 create mode 100644 llvm/unittests/Target/AMDGPU/AMDGPUMCExprTest.cpp

diff --git a/llvm/unittests/Target/AMDGPU/AMDGPUMCExprTest.cpp b/llvm/unittests/Target/AMDGPU/AMDGPUMCExprTest.cpp
new file mode 100644
index 0000000000000..3b94d7275df9a
--- /dev/null
+++ b/llvm/unittests/Target/AMDGPU/AMDGPUMCExprTest.cpp
@@ -0,0 +1,109 @@
+//===- llvm/unittests/MC/AMDGPU/AMDGPUMCExprTest.cpp ---------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "AMDGPUTargetMachine.h"
+#include "AMDGPUUnitTests.h"
+#include "GCNSubtarget.h"
+#include "SIProgramInfo.h"
+#include "MCTargetDesc/AMDGPUMCExpr.h"
+#include "Utils/AMDGPUPALMetadata.h"
+#include "llvm/CodeGen/MachineModuleInfo.h"
+#include "llvm/MC/MCContext.h"
+#include "llvm/MC/MCExpr.h"
+#include "llvm/MC/MCStreamer.h"
+#include "llvm/MC/MCSymbol.h"
+#include "llvm/MC/MCTargetOptions.h"
+#include "llvm/MC/TargetRegistry.h"
+#include "llvm/Target/TargetMachine.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+
+class AMDGPUMCExprTest : public AMDGPUTestBase {
+
+protected:
+  std::unique_ptr<GCNTargetMachine> TM;
+  std::unique_ptr<LLVMContext> LLVMCtx;
+  std::unique_ptr<GCNSubtarget> ST;
+  std::unique_ptr<MachineModuleInfo> MMI;
+  std::unique_ptr<MachineFunction> MF;
+  std::unique_ptr<Module> M;
+  AMDGPUPALMetadata MD;
+
+  AMDGPUMCExprTest() {
+    
+    TM = createAMDGPUTargetMachine("amdgcn--amdpal", "gfx1010", "");
+
+    LLVMCtx = std::make_unique<LLVMContext>();
+    M = std::make_unique<Module>("Module", *LLVMCtx);
+    M->setDataLayout(TM->createDataLayout());
+    auto *FType = FunctionType::get(Type::getVoidTy(*LLVMCtx), false);
+    auto *F = Function::Create(FType, GlobalValue::ExternalLinkage, "Test", *M);
+    MMI = std::make_unique<MachineModuleInfo>(TM.get());
+
+    ST = std::make_unique<GCNSubtarget>(TM->getTargetTriple(),
+                                        TM->getTargetCPU(),
+                                        TM->getTargetFeatureString(), *TM);
+
+    MF = std::make_unique<MachineFunction>(*F, *TM, *ST, MMI->getContext(), 1);
+  }
+};
+//Next two tests showcases the folding of foldAMDGPUMCExpr function that uses KnownBits to simplify expressions as much as possible
+// max(((external_unknown & 0) | 0x8000000000000000), 5)
+TEST_F(AMDGPUMCExprTest, MaxFoldKnownBitsSignedness){
+  MCContext &Ctx = MF->getContext();
+
+  // Set up the unknown/undefined part of the expression
+  MCSymbol *Sym = Ctx.getOrCreateSymbol("external_unknown");
+  const MCExpr *SymRef = MCSymbolRefExpr::create(Sym, Ctx);
+
+  // Set up the rest of the expression
+  const MCExpr *Masked = MCBinaryExpr::createAnd(
+      SymRef, MCConstantExpr::create(0, Ctx),Ctx);
+  const MCExpr *SignBit = AMDGPUMCExpr::createOr({
+      Masked, MCConstantExpr::create(INT64_MIN, Ctx)}, Ctx);
+  const MCExpr *MaxExpr = AMDGPUMCExpr::createMax({
+      SignBit, MCConstantExpr::create(5, Ctx)}, Ctx);
+  
+  // running evaluateAsAbsolute will fail since external_unknown is undefined.
+  int64_t RuntimeRst;
+  EXPECT_FALSE(MaxExpr->evaluateAsAbsolute(RuntimeRst));
+
+  // fold expression and then running evaluateAsAbsolute should now succeed with the correct rst
+  const MCExpr *Folded = AMDGPU::foldAMDGPUMCExpr(MaxExpr, Ctx);
+  int64_t FoldedVal;
+  ASSERT_TRUE(Folded->evaluateAsAbsolute(FoldedVal));
+  EXPECT_EQ(FoldedVal, int64_t{5});
+}
+
+// min(((external_unknown & 0) | 0x8000000000000000), 5)
+TEST_F(AMDGPUMCExprTest, MinFolddKnownBitsSignedness){
+  MCContext &Ctx = MF->getContext();
+
+  // Set up the unknown/undefined part of the expression
+  MCSymbol *Sym = Ctx.getOrCreateSymbol("external_unknown");
+  const MCExpr *SymRef = MCSymbolRefExpr::create(Sym, Ctx);
+
+  // Set up the rest of the expression
+  const MCExpr *Masked = MCBinaryExpr::createAnd(
+      SymRef, MCConstantExpr::create(0, Ctx),Ctx);
+  const MCExpr *SignBit = AMDGPUMCExpr::createOr({
+      Masked, MCConstantExpr::create(INT64_MIN, Ctx)}, Ctx);
+  const MCExpr *MinExpr = AMDGPUMCExpr::createMin({
+      SignBit, MCConstantExpr::create(5, Ctx)}, Ctx);
+
+  // running evaluateAsAbsolute will fail since external_unknown is undefined.
+  int64_t AbsoluteRst;
+  EXPECT_FALSE(MinExpr->evaluateAsAbsolute(AbsoluteRst));
+
+  // fold expression and then running evaluateAsAbsolute should now succeed with the correct rst
+  const MCExpr *Folded = AMDGPU::foldAMDGPUMCExpr(MinExpr, Ctx);
+  int64_t FoldedVal;
+  ASSERT_TRUE(Folded->evaluateAsAbsolute(FoldedVal));
+  EXPECT_EQ(FoldedVal, INT64_MIN);
+}
\ No newline at end of file
diff --git a/llvm/unittests/Target/AMDGPU/CMakeLists.txt b/llvm/unittests/Target/AMDGPU/CMakeLists.txt
index bbd426f56342c..77335a57520bc 100644
--- a/llvm/unittests/Target/AMDGPU/CMakeLists.txt
+++ b/llvm/unittests/Target/AMDGPU/CMakeLists.txt
@@ -23,6 +23,7 @@ set(LLVM_LINK_COMPONENTS
   )
 
 add_llvm_target_unittest(AMDGPUTests
+  AMDGPUMCExprTest.cpp
   AMDGPUUnitTests.cpp
   CSETest.cpp
   DwarfRegMappings.cpp

>From b9c792a532b4dc2d2c7582eecdebc1105cc80bbe Mon Sep 17 00:00:00 2001
From: JoshuaGrindstaff <jgrindst at amd.com>
Date: Mon, 1 Jun 2026 17:34:58 -0500
Subject: [PATCH 06/13] fix formating

---
 .../Target/AMDGPU/AMDGPUMCExprTest.cpp        | 220 +++++++++---------
 1 file changed, 112 insertions(+), 108 deletions(-)

diff --git a/llvm/unittests/Target/AMDGPU/AMDGPUMCExprTest.cpp b/llvm/unittests/Target/AMDGPU/AMDGPUMCExprTest.cpp
index 3b94d7275df9a..7727011032333 100644
--- a/llvm/unittests/Target/AMDGPU/AMDGPUMCExprTest.cpp
+++ b/llvm/unittests/Target/AMDGPU/AMDGPUMCExprTest.cpp
@@ -1,109 +1,113 @@
-//===- llvm/unittests/MC/AMDGPU/AMDGPUMCExprTest.cpp ---------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include "AMDGPUTargetMachine.h"
-#include "AMDGPUUnitTests.h"
-#include "GCNSubtarget.h"
-#include "SIProgramInfo.h"
-#include "MCTargetDesc/AMDGPUMCExpr.h"
-#include "Utils/AMDGPUPALMetadata.h"
-#include "llvm/CodeGen/MachineModuleInfo.h"
-#include "llvm/MC/MCContext.h"
-#include "llvm/MC/MCExpr.h"
-#include "llvm/MC/MCStreamer.h"
-#include "llvm/MC/MCSymbol.h"
-#include "llvm/MC/MCTargetOptions.h"
-#include "llvm/MC/TargetRegistry.h"
-#include "llvm/Target/TargetMachine.h"
-#include "gtest/gtest.h"
-
-using namespace llvm;
-
-class AMDGPUMCExprTest : public AMDGPUTestBase {
-
-protected:
-  std::unique_ptr<GCNTargetMachine> TM;
-  std::unique_ptr<LLVMContext> LLVMCtx;
-  std::unique_ptr<GCNSubtarget> ST;
-  std::unique_ptr<MachineModuleInfo> MMI;
-  std::unique_ptr<MachineFunction> MF;
-  std::unique_ptr<Module> M;
-  AMDGPUPALMetadata MD;
-
-  AMDGPUMCExprTest() {
-    
-    TM = createAMDGPUTargetMachine("amdgcn--amdpal", "gfx1010", "");
-
-    LLVMCtx = std::make_unique<LLVMContext>();
-    M = std::make_unique<Module>("Module", *LLVMCtx);
-    M->setDataLayout(TM->createDataLayout());
-    auto *FType = FunctionType::get(Type::getVoidTy(*LLVMCtx), false);
-    auto *F = Function::Create(FType, GlobalValue::ExternalLinkage, "Test", *M);
-    MMI = std::make_unique<MachineModuleInfo>(TM.get());
-
-    ST = std::make_unique<GCNSubtarget>(TM->getTargetTriple(),
-                                        TM->getTargetCPU(),
-                                        TM->getTargetFeatureString(), *TM);
-
-    MF = std::make_unique<MachineFunction>(*F, *TM, *ST, MMI->getContext(), 1);
-  }
-};
-//Next two tests showcases the folding of foldAMDGPUMCExpr function that uses KnownBits to simplify expressions as much as possible
-// max(((external_unknown & 0) | 0x8000000000000000), 5)
-TEST_F(AMDGPUMCExprTest, MaxFoldKnownBitsSignedness){
-  MCContext &Ctx = MF->getContext();
-
-  // Set up the unknown/undefined part of the expression
-  MCSymbol *Sym = Ctx.getOrCreateSymbol("external_unknown");
-  const MCExpr *SymRef = MCSymbolRefExpr::create(Sym, Ctx);
-
-  // Set up the rest of the expression
-  const MCExpr *Masked = MCBinaryExpr::createAnd(
-      SymRef, MCConstantExpr::create(0, Ctx),Ctx);
-  const MCExpr *SignBit = AMDGPUMCExpr::createOr({
-      Masked, MCConstantExpr::create(INT64_MIN, Ctx)}, Ctx);
-  const MCExpr *MaxExpr = AMDGPUMCExpr::createMax({
-      SignBit, MCConstantExpr::create(5, Ctx)}, Ctx);
-  
-  // running evaluateAsAbsolute will fail since external_unknown is undefined.
-  int64_t RuntimeRst;
-  EXPECT_FALSE(MaxExpr->evaluateAsAbsolute(RuntimeRst));
-
-  // fold expression and then running evaluateAsAbsolute should now succeed with the correct rst
-  const MCExpr *Folded = AMDGPU::foldAMDGPUMCExpr(MaxExpr, Ctx);
-  int64_t FoldedVal;
-  ASSERT_TRUE(Folded->evaluateAsAbsolute(FoldedVal));
-  EXPECT_EQ(FoldedVal, int64_t{5});
-}
-
-// min(((external_unknown & 0) | 0x8000000000000000), 5)
-TEST_F(AMDGPUMCExprTest, MinFolddKnownBitsSignedness){
-  MCContext &Ctx = MF->getContext();
-
-  // Set up the unknown/undefined part of the expression
-  MCSymbol *Sym = Ctx.getOrCreateSymbol("external_unknown");
-  const MCExpr *SymRef = MCSymbolRefExpr::create(Sym, Ctx);
-
-  // Set up the rest of the expression
-  const MCExpr *Masked = MCBinaryExpr::createAnd(
-      SymRef, MCConstantExpr::create(0, Ctx),Ctx);
-  const MCExpr *SignBit = AMDGPUMCExpr::createOr({
-      Masked, MCConstantExpr::create(INT64_MIN, Ctx)}, Ctx);
-  const MCExpr *MinExpr = AMDGPUMCExpr::createMin({
-      SignBit, MCConstantExpr::create(5, Ctx)}, Ctx);
-
-  // running evaluateAsAbsolute will fail since external_unknown is undefined.
-  int64_t AbsoluteRst;
-  EXPECT_FALSE(MinExpr->evaluateAsAbsolute(AbsoluteRst));
-
-  // fold expression and then running evaluateAsAbsolute should now succeed with the correct rst
-  const MCExpr *Folded = AMDGPU::foldAMDGPUMCExpr(MinExpr, Ctx);
-  int64_t FoldedVal;
-  ASSERT_TRUE(Folded->evaluateAsAbsolute(FoldedVal));
-  EXPECT_EQ(FoldedVal, INT64_MIN);
+//===- llvm/unittests/MC/AMDGPU/AMDGPUMCExprTest.cpp
+//---------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "MCTargetDesc/AMDGPUMCExpr.h"
+#include "AMDGPUTargetMachine.h"
+#include "AMDGPUUnitTests.h"
+#include "GCNSubtarget.h"
+#include "SIProgramInfo.h"
+#include "Utils/AMDGPUPALMetadata.h"
+#include "llvm/CodeGen/MachineModuleInfo.h"
+#include "llvm/MC/MCContext.h"
+#include "llvm/MC/MCExpr.h"
+#include "llvm/MC/MCStreamer.h"
+#include "llvm/MC/MCSymbol.h"
+#include "llvm/MC/MCTargetOptions.h"
+#include "llvm/MC/TargetRegistry.h"
+#include "llvm/Target/TargetMachine.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+
+class AMDGPUMCExprTest : public AMDGPUTestBase {
+
+protected:
+  std::unique_ptr<GCNTargetMachine> TM;
+  std::unique_ptr<LLVMContext> LLVMCtx;
+  std::unique_ptr<GCNSubtarget> ST;
+  std::unique_ptr<MachineModuleInfo> MMI;
+  std::unique_ptr<MachineFunction> MF;
+  std::unique_ptr<Module> M;
+  AMDGPUPALMetadata MD;
+
+  AMDGPUMCExprTest() {
+
+    TM = createAMDGPUTargetMachine("amdgcn--amdpal", "gfx1010", "");
+
+    LLVMCtx = std::make_unique<LLVMContext>();
+    M = std::make_unique<Module>("Module", *LLVMCtx);
+    M->setDataLayout(TM->createDataLayout());
+    auto *FType = FunctionType::get(Type::getVoidTy(*LLVMCtx), false);
+    auto *F = Function::Create(FType, GlobalValue::ExternalLinkage, "Test", *M);
+    MMI = std::make_unique<MachineModuleInfo>(TM.get());
+
+    ST = std::make_unique<GCNSubtarget>(TM->getTargetTriple(),
+                                        TM->getTargetCPU(),
+                                        TM->getTargetFeatureString(), *TM);
+
+    MF = std::make_unique<MachineFunction>(*F, *TM, *ST, MMI->getContext(), 1);
+  }
+};
+// Next two tests showcases the folding of foldAMDGPUMCExpr function that uses
+// KnownBits to simplify expressions as much as possible
+//  max(((external_unknown & 0) | 0x8000000000000000), 5)
+TEST_F(AMDGPUMCExprTest, MaxFoldKnownBitsSignedness) {
+  MCContext &Ctx = MF->getContext();
+
+  // Set up the unknown/undefined part of the expression
+  MCSymbol *Sym = Ctx.getOrCreateSymbol("external_unknown");
+  const MCExpr *SymRef = MCSymbolRefExpr::create(Sym, Ctx);
+
+  // Set up the rest of the expression
+  const MCExpr *Masked =
+      MCBinaryExpr::createAnd(SymRef, MCConstantExpr::create(0, Ctx), Ctx);
+  const MCExpr *SignBit = AMDGPUMCExpr::createOr(
+      {Masked, MCConstantExpr::create(INT64_MIN, Ctx)}, Ctx);
+  const MCExpr *MaxExpr =
+      AMDGPUMCExpr::createMax({SignBit, MCConstantExpr::create(5, Ctx)}, Ctx);
+
+  // running evaluateAsAbsolute will fail since external_unknown is undefined.
+  int64_t RuntimeRst;
+  EXPECT_FALSE(MaxExpr->evaluateAsAbsolute(RuntimeRst));
+
+  // fold expression and then running evaluateAsAbsolute should now succeed with
+  // the correct result
+  const MCExpr *Folded = AMDGPU::foldAMDGPUMCExpr(MaxExpr, Ctx);
+  int64_t FoldedVal;
+  ASSERT_TRUE(Folded->evaluateAsAbsolute(FoldedVal));
+  EXPECT_EQ(FoldedVal, int64_t{5});
+}
+
+// min(((external_unknown & 0) | 0x8000000000000000), 5)
+TEST_F(AMDGPUMCExprTest, MinFolddKnownBitsSignedness) {
+  MCContext &Ctx = MF->getContext();
+
+  // Set up the unknown/undefined part of the expression
+  MCSymbol *Sym = Ctx.getOrCreateSymbol("external_unknown");
+  const MCExpr *SymRef = MCSymbolRefExpr::create(Sym, Ctx);
+
+  // Set up the rest of the expression
+  const MCExpr *Masked =
+      MCBinaryExpr::createAnd(SymRef, MCConstantExpr::create(0, Ctx), Ctx);
+  const MCExpr *SignBit = AMDGPUMCExpr::createOr(
+      {Masked, MCConstantExpr::create(INT64_MIN, Ctx)}, Ctx);
+  const MCExpr *MinExpr =
+      AMDGPUMCExpr::createMin({SignBit, MCConstantExpr::create(5, Ctx)}, Ctx);
+
+  // running evaluateAsAbsolute will fail since external_unknown is undefined.
+  int64_t AbsoluteRst;
+  EXPECT_FALSE(MinExpr->evaluateAsAbsolute(AbsoluteRst));
+
+  // fold expression and then running evaluateAsAbsolute should now succeed with
+  // the correct result
+  const MCExpr *Folded = AMDGPU::foldAMDGPUMCExpr(MinExpr, Ctx);
+  int64_t FoldedVal;
+  ASSERT_TRUE(Folded->evaluateAsAbsolute(FoldedVal));
+  EXPECT_EQ(FoldedVal, INT64_MIN);
 }
\ No newline at end of file

>From 1b0d6ee43128ef357537f9ce14150a50425cc76a Mon Sep 17 00:00:00 2001
From: JoshuaGrindstaff <jgrindst at amd.com>
Date: Tue, 2 Jun 2026 12:35:15 -0500
Subject: [PATCH 07/13] Fixes based on feedback Removed unneccessary
 includes/variables Fixed typo

---
 llvm/unittests/Target/AMDGPU/AMDGPUMCExprTest.cpp | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/llvm/unittests/Target/AMDGPU/AMDGPUMCExprTest.cpp b/llvm/unittests/Target/AMDGPU/AMDGPUMCExprTest.cpp
index 7727011032333..86c296feed792 100644
--- a/llvm/unittests/Target/AMDGPU/AMDGPUMCExprTest.cpp
+++ b/llvm/unittests/Target/AMDGPU/AMDGPUMCExprTest.cpp
@@ -11,16 +11,10 @@
 #include "AMDGPUTargetMachine.h"
 #include "AMDGPUUnitTests.h"
 #include "GCNSubtarget.h"
-#include "SIProgramInfo.h"
-#include "Utils/AMDGPUPALMetadata.h"
 #include "llvm/CodeGen/MachineModuleInfo.h"
 #include "llvm/MC/MCContext.h"
 #include "llvm/MC/MCExpr.h"
-#include "llvm/MC/MCStreamer.h"
 #include "llvm/MC/MCSymbol.h"
-#include "llvm/MC/MCTargetOptions.h"
-#include "llvm/MC/TargetRegistry.h"
-#include "llvm/Target/TargetMachine.h"
 #include "gtest/gtest.h"
 
 using namespace llvm;
@@ -34,7 +28,6 @@ class AMDGPUMCExprTest : public AMDGPUTestBase {
   std::unique_ptr<MachineModuleInfo> MMI;
   std::unique_ptr<MachineFunction> MF;
   std::unique_ptr<Module> M;
-  AMDGPUPALMetadata MD;
 
   AMDGPUMCExprTest() {
 
@@ -85,7 +78,7 @@ TEST_F(AMDGPUMCExprTest, MaxFoldKnownBitsSignedness) {
 }
 
 // min(((external_unknown & 0) | 0x8000000000000000), 5)
-TEST_F(AMDGPUMCExprTest, MinFolddKnownBitsSignedness) {
+TEST_F(AMDGPUMCExprTest, MinFoldKnownBitsSignedness) {
   MCContext &Ctx = MF->getContext();
 
   // Set up the unknown/undefined part of the expression

>From 4223c6038dca313d84939369fff431891fdf1a9b Mon Sep 17 00:00:00 2001
From: JoshuaGrindstaff <jgrindst at amd.com>
Date: Tue, 2 Jun 2026 14:02:16 -0500
Subject: [PATCH 08/13] fix formating

---
 .../Target/AMDGPU/AMDGPUMCResourceInfo.cpp    | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.cpp b/llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.cpp
index c529219692e9c..2291b44517730 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.cpp
@@ -13,6 +13,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "AMDGPUMCResourceInfo.h"
+#include "GCNSubtarget.h"
 #include "SIMachineFunctionInfo.h"
 #include "Utils/AMDGPUBaseInfo.h"
 #include "llvm/ADT/StringRef.h"
@@ -20,7 +21,6 @@
 #include "llvm/MC/MCContext.h"
 #include "llvm/MC/MCSymbol.h"
 #include "llvm/Target/TargetMachine.h"
-#include "GCNSubtarget.h"
 
 #define DEBUG_TYPE "amdgpu-mc-resource-usage"
 
@@ -310,7 +310,8 @@ void MCResourceInfo::gatherResourceInfo(
   });
 
   const GCNSubtarget &ST = MF.getSubtarget<GCNSubtarget>();
-  auto [MaxAllowedVGPRs, MaxAllowedAGPRs] = ST.getMaxNumVectorRegs(MF.getFunction());
+  auto [MaxAllowedVGPRs, MaxAllowedAGPRs] =
+      ST.getMaxNumVectorRegs(MF.getFunction());
   auto SetMaxReg = [&](MCSymbol *MaxSym, int32_t numRegs,
                        ResourceInfoKind RIK) {
     if (!FRI.HasIndirectCall) {
@@ -321,17 +322,19 @@ void MCResourceInfo::gatherResourceInfo(
       MCSymbol *LocalNumSym = getSymbol(FnSym->getName(), RIK, OutContext);
       const MCExpr *RegExpr = AMDGPUMCExpr::createMax(
           {MCConstantExpr::create(numRegs, OutContext), SymRef}, OutContext);
-      if(RIK == RIK_NumVGPR) {
+      if (RIK == RIK_NumVGPR) {
         RegExpr = AMDGPUMCExpr::createMin(
-          {MCConstantExpr::create(MaxAllowedVGPRs, OutContext),RegExpr},OutContext);
-      }
-      else if (RIK == RIK_NumAGPR) {
+            {MCConstantExpr::create(MaxAllowedVGPRs, OutContext), RegExpr},
+            OutContext);
+      } else if (RIK == RIK_NumAGPR) {
         RegExpr = AMDGPUMCExpr::createMin(
-          {MCConstantExpr::create(MaxAllowedAGPRs, OutContext),RegExpr},OutContext);
+            {MCConstantExpr::create(MaxAllowedAGPRs, OutContext), RegExpr},
+            OutContext);
       }
       LocalNumSym->setVariableValue(RegExpr);
       LLVM_DEBUG(dbgs() << "MCResUse:   " << LocalNumSym->getName()
-                        << ": Indirect callee within, using minimum of module maximum and function maximum\n");
+                        << ": Indirect callee within, using minimum of module "
+                           "maximum and function maximum\n");
     }
   };
 

>From e23815c8ece0060581ff6fa0692cb76f35ff7ef4 Mon Sep 17 00:00:00 2001
From: JoshuaGrindstaff <jgrindst at amd.com>
Date: Wed, 3 Jun 2026 15:16:55 -0500
Subject: [PATCH 09/13] Adding test for new indirect call behavior

---
 .../CodeGen/AMDGPU/indirect-call-vgpr-cap.ll  | 251 ++++++++++++++++++
 1 file changed, 251 insertions(+)
 create mode 100644 llvm/test/CodeGen/AMDGPU/indirect-call-vgpr-cap.ll

diff --git a/llvm/test/CodeGen/AMDGPU/indirect-call-vgpr-cap.ll b/llvm/test/CodeGen/AMDGPU/indirect-call-vgpr-cap.ll
new file mode 100644
index 0000000000000..21ee32777cf06
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/indirect-call-vgpr-cap.ll
@@ -0,0 +1,251 @@
+; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx942 < %s | FileCheck %s --check-prefixes=CHECK
+
+declare void @extern_fn() #0          ; forces HasIndirectCall path
+define void @big_vgpr_user() #1 {
+  %v0 = call i32 asm sideeffect "; def $0", "=v"()
+  %v1 = call i32 asm sideeffect "; def $0", "=v"()
+  %v2 = call i32 asm sideeffect "; def $0", "=v"()
+  %v3 = call i32 asm sideeffect "; def $0", "=v"()
+  %v4 = call i32 asm sideeffect "; def $0", "=v"()
+  %v5 = call i32 asm sideeffect "; def $0", "=v"()
+  %v6 = call i32 asm sideeffect "; def $0", "=v"()
+  %v7 = call i32 asm sideeffect "; def $0", "=v"()
+  %v8 = call i32 asm sideeffect "; def $0", "=v"()
+  %v9 = call i32 asm sideeffect "; def $0", "=v"()
+  %v10 = call i32 asm sideeffect "; def $0", "=v"()
+  %v11 = call i32 asm sideeffect "; def $0", "=v"()
+  %v12 = call i32 asm sideeffect "; def $0", "=v"()
+  %v13 = call i32 asm sideeffect "; def $0", "=v"()
+  %v14 = call i32 asm sideeffect "; def $0", "=v"()
+  %v15 = call i32 asm sideeffect "; def $0", "=v"()
+  %v16 = call i32 asm sideeffect "; def $0", "=v"()
+  %v17 = call i32 asm sideeffect "; def $0", "=v"()
+  %v18 = call i32 asm sideeffect "; def $0", "=v"()
+  %v19 = call i32 asm sideeffect "; def $0", "=v"()
+  %v20 = call i32 asm sideeffect "; def $0", "=v"()
+  %v21 = call i32 asm sideeffect "; def $0", "=v"()
+  %v22 = call i32 asm sideeffect "; def $0", "=v"()
+  %v23 = call i32 asm sideeffect "; def $0", "=v"()
+  %v24 = call i32 asm sideeffect "; def $0", "=v"()
+  %v25 = call i32 asm sideeffect "; def $0", "=v"()
+  %v26 = call i32 asm sideeffect "; def $0", "=v"()
+  %v27 = call i32 asm sideeffect "; def $0", "=v"()
+  %v28 = call i32 asm sideeffect "; def $0", "=v"()
+  %v29 = call i32 asm sideeffect "; def $0", "=v"()
+  %v30 = call i32 asm sideeffect "; def $0", "=v"()
+  %v31 = call i32 asm sideeffect "; def $0", "=v"()
+  %v32 = call i32 asm sideeffect "; def $0", "=v"()
+  %v33 = call i32 asm sideeffect "; def $0", "=v"()
+  %v34 = call i32 asm sideeffect "; def $0", "=v"()
+  %v35 = call i32 asm sideeffect "; def $0", "=v"()
+  %v36 = call i32 asm sideeffect "; def $0", "=v"()
+  %v37 = call i32 asm sideeffect "; def $0", "=v"()
+  %v38 = call i32 asm sideeffect "; def $0", "=v"()
+  %v39 = call i32 asm sideeffect "; def $0", "=v"()
+  %v40 = call i32 asm sideeffect "; def $0", "=v"()
+  %v41 = call i32 asm sideeffect "; def $0", "=v"()
+  %v42 = call i32 asm sideeffect "; def $0", "=v"()
+  %v43 = call i32 asm sideeffect "; def $0", "=v"()
+  %v44 = call i32 asm sideeffect "; def $0", "=v"()
+  %v45 = call i32 asm sideeffect "; def $0", "=v"()
+  %v46 = call i32 asm sideeffect "; def $0", "=v"()
+  %v47 = call i32 asm sideeffect "; def $0", "=v"()
+  %v48 = call i32 asm sideeffect "; def $0", "=v"()
+  %v49 = call i32 asm sideeffect "; def $0", "=v"()
+  %v50 = call i32 asm sideeffect "; def $0", "=v"()
+  %v51 = call i32 asm sideeffect "; def $0", "=v"()
+  %v52 = call i32 asm sideeffect "; def $0", "=v"()
+  %v53 = call i32 asm sideeffect "; def $0", "=v"()
+  %v54 = call i32 asm sideeffect "; def $0", "=v"()
+  %v55 = call i32 asm sideeffect "; def $0", "=v"()
+  %v56 = call i32 asm sideeffect "; def $0", "=v"()
+  %v57 = call i32 asm sideeffect "; def $0", "=v"()
+  %v58 = call i32 asm sideeffect "; def $0", "=v"()
+  %v59 = call i32 asm sideeffect "; def $0", "=v"()
+  %v60 = call i32 asm sideeffect "; def $0", "=v"()
+  %v61 = call i32 asm sideeffect "; def $0", "=v"()
+  %v62 = call i32 asm sideeffect "; def $0", "=v"()
+  %v63 = call i32 asm sideeffect "; def $0", "=v"()
+  %v64 = call i32 asm sideeffect "; def $0", "=v"()
+  %v65 = call i32 asm sideeffect "; def $0", "=v"()
+  %v66 = call i32 asm sideeffect "; def $0", "=v"()
+  %v67 = call i32 asm sideeffect "; def $0", "=v"()
+  %v68 = call i32 asm sideeffect "; def $0", "=v"()
+  %v69 = call i32 asm sideeffect "; def $0", "=v"()
+  %v70 = call i32 asm sideeffect "; def $0", "=v"()
+  %v71 = call i32 asm sideeffect "; def $0", "=v"()
+  %v72 = call i32 asm sideeffect "; def $0", "=v"()
+  %v73 = call i32 asm sideeffect "; def $0", "=v"()
+  %v74 = call i32 asm sideeffect "; def $0", "=v"()
+  %v75 = call i32 asm sideeffect "; def $0", "=v"()
+  %v76 = call i32 asm sideeffect "; def $0", "=v"()
+  %v77 = call i32 asm sideeffect "; def $0", "=v"()
+  %v78 = call i32 asm sideeffect "; def $0", "=v"()
+  %v79 = call i32 asm sideeffect "; def $0", "=v"()
+  %v80 = call i32 asm sideeffect "; def $0", "=v"()
+  %v81 = call i32 asm sideeffect "; def $0", "=v"()
+  %v82 = call i32 asm sideeffect "; def $0", "=v"()
+  %v83 = call i32 asm sideeffect "; def $0", "=v"()
+  %v84 = call i32 asm sideeffect "; def $0", "=v"()
+  %v85 = call i32 asm sideeffect "; def $0", "=v"()
+  %v86 = call i32 asm sideeffect "; def $0", "=v"()
+  %v87 = call i32 asm sideeffect "; def $0", "=v"()
+  %v88 = call i32 asm sideeffect "; def $0", "=v"()
+  %v89 = call i32 asm sideeffect "; def $0", "=v"()
+  %v90 = call i32 asm sideeffect "; def $0", "=v"()
+  %v91 = call i32 asm sideeffect "; def $0", "=v"()
+  %v92 = call i32 asm sideeffect "; def $0", "=v"()
+  %v93 = call i32 asm sideeffect "; def $0", "=v"()
+  %v94 = call i32 asm sideeffect "; def $0", "=v"()
+  %v95 = call i32 asm sideeffect "; def $0", "=v"()
+  %v96 = call i32 asm sideeffect "; def $0", "=v"()
+  %v97 = call i32 asm sideeffect "; def $0", "=v"()
+  %v98 = call i32 asm sideeffect "; def $0", "=v"()
+  %v99 = call i32 asm sideeffect "; def $0", "=v"()
+  %v100 = call i32 asm sideeffect "; def $0", "=v"()
+  call void asm sideeffect "; use $0", "v"(i32 %v0)
+  call void asm sideeffect "; use $0", "v"(i32 %v1)
+  call void asm sideeffect "; use $0", "v"(i32 %v2)
+  call void asm sideeffect "; use $0", "v"(i32 %v3)
+  call void asm sideeffect "; use $0", "v"(i32 %v4)
+  call void asm sideeffect "; use $0", "v"(i32 %v5)
+  call void asm sideeffect "; use $0", "v"(i32 %v6)
+  call void asm sideeffect "; use $0", "v"(i32 %v7)
+  call void asm sideeffect "; use $0", "v"(i32 %v8)
+  call void asm sideeffect "; use $0", "v"(i32 %v9)
+  call void asm sideeffect "; use $0", "v"(i32 %v10)
+  call void asm sideeffect "; use $0", "v"(i32 %v11)
+  call void asm sideeffect "; use $0", "v"(i32 %v12)
+  call void asm sideeffect "; use $0", "v"(i32 %v13)
+  call void asm sideeffect "; use $0", "v"(i32 %v14)
+  call void asm sideeffect "; use $0", "v"(i32 %v15)
+  call void asm sideeffect "; use $0", "v"(i32 %v16)
+  call void asm sideeffect "; use $0", "v"(i32 %v17)
+  call void asm sideeffect "; use $0", "v"(i32 %v18)
+  call void asm sideeffect "; use $0", "v"(i32 %v19)
+  call void asm sideeffect "; use $0", "v"(i32 %v20)
+  call void asm sideeffect "; use $0", "v"(i32 %v21)
+  call void asm sideeffect "; use $0", "v"(i32 %v22)
+  call void asm sideeffect "; use $0", "v"(i32 %v23)
+  call void asm sideeffect "; use $0", "v"(i32 %v24)
+  call void asm sideeffect "; use $0", "v"(i32 %v25)
+  call void asm sideeffect "; use $0", "v"(i32 %v26)
+  call void asm sideeffect "; use $0", "v"(i32 %v27)
+  call void asm sideeffect "; use $0", "v"(i32 %v28)
+  call void asm sideeffect "; use $0", "v"(i32 %v29)
+  call void asm sideeffect "; use $0", "v"(i32 %v30)
+  call void asm sideeffect "; use $0", "v"(i32 %v31)
+  call void asm sideeffect "; use $0", "v"(i32 %v32)
+  call void asm sideeffect "; use $0", "v"(i32 %v33)
+  call void asm sideeffect "; use $0", "v"(i32 %v34)
+  call void asm sideeffect "; use $0", "v"(i32 %v35)
+  call void asm sideeffect "; use $0", "v"(i32 %v36)
+  call void asm sideeffect "; use $0", "v"(i32 %v37)
+  call void asm sideeffect "; use $0", "v"(i32 %v38)
+  call void asm sideeffect "; use $0", "v"(i32 %v39)
+  call void asm sideeffect "; use $0", "v"(i32 %v40)
+  call void asm sideeffect "; use $0", "v"(i32 %v41)
+  call void asm sideeffect "; use $0", "v"(i32 %v42)
+  call void asm sideeffect "; use $0", "v"(i32 %v43)
+  call void asm sideeffect "; use $0", "v"(i32 %v44)
+  call void asm sideeffect "; use $0", "v"(i32 %v45)
+  call void asm sideeffect "; use $0", "v"(i32 %v46)
+  call void asm sideeffect "; use $0", "v"(i32 %v47)
+  call void asm sideeffect "; use $0", "v"(i32 %v48)
+  call void asm sideeffect "; use $0", "v"(i32 %v49)
+  call void asm sideeffect "; use $0", "v"(i32 %v50)
+  call void asm sideeffect "; use $0", "v"(i32 %v51)
+  call void asm sideeffect "; use $0", "v"(i32 %v52)
+  call void asm sideeffect "; use $0", "v"(i32 %v53)
+  call void asm sideeffect "; use $0", "v"(i32 %v54)
+  call void asm sideeffect "; use $0", "v"(i32 %v55)
+  call void asm sideeffect "; use $0", "v"(i32 %v56)
+  call void asm sideeffect "; use $0", "v"(i32 %v57)
+  call void asm sideeffect "; use $0", "v"(i32 %v58)
+  call void asm sideeffect "; use $0", "v"(i32 %v59)
+  call void asm sideeffect "; use $0", "v"(i32 %v60)
+  call void asm sideeffect "; use $0", "v"(i32 %v61)
+  call void asm sideeffect "; use $0", "v"(i32 %v62)
+  call void asm sideeffect "; use $0", "v"(i32 %v63)
+  call void asm sideeffect "; use $0", "v"(i32 %v64)
+  call void asm sideeffect "; use $0", "v"(i32 %v65)
+  call void asm sideeffect "; use $0", "v"(i32 %v66)
+  call void asm sideeffect "; use $0", "v"(i32 %v67)
+  call void asm sideeffect "; use $0", "v"(i32 %v68)
+  call void asm sideeffect "; use $0", "v"(i32 %v69)
+  call void asm sideeffect "; use $0", "v"(i32 %v70)
+  call void asm sideeffect "; use $0", "v"(i32 %v71)
+  call void asm sideeffect "; use $0", "v"(i32 %v72)
+  call void asm sideeffect "; use $0", "v"(i32 %v73)
+  call void asm sideeffect "; use $0", "v"(i32 %v74)
+  call void asm sideeffect "; use $0", "v"(i32 %v75)
+  call void asm sideeffect "; use $0", "v"(i32 %v76)
+  call void asm sideeffect "; use $0", "v"(i32 %v77)
+  call void asm sideeffect "; use $0", "v"(i32 %v78)
+  call void asm sideeffect "; use $0", "v"(i32 %v79)
+  call void asm sideeffect "; use $0", "v"(i32 %v80)
+  call void asm sideeffect "; use $0", "v"(i32 %v81)
+  call void asm sideeffect "; use $0", "v"(i32 %v82)
+  call void asm sideeffect "; use $0", "v"(i32 %v83)
+  call void asm sideeffect "; use $0", "v"(i32 %v84)
+  call void asm sideeffect "; use $0", "v"(i32 %v85)
+  call void asm sideeffect "; use $0", "v"(i32 %v86)
+  call void asm sideeffect "; use $0", "v"(i32 %v87)
+  call void asm sideeffect "; use $0", "v"(i32 %v88)
+  call void asm sideeffect "; use $0", "v"(i32 %v89)
+  call void asm sideeffect "; use $0", "v"(i32 %v90)
+  call void asm sideeffect "; use $0", "v"(i32 %v91)
+  call void asm sideeffect "; use $0", "v"(i32 %v92)
+  call void asm sideeffect "; use $0", "v"(i32 %v93)
+  call void asm sideeffect "; use $0", "v"(i32 %v94)
+  call void asm sideeffect "; use $0", "v"(i32 %v95)
+  call void asm sideeffect "; use $0", "v"(i32 %v96)
+  call void asm sideeffect "; use $0", "v"(i32 %v97)
+  call void asm sideeffect "; use $0", "v"(i32 %v98)
+  call void asm sideeffect "; use $0", "v"(i32 %v99)
+  call void asm sideeffect "; use $0", "v"(i32 %v100)
+  ret void
+}
+define internal void @small_callee() {
+    ret void
+}
+
+define amdgpu_kernel void @kernel_indirect_attributed() #0 {
+    
+    call void @extern_fn()
+    ret void
+}
+
+; CHECK: .set .Lkernel_indirect_attributed.num_vgpr, min(64, max(32, amdgpu.max_num_vgpr))
+; CHECK: .set .Lkernel_indirect_attributed.num_agpr, min(64, max(0, amdgpu.max_num_agpr))
+
+define amdgpu_kernel void @kernel_indirect_unattributed() { 
+    call void @extern_fn()
+    ret void
+}
+
+; CHECK: .set .Lkernel_indirect_unattributed.num_vgpr, min(64, max(32, amdgpu.max_num_vgpr))
+; CHECK: .set .Lkernel_indirect_unattributed.num_agpr, min(64, max(0, amdgpu.max_num_agpr))
+
+define amdgpu_kernel void @kernel_direct_only() {
+    call void @small_callee()
+    ret void
+}
+
+; CHECK: .set .Lkernel_direct_only.num_vgpr, max({{[0-9]+}}, .Lsmall_callee.num_vgpr)
+
+
+attributes #0 = { "amdgpu-flat-work-group-size"="1,1024" }
+attributes #1 = {nounwind noinline norecurse "amdgpu-agpr-alloc"="0"}
+
+; CHECK: .set amdgpu.max_num_vgpr, {{[0-9]+}}
+
+; CHECK-LABEL: .symbol: kernel_indirect_attributed.kd
+; CHECK: .vgpr_count: 64
+
+; CHECK-LABEL:  .symbol: kernel_indirect_unattributed.kd
+; CHECK: .vgpr_count: 64
+
+; CHECK-LABEL: .symbol: kernel_direct_only.kd
+; CHECK: .vgpr_count: 32
+

>From 937971fe96463ad2a487f9eb3d9d080143815d30 Mon Sep 17 00:00:00 2001
From: JoshuaGrindstaff <jgrindst at amd.com>
Date: Wed, 3 Jun 2026 17:54:56 -0500
Subject: [PATCH 10/13] Modified dynamic vgpr count propagation tests

---
 ...gpr-vgpr-count-propagation-direct-chain.ll | 20 +++++++++----------
 .../dvgpr-vgpr-count-propagation-indirect.ll  |  6 +++---
 .../AMDGPU/dvgpr-vgpr-count-propagation.ll    | 16 +++++++--------
 3 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/llvm/test/CodeGen/AMDGPU/dvgpr-vgpr-count-propagation-direct-chain.ll b/llvm/test/CodeGen/AMDGPU/dvgpr-vgpr-count-propagation-direct-chain.ll
index 7b01eec2698c3..5583ccf4085fb 100644
--- a/llvm/test/CodeGen/AMDGPU/dvgpr-vgpr-count-propagation-direct-chain.ll
+++ b/llvm/test/CodeGen/AMDGPU/dvgpr-vgpr-count-propagation-direct-chain.ll
@@ -14,22 +14,22 @@
 ; DVGPR:  .set .Lamdgpu_cs_main.num_vgpr, max(42, .Lgfx_func_a.num_vgpr)
 ; DVGPR:  .set .Lfunc.0.num_vgpr, max(11, .Lgfx_func_a.num_vgpr)
 ; DVGPR:  .set .Lfunc.1.num_vgpr, 82
-; DVGPR:  .set .Lfunc.2.num_vgpr, max(11, amdgpu.max_num_vgpr)
+; DVGPR:  .set .Lfunc.2.num_vgpr, min(192, max(11, amdgpu.max_num_vgpr))
 ; DVGPR:  .set .Lfunc.3.num_vgpr, 11
-; DVGPR:  .set .Lfunc.4.num_vgpr, max(82, amdgpu.max_num_vgpr)
+; DVGPR:  .set .Lfunc.4.num_vgpr, min(192, max(82, amdgpu.max_num_vgpr))
 ; DVGPR:  .set .Lretry_vgpr_alloc.num_vgpr, 11
 ; DVGPR:  .set .Lfirst_retry_wrapper.num_vgpr, 11
 ; DVGPR:  .set amdgpu.max_num_vgpr, 82
 
 ; NODVGPR:  .set .Lgfx_func_a.num_vgpr, 40
-; NODVGPR:  .set .Lamdgpu_cs_main.num_vgpr, max(42, amdgpu.max_num_vgpr)
-; NODVGPR:  .set .Lfunc.0.num_vgpr, max(11, amdgpu.max_num_vgpr)
-; NODVGPR:  .set .Lfunc.1.num_vgpr, max(82, amdgpu.max_num_vgpr)
-; NODVGPR:  .set .Lfunc.2.num_vgpr, max(11, amdgpu.max_num_vgpr)
-; NODVGPR:  .set .Lfunc.3.num_vgpr, max(11, amdgpu.max_num_vgpr)
-; NODVGPR:  .set .Lfunc.4.num_vgpr, max(82, amdgpu.max_num_vgpr)
-; NODVGPR:  .set .Lretry_vgpr_alloc.num_vgpr, max(11, amdgpu.max_num_vgpr)
-; NODVGPR:  .set .Lfirst_retry_wrapper.num_vgpr, max(11, amdgpu.max_num_vgpr)
+; NODVGPR:  .set .Lamdgpu_cs_main.num_vgpr, min(192, max(42, amdgpu.max_num_vgpr))
+; NODVGPR:  .set .Lfunc.0.num_vgpr, min(192, max(11, amdgpu.max_num_vgpr))
+; NODVGPR:  .set .Lfunc.1.num_vgpr, min(192, max(82, amdgpu.max_num_vgpr))
+; NODVGPR:  .set .Lfunc.2.num_vgpr, min(192, max(11, amdgpu.max_num_vgpr))
+; NODVGPR:  .set .Lfunc.3.num_vgpr, min(192, max(11, amdgpu.max_num_vgpr))
+; NODVGPR:  .set .Lfunc.4.num_vgpr, min(192, max(82, amdgpu.max_num_vgpr))
+; NODVGPR:  .set .Lretry_vgpr_alloc.num_vgpr, min(192, max(11, amdgpu.max_num_vgpr))
+; NODVGPR:  .set .Lfirst_retry_wrapper.num_vgpr, min(192, max(11, amdgpu.max_num_vgpr))
 ; NODVGPR:  .set amdgpu.max_num_vgpr, 82
 
 ; DVGPR:  - .hardware_stages:
diff --git a/llvm/test/CodeGen/AMDGPU/dvgpr-vgpr-count-propagation-indirect.ll b/llvm/test/CodeGen/AMDGPU/dvgpr-vgpr-count-propagation-indirect.ll
index f9cf887ac668b..b71dcc956d90f 100644
--- a/llvm/test/CodeGen/AMDGPU/dvgpr-vgpr-count-propagation-indirect.ll
+++ b/llvm/test/CodeGen/AMDGPU/dvgpr-vgpr-count-propagation-indirect.ll
@@ -15,9 +15,9 @@
 
 ; NODVGPR:  .set .Lgfx_func_a.num_vgpr, 40
 ; NODVGPR:  .set .Lgfx_func_b.num_vgpr, 80
-; NODVGPR:  .set .Lfunc_with_indirect_call.num_vgpr, max(11, amdgpu.max_num_vgpr)
-; NODVGPR:  .set .Lfunc_direct_only.num_vgpr, max(11, amdgpu.max_num_vgpr)
-; NODVGPR:  .set .Lfunc_chain_only.num_vgpr, max(11, amdgpu.max_num_vgpr)
+; NODVGPR:  .set .Lfunc_with_indirect_call.num_vgpr, min(192, max(11, amdgpu.max_num_vgpr))
+; NODVGPR:  .set .Lfunc_direct_only.num_vgpr, min(192, max(11, amdgpu.max_num_vgpr))
+; NODVGPR:  .set .Lfunc_chain_only.num_vgpr, min(192, max(11, amdgpu.max_num_vgpr))
 ; NODVGPR:  .set amdgpu.max_num_vgpr, 80
 
 define amdgpu_gfx void @gfx_func_a() #0 {
diff --git a/llvm/test/CodeGen/AMDGPU/dvgpr-vgpr-count-propagation.ll b/llvm/test/CodeGen/AMDGPU/dvgpr-vgpr-count-propagation.ll
index 7001e23f7002d..e8da866d2fa6e 100644
--- a/llvm/test/CodeGen/AMDGPU/dvgpr-vgpr-count-propagation.ll
+++ b/llvm/test/CodeGen/AMDGPU/dvgpr-vgpr-count-propagation.ll
@@ -27,14 +27,14 @@
 ; NODVGPR:  .set .Lgfx_func_a.num_vgpr, 40
 ; NODVGPR:  .set .Lgfx_func_b2.num_vgpr, 80
 ; NODVGPR:  .set .Lgfx_func_b.num_vgpr, max(61, .Lgfx_func_b2.num_vgpr)
-; NODVGPR:  .set .Lamdgpu_cs_main.num_vgpr, max(42, amdgpu.max_num_vgpr)
-; NODVGPR:  .set .Lfunc.0.num_vgpr, max(13, amdgpu.max_num_vgpr)
-; NODVGPR:  .set .Lfunc.1.num_vgpr, max(14, amdgpu.max_num_vgpr)
-; NODVGPR:  .set .Lfunc.2.num_vgpr, max(16, amdgpu.max_num_vgpr)
-; NODVGPR:  .set .Lfunc.3.num_vgpr, max(15, amdgpu.max_num_vgpr)
-; NODVGPR:  .set .Lfunc.4.num_vgpr, max(100, amdgpu.max_num_vgpr)
-; NODVGPR:  .set .Lretry_vgpr_alloc.num_vgpr, max(11, amdgpu.max_num_vgpr)
-; NODVGPR:  .set .Lfirst_retry_wrapper.num_vgpr, max(11, amdgpu.max_num_vgpr)
+; NODVGPR:  .set .Lamdgpu_cs_main.num_vgpr, min(192, max(42, amdgpu.max_num_vgpr))
+; NODVGPR:  .set .Lfunc.0.num_vgpr, min(192, max(13, amdgpu.max_num_vgpr))
+; NODVGPR:  .set .Lfunc.1.num_vgpr, min(192, max(14, amdgpu.max_num_vgpr))
+; NODVGPR:  .set .Lfunc.2.num_vgpr, min(192, max(16, amdgpu.max_num_vgpr))
+; NODVGPR:  .set .Lfunc.3.num_vgpr, min(192, max(15, amdgpu.max_num_vgpr))
+; NODVGPR:  .set .Lfunc.4.num_vgpr, min(192, max(100, amdgpu.max_num_vgpr))
+; NODVGPR:  .set .Lretry_vgpr_alloc.num_vgpr, min(192, max(11, amdgpu.max_num_vgpr))
+; NODVGPR:  .set .Lfirst_retry_wrapper.num_vgpr, min(192, max(11, amdgpu.max_num_vgpr))
 ; NODVGPR:  .set amdgpu.max_num_vgpr, 100
 
 ; DVGPR:  - .hardware_stages:

>From 567f69b37c00e70999d104c6cb8fcf846947f338 Mon Sep 17 00:00:00 2001
From: JoshuaGrindstaff <jgrindst at amd.com>
Date: Wed, 3 Jun 2026 19:44:56 -0500
Subject: [PATCH 11/13] Fixed C++17 structured binding capture error

---
 llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.cpp b/llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.cpp
index 2291b44517730..7191ee93797e1 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.cpp
@@ -310,8 +310,10 @@ void MCResourceInfo::gatherResourceInfo(
   });
 
   const GCNSubtarget &ST = MF.getSubtarget<GCNSubtarget>();
-  auto [MaxAllowedVGPRs, MaxAllowedAGPRs] =
+  std::pair<unsigned, unsigned> MaxNumVectorRegs =
       ST.getMaxNumVectorRegs(MF.getFunction());
+  unsigned MaxAllowedVGPRs = MaxNumVectorRegs.first;
+  unsigned MaxAllowedAGPRs = MaxNumVectorRegs.second;
   auto SetMaxReg = [&](MCSymbol *MaxSym, int32_t numRegs,
                        ResourceInfoKind RIK) {
     if (!FRI.HasIndirectCall) {

>From 523af80fa4237f48fc4c19e9eb166e2b3d6fcbe4 Mon Sep 17 00:00:00 2001
From: JoshuaGrindstaff <jgrindst at amd.com>
Date: Thu, 4 Jun 2026 14:19:10 -0500
Subject: [PATCH 12/13] Increased vgpr usage

---
 .../CodeGen/AMDGPU/indirect-call-vgpr-cap.ll  | 50 +++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/llvm/test/CodeGen/AMDGPU/indirect-call-vgpr-cap.ll b/llvm/test/CodeGen/AMDGPU/indirect-call-vgpr-cap.ll
index 21ee32777cf06..f599ae943cb0f 100644
--- a/llvm/test/CodeGen/AMDGPU/indirect-call-vgpr-cap.ll
+++ b/llvm/test/CodeGen/AMDGPU/indirect-call-vgpr-cap.ll
@@ -103,6 +103,31 @@ define void @big_vgpr_user() #1 {
   %v98 = call i32 asm sideeffect "; def $0", "=v"()
   %v99 = call i32 asm sideeffect "; def $0", "=v"()
   %v100 = call i32 asm sideeffect "; def $0", "=v"()
+  %v101 = call i32 asm sideeffect "; def $0", "=v"()
+  %v102 = call i32 asm sideeffect "; def $0", "=v"()
+  %v103 = call i32 asm sideeffect "; def $0", "=v"()
+  %v104 = call i32 asm sideeffect "; def $0", "=v"()
+  %v105 = call i32 asm sideeffect "; def $0", "=v"()
+  %v106 = call i32 asm sideeffect "; def $0", "=v"()
+  %v107 = call i32 asm sideeffect "; def $0", "=v"()
+  %v108 = call i32 asm sideeffect "; def $0", "=v"()
+  %v109 = call i32 asm sideeffect "; def $0", "=v"()
+  %v110 = call i32 asm sideeffect "; def $0", "=v"()
+  %v111 = call i32 asm sideeffect "; def $0", "=v"()
+  %v112 = call i32 asm sideeffect "; def $0", "=v"()
+  %v113 = call i32 asm sideeffect "; def $0", "=v"()
+  %v114 = call i32 asm sideeffect "; def $0", "=v"()
+  %v115 = call i32 asm sideeffect "; def $0", "=v"()
+  %v116 = call i32 asm sideeffect "; def $0", "=v"()
+  %v117 = call i32 asm sideeffect "; def $0", "=v"()
+  %v118 = call i32 asm sideeffect "; def $0", "=v"()
+  %v119 = call i32 asm sideeffect "; def $0", "=v"()
+  %v120 = call i32 asm sideeffect "; def $0", "=v"()
+  %v121 = call i32 asm sideeffect "; def $0", "=v"()
+  %v122 = call i32 asm sideeffect "; def $0", "=v"()
+  %v123 = call i32 asm sideeffect "; def $0", "=v"()
+  %v124 = call i32 asm sideeffect "; def $0", "=v"()
+  %v125 = call i32 asm sideeffect "; def $0", "=v"()
   call void asm sideeffect "; use $0", "v"(i32 %v0)
   call void asm sideeffect "; use $0", "v"(i32 %v1)
   call void asm sideeffect "; use $0", "v"(i32 %v2)
@@ -204,6 +229,31 @@ define void @big_vgpr_user() #1 {
   call void asm sideeffect "; use $0", "v"(i32 %v98)
   call void asm sideeffect "; use $0", "v"(i32 %v99)
   call void asm sideeffect "; use $0", "v"(i32 %v100)
+  call void asm sideeffect "; use $0", "v"(i32 %v101)
+  call void asm sideeffect "; use $0", "v"(i32 %v102)
+  call void asm sideeffect "; use $0", "v"(i32 %v103)
+  call void asm sideeffect "; use $0", "v"(i32 %v104)
+  call void asm sideeffect "; use $0", "v"(i32 %v105)
+  call void asm sideeffect "; use $0", "v"(i32 %v106)
+  call void asm sideeffect "; use $0", "v"(i32 %v107)
+  call void asm sideeffect "; use $0", "v"(i32 %v108)
+  call void asm sideeffect "; use $0", "v"(i32 %v109)
+  call void asm sideeffect "; use $0", "v"(i32 %v110)
+  call void asm sideeffect "; use $0", "v"(i32 %v111)
+  call void asm sideeffect "; use $0", "v"(i32 %v112)
+  call void asm sideeffect "; use $0", "v"(i32 %v113)
+  call void asm sideeffect "; use $0", "v"(i32 %v114)
+  call void asm sideeffect "; use $0", "v"(i32 %v115)
+  call void asm sideeffect "; use $0", "v"(i32 %v116)
+  call void asm sideeffect "; use $0", "v"(i32 %v117)
+  call void asm sideeffect "; use $0", "v"(i32 %v118)
+  call void asm sideeffect "; use $0", "v"(i32 %v119)
+  call void asm sideeffect "; use $0", "v"(i32 %v120)
+  call void asm sideeffect "; use $0", "v"(i32 %v121)
+  call void asm sideeffect "; use $0", "v"(i32 %v122)
+  call void asm sideeffect "; use $0", "v"(i32 %v123)
+  call void asm sideeffect "; use $0", "v"(i32 %v124)
+  call void asm sideeffect "; use $0", "v"(i32 %v125)
   ret void
 }
 define internal void @small_callee() {

>From ff5b86181d8b6e5d161060c6a6b92d4262ee9c99 Mon Sep 17 00:00:00 2001
From: JoshuaGrindstaff <jgrindst at amd.com>
Date: Thu, 4 Jun 2026 15:52:32 -0500
Subject: [PATCH 13/13] Updated indirect-call-vgpr-cap test and added agpr
 equivalent test

---
 .../CodeGen/AMDGPU/indirect-call-agpr-cap.ll  |  56 ++++
 .../CodeGen/AMDGPU/indirect-call-vgpr-cap.ll  | 258 +-----------------
 2 files changed, 60 insertions(+), 254 deletions(-)
 create mode 100644 llvm/test/CodeGen/AMDGPU/indirect-call-agpr-cap.ll

diff --git a/llvm/test/CodeGen/AMDGPU/indirect-call-agpr-cap.ll b/llvm/test/CodeGen/AMDGPU/indirect-call-agpr-cap.ll
new file mode 100644
index 0000000000000..9be74be509757
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/indirect-call-agpr-cap.ll
@@ -0,0 +1,56 @@
+; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx942 < %s | FileCheck %s --check-prefixes=CHECK
+
+declare void @extern_fn() #0          ; forces HasIndirectCall path
+define void @big_vgpr_user() #1 {
+    call void asm sideeffect "","~{a125}"() #1
+    ret void
+}
+define internal void @small_callee() {
+    ret void
+}
+
+define amdgpu_kernel void @kernel_indirect_attributed() #0 {
+    
+    call void @extern_fn()
+    ret void
+}
+
+; CHECK: .set .Lkernel_indirect_attributed.num_vgpr, min(64, max(32, amdgpu.max_num_vgpr))
+; CHECK: .set .Lkernel_indirect_attributed.num_agpr, min(64, max(0, amdgpu.max_num_agpr))
+
+define amdgpu_kernel void @kernel_indirect_unattributed() { 
+    call void @extern_fn()
+    ret void
+}
+
+; CHECK: .set .Lkernel_indirect_unattributed.num_vgpr, min(64, max(32, amdgpu.max_num_vgpr))
+; CHECK: .set .Lkernel_indirect_unattributed.num_agpr, min(64, max(0, amdgpu.max_num_agpr))
+
+define amdgpu_kernel void @kernel_direct_only() {
+    call void @small_callee()
+    ret void
+}
+
+; CHECK: .set .Lkernel_direct_only.num_vgpr, max({{[0-9]+}}, .Lsmall_callee.num_vgpr)
+
+
+attributes #0 = {"amdgpu-flat-work-group-size"="1,1024"}
+attributes #1 = {nounwind noinline norecurse}
+attributes #2 = {nounwind noinline norecurse}
+
+; CHECK: .set amdgpu.max_num_agpr, 126
+
+
+
+; CHECK: .agpr_count: 64
+; CHECK-LABEL: .symbol: kernel_indirect_attributed.kd
+; CHECK: .vgpr_count: 96
+
+; CHECK: .agpr_count: 64
+; CHECK-LABEL:  .symbol: kernel_indirect_unattributed.kd
+; CHECK: .vgpr_count: 96
+
+; CHECK: .agpr_count: 0
+; CHECK-LABEL: .symbol: kernel_direct_only.kd
+; CHECK: .vgpr_count: 32
+
diff --git a/llvm/test/CodeGen/AMDGPU/indirect-call-vgpr-cap.ll b/llvm/test/CodeGen/AMDGPU/indirect-call-vgpr-cap.ll
index f599ae943cb0f..482e14a94303b 100644
--- a/llvm/test/CodeGen/AMDGPU/indirect-call-vgpr-cap.ll
+++ b/llvm/test/CodeGen/AMDGPU/indirect-call-vgpr-cap.ll
@@ -2,259 +2,8 @@
 
 declare void @extern_fn() #0          ; forces HasIndirectCall path
 define void @big_vgpr_user() #1 {
-  %v0 = call i32 asm sideeffect "; def $0", "=v"()
-  %v1 = call i32 asm sideeffect "; def $0", "=v"()
-  %v2 = call i32 asm sideeffect "; def $0", "=v"()
-  %v3 = call i32 asm sideeffect "; def $0", "=v"()
-  %v4 = call i32 asm sideeffect "; def $0", "=v"()
-  %v5 = call i32 asm sideeffect "; def $0", "=v"()
-  %v6 = call i32 asm sideeffect "; def $0", "=v"()
-  %v7 = call i32 asm sideeffect "; def $0", "=v"()
-  %v8 = call i32 asm sideeffect "; def $0", "=v"()
-  %v9 = call i32 asm sideeffect "; def $0", "=v"()
-  %v10 = call i32 asm sideeffect "; def $0", "=v"()
-  %v11 = call i32 asm sideeffect "; def $0", "=v"()
-  %v12 = call i32 asm sideeffect "; def $0", "=v"()
-  %v13 = call i32 asm sideeffect "; def $0", "=v"()
-  %v14 = call i32 asm sideeffect "; def $0", "=v"()
-  %v15 = call i32 asm sideeffect "; def $0", "=v"()
-  %v16 = call i32 asm sideeffect "; def $0", "=v"()
-  %v17 = call i32 asm sideeffect "; def $0", "=v"()
-  %v18 = call i32 asm sideeffect "; def $0", "=v"()
-  %v19 = call i32 asm sideeffect "; def $0", "=v"()
-  %v20 = call i32 asm sideeffect "; def $0", "=v"()
-  %v21 = call i32 asm sideeffect "; def $0", "=v"()
-  %v22 = call i32 asm sideeffect "; def $0", "=v"()
-  %v23 = call i32 asm sideeffect "; def $0", "=v"()
-  %v24 = call i32 asm sideeffect "; def $0", "=v"()
-  %v25 = call i32 asm sideeffect "; def $0", "=v"()
-  %v26 = call i32 asm sideeffect "; def $0", "=v"()
-  %v27 = call i32 asm sideeffect "; def $0", "=v"()
-  %v28 = call i32 asm sideeffect "; def $0", "=v"()
-  %v29 = call i32 asm sideeffect "; def $0", "=v"()
-  %v30 = call i32 asm sideeffect "; def $0", "=v"()
-  %v31 = call i32 asm sideeffect "; def $0", "=v"()
-  %v32 = call i32 asm sideeffect "; def $0", "=v"()
-  %v33 = call i32 asm sideeffect "; def $0", "=v"()
-  %v34 = call i32 asm sideeffect "; def $0", "=v"()
-  %v35 = call i32 asm sideeffect "; def $0", "=v"()
-  %v36 = call i32 asm sideeffect "; def $0", "=v"()
-  %v37 = call i32 asm sideeffect "; def $0", "=v"()
-  %v38 = call i32 asm sideeffect "; def $0", "=v"()
-  %v39 = call i32 asm sideeffect "; def $0", "=v"()
-  %v40 = call i32 asm sideeffect "; def $0", "=v"()
-  %v41 = call i32 asm sideeffect "; def $0", "=v"()
-  %v42 = call i32 asm sideeffect "; def $0", "=v"()
-  %v43 = call i32 asm sideeffect "; def $0", "=v"()
-  %v44 = call i32 asm sideeffect "; def $0", "=v"()
-  %v45 = call i32 asm sideeffect "; def $0", "=v"()
-  %v46 = call i32 asm sideeffect "; def $0", "=v"()
-  %v47 = call i32 asm sideeffect "; def $0", "=v"()
-  %v48 = call i32 asm sideeffect "; def $0", "=v"()
-  %v49 = call i32 asm sideeffect "; def $0", "=v"()
-  %v50 = call i32 asm sideeffect "; def $0", "=v"()
-  %v51 = call i32 asm sideeffect "; def $0", "=v"()
-  %v52 = call i32 asm sideeffect "; def $0", "=v"()
-  %v53 = call i32 asm sideeffect "; def $0", "=v"()
-  %v54 = call i32 asm sideeffect "; def $0", "=v"()
-  %v55 = call i32 asm sideeffect "; def $0", "=v"()
-  %v56 = call i32 asm sideeffect "; def $0", "=v"()
-  %v57 = call i32 asm sideeffect "; def $0", "=v"()
-  %v58 = call i32 asm sideeffect "; def $0", "=v"()
-  %v59 = call i32 asm sideeffect "; def $0", "=v"()
-  %v60 = call i32 asm sideeffect "; def $0", "=v"()
-  %v61 = call i32 asm sideeffect "; def $0", "=v"()
-  %v62 = call i32 asm sideeffect "; def $0", "=v"()
-  %v63 = call i32 asm sideeffect "; def $0", "=v"()
-  %v64 = call i32 asm sideeffect "; def $0", "=v"()
-  %v65 = call i32 asm sideeffect "; def $0", "=v"()
-  %v66 = call i32 asm sideeffect "; def $0", "=v"()
-  %v67 = call i32 asm sideeffect "; def $0", "=v"()
-  %v68 = call i32 asm sideeffect "; def $0", "=v"()
-  %v69 = call i32 asm sideeffect "; def $0", "=v"()
-  %v70 = call i32 asm sideeffect "; def $0", "=v"()
-  %v71 = call i32 asm sideeffect "; def $0", "=v"()
-  %v72 = call i32 asm sideeffect "; def $0", "=v"()
-  %v73 = call i32 asm sideeffect "; def $0", "=v"()
-  %v74 = call i32 asm sideeffect "; def $0", "=v"()
-  %v75 = call i32 asm sideeffect "; def $0", "=v"()
-  %v76 = call i32 asm sideeffect "; def $0", "=v"()
-  %v77 = call i32 asm sideeffect "; def $0", "=v"()
-  %v78 = call i32 asm sideeffect "; def $0", "=v"()
-  %v79 = call i32 asm sideeffect "; def $0", "=v"()
-  %v80 = call i32 asm sideeffect "; def $0", "=v"()
-  %v81 = call i32 asm sideeffect "; def $0", "=v"()
-  %v82 = call i32 asm sideeffect "; def $0", "=v"()
-  %v83 = call i32 asm sideeffect "; def $0", "=v"()
-  %v84 = call i32 asm sideeffect "; def $0", "=v"()
-  %v85 = call i32 asm sideeffect "; def $0", "=v"()
-  %v86 = call i32 asm sideeffect "; def $0", "=v"()
-  %v87 = call i32 asm sideeffect "; def $0", "=v"()
-  %v88 = call i32 asm sideeffect "; def $0", "=v"()
-  %v89 = call i32 asm sideeffect "; def $0", "=v"()
-  %v90 = call i32 asm sideeffect "; def $0", "=v"()
-  %v91 = call i32 asm sideeffect "; def $0", "=v"()
-  %v92 = call i32 asm sideeffect "; def $0", "=v"()
-  %v93 = call i32 asm sideeffect "; def $0", "=v"()
-  %v94 = call i32 asm sideeffect "; def $0", "=v"()
-  %v95 = call i32 asm sideeffect "; def $0", "=v"()
-  %v96 = call i32 asm sideeffect "; def $0", "=v"()
-  %v97 = call i32 asm sideeffect "; def $0", "=v"()
-  %v98 = call i32 asm sideeffect "; def $0", "=v"()
-  %v99 = call i32 asm sideeffect "; def $0", "=v"()
-  %v100 = call i32 asm sideeffect "; def $0", "=v"()
-  %v101 = call i32 asm sideeffect "; def $0", "=v"()
-  %v102 = call i32 asm sideeffect "; def $0", "=v"()
-  %v103 = call i32 asm sideeffect "; def $0", "=v"()
-  %v104 = call i32 asm sideeffect "; def $0", "=v"()
-  %v105 = call i32 asm sideeffect "; def $0", "=v"()
-  %v106 = call i32 asm sideeffect "; def $0", "=v"()
-  %v107 = call i32 asm sideeffect "; def $0", "=v"()
-  %v108 = call i32 asm sideeffect "; def $0", "=v"()
-  %v109 = call i32 asm sideeffect "; def $0", "=v"()
-  %v110 = call i32 asm sideeffect "; def $0", "=v"()
-  %v111 = call i32 asm sideeffect "; def $0", "=v"()
-  %v112 = call i32 asm sideeffect "; def $0", "=v"()
-  %v113 = call i32 asm sideeffect "; def $0", "=v"()
-  %v114 = call i32 asm sideeffect "; def $0", "=v"()
-  %v115 = call i32 asm sideeffect "; def $0", "=v"()
-  %v116 = call i32 asm sideeffect "; def $0", "=v"()
-  %v117 = call i32 asm sideeffect "; def $0", "=v"()
-  %v118 = call i32 asm sideeffect "; def $0", "=v"()
-  %v119 = call i32 asm sideeffect "; def $0", "=v"()
-  %v120 = call i32 asm sideeffect "; def $0", "=v"()
-  %v121 = call i32 asm sideeffect "; def $0", "=v"()
-  %v122 = call i32 asm sideeffect "; def $0", "=v"()
-  %v123 = call i32 asm sideeffect "; def $0", "=v"()
-  %v124 = call i32 asm sideeffect "; def $0", "=v"()
-  %v125 = call i32 asm sideeffect "; def $0", "=v"()
-  call void asm sideeffect "; use $0", "v"(i32 %v0)
-  call void asm sideeffect "; use $0", "v"(i32 %v1)
-  call void asm sideeffect "; use $0", "v"(i32 %v2)
-  call void asm sideeffect "; use $0", "v"(i32 %v3)
-  call void asm sideeffect "; use $0", "v"(i32 %v4)
-  call void asm sideeffect "; use $0", "v"(i32 %v5)
-  call void asm sideeffect "; use $0", "v"(i32 %v6)
-  call void asm sideeffect "; use $0", "v"(i32 %v7)
-  call void asm sideeffect "; use $0", "v"(i32 %v8)
-  call void asm sideeffect "; use $0", "v"(i32 %v9)
-  call void asm sideeffect "; use $0", "v"(i32 %v10)
-  call void asm sideeffect "; use $0", "v"(i32 %v11)
-  call void asm sideeffect "; use $0", "v"(i32 %v12)
-  call void asm sideeffect "; use $0", "v"(i32 %v13)
-  call void asm sideeffect "; use $0", "v"(i32 %v14)
-  call void asm sideeffect "; use $0", "v"(i32 %v15)
-  call void asm sideeffect "; use $0", "v"(i32 %v16)
-  call void asm sideeffect "; use $0", "v"(i32 %v17)
-  call void asm sideeffect "; use $0", "v"(i32 %v18)
-  call void asm sideeffect "; use $0", "v"(i32 %v19)
-  call void asm sideeffect "; use $0", "v"(i32 %v20)
-  call void asm sideeffect "; use $0", "v"(i32 %v21)
-  call void asm sideeffect "; use $0", "v"(i32 %v22)
-  call void asm sideeffect "; use $0", "v"(i32 %v23)
-  call void asm sideeffect "; use $0", "v"(i32 %v24)
-  call void asm sideeffect "; use $0", "v"(i32 %v25)
-  call void asm sideeffect "; use $0", "v"(i32 %v26)
-  call void asm sideeffect "; use $0", "v"(i32 %v27)
-  call void asm sideeffect "; use $0", "v"(i32 %v28)
-  call void asm sideeffect "; use $0", "v"(i32 %v29)
-  call void asm sideeffect "; use $0", "v"(i32 %v30)
-  call void asm sideeffect "; use $0", "v"(i32 %v31)
-  call void asm sideeffect "; use $0", "v"(i32 %v32)
-  call void asm sideeffect "; use $0", "v"(i32 %v33)
-  call void asm sideeffect "; use $0", "v"(i32 %v34)
-  call void asm sideeffect "; use $0", "v"(i32 %v35)
-  call void asm sideeffect "; use $0", "v"(i32 %v36)
-  call void asm sideeffect "; use $0", "v"(i32 %v37)
-  call void asm sideeffect "; use $0", "v"(i32 %v38)
-  call void asm sideeffect "; use $0", "v"(i32 %v39)
-  call void asm sideeffect "; use $0", "v"(i32 %v40)
-  call void asm sideeffect "; use $0", "v"(i32 %v41)
-  call void asm sideeffect "; use $0", "v"(i32 %v42)
-  call void asm sideeffect "; use $0", "v"(i32 %v43)
-  call void asm sideeffect "; use $0", "v"(i32 %v44)
-  call void asm sideeffect "; use $0", "v"(i32 %v45)
-  call void asm sideeffect "; use $0", "v"(i32 %v46)
-  call void asm sideeffect "; use $0", "v"(i32 %v47)
-  call void asm sideeffect "; use $0", "v"(i32 %v48)
-  call void asm sideeffect "; use $0", "v"(i32 %v49)
-  call void asm sideeffect "; use $0", "v"(i32 %v50)
-  call void asm sideeffect "; use $0", "v"(i32 %v51)
-  call void asm sideeffect "; use $0", "v"(i32 %v52)
-  call void asm sideeffect "; use $0", "v"(i32 %v53)
-  call void asm sideeffect "; use $0", "v"(i32 %v54)
-  call void asm sideeffect "; use $0", "v"(i32 %v55)
-  call void asm sideeffect "; use $0", "v"(i32 %v56)
-  call void asm sideeffect "; use $0", "v"(i32 %v57)
-  call void asm sideeffect "; use $0", "v"(i32 %v58)
-  call void asm sideeffect "; use $0", "v"(i32 %v59)
-  call void asm sideeffect "; use $0", "v"(i32 %v60)
-  call void asm sideeffect "; use $0", "v"(i32 %v61)
-  call void asm sideeffect "; use $0", "v"(i32 %v62)
-  call void asm sideeffect "; use $0", "v"(i32 %v63)
-  call void asm sideeffect "; use $0", "v"(i32 %v64)
-  call void asm sideeffect "; use $0", "v"(i32 %v65)
-  call void asm sideeffect "; use $0", "v"(i32 %v66)
-  call void asm sideeffect "; use $0", "v"(i32 %v67)
-  call void asm sideeffect "; use $0", "v"(i32 %v68)
-  call void asm sideeffect "; use $0", "v"(i32 %v69)
-  call void asm sideeffect "; use $0", "v"(i32 %v70)
-  call void asm sideeffect "; use $0", "v"(i32 %v71)
-  call void asm sideeffect "; use $0", "v"(i32 %v72)
-  call void asm sideeffect "; use $0", "v"(i32 %v73)
-  call void asm sideeffect "; use $0", "v"(i32 %v74)
-  call void asm sideeffect "; use $0", "v"(i32 %v75)
-  call void asm sideeffect "; use $0", "v"(i32 %v76)
-  call void asm sideeffect "; use $0", "v"(i32 %v77)
-  call void asm sideeffect "; use $0", "v"(i32 %v78)
-  call void asm sideeffect "; use $0", "v"(i32 %v79)
-  call void asm sideeffect "; use $0", "v"(i32 %v80)
-  call void asm sideeffect "; use $0", "v"(i32 %v81)
-  call void asm sideeffect "; use $0", "v"(i32 %v82)
-  call void asm sideeffect "; use $0", "v"(i32 %v83)
-  call void asm sideeffect "; use $0", "v"(i32 %v84)
-  call void asm sideeffect "; use $0", "v"(i32 %v85)
-  call void asm sideeffect "; use $0", "v"(i32 %v86)
-  call void asm sideeffect "; use $0", "v"(i32 %v87)
-  call void asm sideeffect "; use $0", "v"(i32 %v88)
-  call void asm sideeffect "; use $0", "v"(i32 %v89)
-  call void asm sideeffect "; use $0", "v"(i32 %v90)
-  call void asm sideeffect "; use $0", "v"(i32 %v91)
-  call void asm sideeffect "; use $0", "v"(i32 %v92)
-  call void asm sideeffect "; use $0", "v"(i32 %v93)
-  call void asm sideeffect "; use $0", "v"(i32 %v94)
-  call void asm sideeffect "; use $0", "v"(i32 %v95)
-  call void asm sideeffect "; use $0", "v"(i32 %v96)
-  call void asm sideeffect "; use $0", "v"(i32 %v97)
-  call void asm sideeffect "; use $0", "v"(i32 %v98)
-  call void asm sideeffect "; use $0", "v"(i32 %v99)
-  call void asm sideeffect "; use $0", "v"(i32 %v100)
-  call void asm sideeffect "; use $0", "v"(i32 %v101)
-  call void asm sideeffect "; use $0", "v"(i32 %v102)
-  call void asm sideeffect "; use $0", "v"(i32 %v103)
-  call void asm sideeffect "; use $0", "v"(i32 %v104)
-  call void asm sideeffect "; use $0", "v"(i32 %v105)
-  call void asm sideeffect "; use $0", "v"(i32 %v106)
-  call void asm sideeffect "; use $0", "v"(i32 %v107)
-  call void asm sideeffect "; use $0", "v"(i32 %v108)
-  call void asm sideeffect "; use $0", "v"(i32 %v109)
-  call void asm sideeffect "; use $0", "v"(i32 %v110)
-  call void asm sideeffect "; use $0", "v"(i32 %v111)
-  call void asm sideeffect "; use $0", "v"(i32 %v112)
-  call void asm sideeffect "; use $0", "v"(i32 %v113)
-  call void asm sideeffect "; use $0", "v"(i32 %v114)
-  call void asm sideeffect "; use $0", "v"(i32 %v115)
-  call void asm sideeffect "; use $0", "v"(i32 %v116)
-  call void asm sideeffect "; use $0", "v"(i32 %v117)
-  call void asm sideeffect "; use $0", "v"(i32 %v118)
-  call void asm sideeffect "; use $0", "v"(i32 %v119)
-  call void asm sideeffect "; use $0", "v"(i32 %v120)
-  call void asm sideeffect "; use $0", "v"(i32 %v121)
-  call void asm sideeffect "; use $0", "v"(i32 %v122)
-  call void asm sideeffect "; use $0", "v"(i32 %v123)
-  call void asm sideeffect "; use $0", "v"(i32 %v124)
-  call void asm sideeffect "; use $0", "v"(i32 %v125)
-  ret void
+    call void asm sideeffect "","~{v125}"() #1
+    ret void
 }
 define internal void @small_callee() {
     ret void
@@ -287,8 +36,9 @@ define amdgpu_kernel void @kernel_direct_only() {
 
 attributes #0 = { "amdgpu-flat-work-group-size"="1,1024" }
 attributes #1 = {nounwind noinline norecurse "amdgpu-agpr-alloc"="0"}
+attributes #2 = {nounwind noinline norecurse}
 
-; CHECK: .set amdgpu.max_num_vgpr, {{[0-9]+}}
+; CHECK: .set amdgpu.max_num_vgpr, 126
 
 ; CHECK-LABEL: .symbol: kernel_indirect_attributed.kd
 ; CHECK: .vgpr_count: 64



More information about the llvm-commits mailing list