[llvm-branch-commits] [llvm] [AMDGPU] Validate generic-target addressable local memory size (PR #223179)

Chinmay Deshpande via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sat Sep 12 14:40:46 PDT 2026


https://github.com/chinmaydd created https://github.com/llvm/llvm-project/pull/223179

Apply the generic numeric at-most comparison to addressable LDS size. A generic target must not advertise more local memory than any GPU it covers.

Keep the backend fallback of 32768 bytes and add integration tests using the real LDS features for valid coverage, over-advertised capacity, and conflicting feature values.

Change-Id: I9fffbe532b8b5bc8875f20f394f29e2e6899f52e

>From 981de5d28bf506ab22fac1e95144e6f8c002f6d8 Mon Sep 17 00:00:00 2001
From: Chinmay Deshpande <chdeshpa at amd.com>
Date: Sat, 12 Sep 2026 17:26:40 -0400
Subject: [PATCH] [AMDGPU] Validate generic-target addressable local memory
 size

Apply the generic numeric at-most comparison to addressable LDS size. A
generic target must not advertise more local memory than any GPU it covers.

Keep the backend fallback of 32768 bytes and add integration tests using
the real LDS features for valid coverage, over-advertised capacity, and
conflicting feature values.

Change-Id: I9fffbe532b8b5bc8875f20f394f29e2e6899f52e
---
 llvm/lib/Target/AMDGPU/AMDGPUFeatures.td      |  8 ++-
 .../AMDGPUTargetDefLocalMemorySize.td         | 51 +++++++++++++++++++
 2 files changed, 57 insertions(+), 2 deletions(-)
 create mode 100644 llvm/test/TableGen/AMDGPUTargetDefLocalMemorySize.td

diff --git a/llvm/lib/Target/AMDGPU/AMDGPUFeatures.td b/llvm/lib/Target/AMDGPU/AMDGPUFeatures.td
index 1d398830f07c6..8fe7d6c57e1ec 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUFeatures.td
+++ b/llvm/lib/Target/AMDGPU/AMDGPUFeatures.td
@@ -31,10 +31,14 @@ def FeatureFlatOffsetBits12 : SubtargetFeatureFlatOffsetBits<12>;
 def FeatureFlatOffsetBits24 : SubtargetFeatureFlatOffsetBits<24>;
 
 // Addressable local memory size is the maximum number of bytes of LDS that can
-// be allocated to a single workgroup.
+// be allocated to a single workgroup. A generic target must not advertise more
+// addressable memory than any of its covered GPUs.
+def AddressableLocalMemorySizeProperty : AMDGPUGenericNumericProperty<
+  "AddressableLocalMemorySize", 32768, AMDGPUGenericAtMost>;
+
 class SubtargetFeatureAddressableLocalMemorySize <int Value> : SubtargetFeature<
   "addressablelocalmemorysize"#Value,
-  "AddressableLocalMemorySize",
+  AddressableLocalMemorySizeProperty.FieldName,
   !cast<string>(Value),
   "The size of local memory in bytes"
 >;
diff --git a/llvm/test/TableGen/AMDGPUTargetDefLocalMemorySize.td b/llvm/test/TableGen/AMDGPUTargetDefLocalMemorySize.td
new file mode 100644
index 0000000000000..1c96c221d5e1b
--- /dev/null
+++ b/llvm/test/TableGen/AMDGPUTargetDefLocalMemorySize.td
@@ -0,0 +1,51 @@
+// RUN: split-file %s %t
+// RUN: llvm-tblgen -gen-amdgpu-target-def -I %t -I %p/../../include -I %p/../../lib/Target/AMDGPU %t/lds-valid.td \
+// RUN:   | FileCheck %t/lds-valid.td
+// RUN: not llvm-tblgen -gen-amdgpu-target-def -I %t -I %p/../../include -I %p/../../lib/Target/AMDGPU %t/lds-conflicting-member.td 2>&1 \
+// RUN:   | FileCheck %t/lds-conflicting-member.td -DFILE=%t/lds-conflicting-member.td --implicit-check-not="error:"
+// RUN: not llvm-tblgen -gen-amdgpu-target-def -I %t -I %p/../../include -I %p/../../lib/Target/AMDGPU %t/lds-invalid.td 2>&1 \
+// RUN:   | FileCheck %t/lds-invalid.td -DFILE=%t/lds-invalid.td --implicit-check-not="error:"
+
+//--- lds-common.td
+include "llvm/Target/Target.td"
+include "AMDGPUFeatures.td"
+def MyTarget : Target;
+
+//--- lds-valid.td
+include "lds-common.td"
+// Exercise the actual addressable LDS features and their declared policy.
+def GFX942 : AMDGPUProcessorModel<"gfx942", NoSchedModel,
+    [FeatureAddressableLocalMemorySize65536], [9, 4, 2]>;
+def GFX950 : AMDGPUProcessorModel<"gfx950", NoSchedModel,
+    [FeatureAddressableLocalMemorySize163840], [9, 5, 0]>;
+def : AMDGPUProcessorModel<"gfx9-4-generic", NoSchedModel,
+    [FeatureAddressableLocalMemorySize65536], [9, 4, 0]> {
+  let CoveredGPUs = [GFX942, GFX950];
+}
+// CHECK: {[[#]], Triple::AMDGPUSubArch942, {{.*}}, {9, 4, 2}, [[#]], 10, 65536, 32, 0},
+// CHECK: {[[#]], Triple::AMDGPUSubArch950, {{.*}}, {9, 5, 0}, [[#]], 10, 163840, 32, 0},
+// CHECK: {[[#]], Triple::AMDGPUSubArch9_4, {{.*}}, {9, 4, 0}, [[#]], 10, 65536, 32, 0},
+
+//--- lds-conflicting-member.td
+include "lds-common.td"
+// The backend's LDS helper checks 32768 first. Taking the maximum here would
+// incorrectly accept a 65536-byte generic target covering this ambiguous GPU.
+// CHECK: [[FILE]]:[[#@LINE+1]]:5: error: GPU 'gfx900' gets conflicting 'AddressableLocalMemorySize' values from 'addressablelocalmemorysize65536' and 'addressablelocalmemorysize32768'
+def GFX900 : AMDGPUProcessorModel<"gfx900", NoSchedModel,
+    [FeatureAddressableLocalMemorySize32768,
+     FeatureAddressableLocalMemorySize65536], [9, 0, 0]>;
+def : AMDGPUProcessorModel<"gfx9-generic", NoSchedModel,
+    [FeatureAddressableLocalMemorySize65536], [9, 0, 0]> {
+  let CoveredGPUs = [GFX900];
+}
+
+//--- lds-invalid.td
+include "lds-common.td"
+def GFX900 : AMDGPUProcessorModel<"gfx900", NoSchedModel,
+    [FeatureAddressableLocalMemorySize32768], [9, 0, 0]>;
+// The real policy must reject a generic target claiming more LDS than a member.
+// CHECK: [[FILE]]:[[#@LINE+1]]:1: error: generic target 'gfx9-generic' has 'AddressableLocalMemorySize' value 65536, which must be at most the value 32768 of covered GPU 'gfx900'
+def : AMDGPUProcessorModel<"gfx9-generic", NoSchedModel,
+    [FeatureAddressableLocalMemorySize65536], [9, 0, 0]> {
+  let CoveredGPUs = [GFX900];
+}



More information about the llvm-branch-commits mailing list