[llvm] [AMDGPU] Add target features for artificial LDS size limit (PR #229153)

Mariusz Sikora via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 5 09:52:10 PDT 2026


https://github.com/mariusz-sikora-at-amd created https://github.com/llvm/llvm-project/pull/229153

Add local-memory-size-limit-{65536,131072} to limit the LDS size below the hardware maximum. They are not set by default for any gpu and are meant to be used only by a frontend like LLPC. For now only gfx13 will use them.

>From e9648aec0b3c5b6d940de6ca0e5594048f34c6fc Mon Sep 17 00:00:00 2001
From: Mariusz Sikora <mariusz.sikora at amd.com>
Date: Mon, 5 Oct 2026 10:09:23 -0400
Subject: [PATCH] [AMDGPU] Add target features for artificial LDS size limit

Add local-memory-size-limit-{65536,131072} to limit the LDS size below
the hardware maximum. They are not set by default for any gpu and
are meant to be used only by a frontend like LLPC. For now only gfx13
will use them.
---
 .../llvm/TargetParser/AMDGPUTargetParser.h    |  18 ++-
 llvm/lib/Target/AMDGPU/AMDGPU.td              |   8 +
 llvm/lib/Target/AMDGPU/AMDGPUFeatures.td      |  13 ++
 llvm/lib/Target/AMDGPU/AMDGPUSubtarget.h      |   1 +
 llvm/lib/Target/AMDGPU/GCNSubtarget.cpp       |  17 +-
 llvm/lib/TargetParser/AMDGPUTargetParser.cpp  |  25 ++-
 .../AMDGPU/check-subtarget-features.ll        |   6 +
 .../lds-limit-diagnostics-gfx13-limit.ll      |  14 ++
 .../occupancy-levels-gfx1310-lds-limit.ll     | 148 ++++++++++++++++++
 .../TargetParser/TargetParserTest.cpp         |  28 ++++
 10 files changed, 261 insertions(+), 17 deletions(-)
 create mode 100644 llvm/test/CodeGen/AMDGPU/lds-limit-diagnostics-gfx13-limit.ll
 create mode 100644 llvm/test/CodeGen/AMDGPU/occupancy-levels-gfx1310-lds-limit.ll

diff --git a/llvm/include/llvm/TargetParser/AMDGPUTargetParser.h b/llvm/include/llvm/TargetParser/AMDGPUTargetParser.h
index 042542ced349da..12dad163a15800 100644
--- a/llvm/include/llvm/TargetParser/AMDGPUTargetParser.h
+++ b/llvm/include/llvm/TargetParser/AMDGPUTargetParser.h
@@ -227,15 +227,21 @@ getMaxHWAddressableLocalMemorySize(Triple::SubArchType SubArch);
 
 /// \returns Total LDS in bytes available to work-groups sharing a physical
 /// block. \p FullSIMDMode selects full-SIMD mode (four SIMDs) when true and
-/// half-SIMD mode (two SIMDs) otherwise.
-LLVM_ABI unsigned getLocalMemorySize(GPUKind AK, bool FullSIMDMode);
+/// half-SIMD mode (two SIMDs) otherwise. \p LimitBytes imposes an artificial
+/// limit on the addressable LDS below the HW cap (0 means no artificial limit).
+LLVM_ABI unsigned getLocalMemorySize(GPUKind AK, bool FullSIMDMode,
+                                     unsigned LimitBytes = 0);
 LLVM_ABI unsigned getLocalMemorySize(Triple::SubArchType SubArch,
-                                     bool FullSIMDMode);
+                                     bool FullSIMDMode,
+                                     unsigned LimitBytes = 0);
 
-/// \returns LDS in bytes a single work-group can allocate.
-LLVM_ABI unsigned getAddressableLocalMemorySize(GPUKind AK, bool FullSIMDMode);
+/// \returns LDS in bytes a single work-group can allocate. \p LimitBytes
+/// imposes an artificial limit below the HW cap (0 means no artificial limit).
+LLVM_ABI unsigned getAddressableLocalMemorySize(GPUKind AK, bool FullSIMDMode,
+                                                unsigned LimitBytes = 0);
 LLVM_ABI unsigned getAddressableLocalMemorySize(Triple::SubArchType SubArch,
-                                                bool FullSIMDMode);
+                                                bool FullSIMDMode,
+                                                unsigned LimitBytes = 0);
 
 /// \returns Number of LDS banks per compute unit.
 LLVM_ABI unsigned getLDSBankCount(GPUKind AK);
diff --git a/llvm/lib/Target/AMDGPU/AMDGPU.td b/llvm/lib/Target/AMDGPU/AMDGPU.td
index d552eae9c08d31..157113bb41021d 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPU.td
+++ b/llvm/lib/Target/AMDGPU/AMDGPU.td
@@ -303,6 +303,13 @@ defm HalfAddressablePhysicalLocalMemory : AMDGPUSubtargetFeature<"half-addressab
   /*GenPredicate=*/0
 >;
 
+// Target can use the LDS/VC (vector cache) split, so the LDS size can be
+// limited with local-memory-size-limit-*.
+defm SupportsLocalMemorySizeLimit : AMDGPUSubtargetFeature<"supports-local-memory-size-limit",
+  "Hardware supports limiting the LDS size",
+  /*GenPredicate=*/0
+>;
+
 defm MFMAInlineLiteralBug : AMDGPUSubtargetFeature<"mfma-inline-literal-bug",
   "MFMA cannot use inline literal as SrcC",
   /*GenPredicate=*/0
@@ -2701,6 +2708,7 @@ def FeatureISAVersion13 : FeatureSet<
    FeatureWaveMatchInsts,
    FeatureExclusiveScanInsts,
    FeatureAddressableLocalMemorySize196608,
+   FeatureSupportsLocalMemorySizeLimit,
    FeatureLDSAllocGranularity1024,
    FeatureLDSEncodingGranularity1024,
    Feature64BitLiterals,
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUFeatures.td b/llvm/lib/Target/AMDGPU/AMDGPUFeatures.td
index cd3ac06f60fd1c..a27711e7adb7e9 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUFeatures.td
+++ b/llvm/lib/Target/AMDGPU/AMDGPUFeatures.td
@@ -46,6 +46,19 @@ def FeatureAddressableLocalMemorySize163840 : SubtargetFeatureAddressableLocalMe
 def FeatureAddressableLocalMemorySize196608 : SubtargetFeatureAddressableLocalMemorySize<196608>;
 def FeatureAddressableLocalMemorySize327680 : SubtargetFeatureAddressableLocalMemorySize<327680>;
 
+// Limit the LDS size below the hardware maximum. It is not enabled by default
+// for any processor. A frontend like LLPC can set it. Only one limit can be
+// used.
+class SubtargetFeatureLocalMemorySizeLimit <int Value> : SubtargetFeature<
+  "local-memory-size-limit-"#Value,
+  "LocalMemorySizeLimit",
+  !cast<string>(Value),
+  "Artificial limit on local memory (LDS), specified in bytes"
+>;
+
+def FeatureLocalMemorySizeLimit65536 : SubtargetFeatureLocalMemorySizeLimit<65536>;
+def FeatureLocalMemorySizeLimit131072 : SubtargetFeatureLocalMemorySizeLimit<131072>;
+
 // A generic target uses the largest allocation granularity of its covered GPUs.
 // Its feature must be present on at least one covered GPU.
 class SubtargetFeatureLDSAllocGranularity <int Granularity> : AMDGPUGenericAnyFeature <
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUSubtarget.h b/llvm/lib/Target/AMDGPU/AMDGPUSubtarget.h
index d2ab61671c932d..6713cdaf4b876f 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUSubtarget.h
+++ b/llvm/lib/Target/AMDGPU/AMDGPUSubtarget.h
@@ -59,6 +59,7 @@ class AMDGPUSubtarget {
   unsigned MaxWavesPerEU = 0;
   unsigned LocalMemorySize = 0;
   unsigned AddressableLocalMemorySize = 0;
+  unsigned LocalMemorySizeLimit = 0;
   unsigned LDSAllocationGranularity = 0;
   unsigned LDSEncodingGranularity = 0;
   char WavefrontSizeLog2 = 0;
diff --git a/llvm/lib/Target/AMDGPU/GCNSubtarget.cpp b/llvm/lib/Target/AMDGPU/GCNSubtarget.cpp
index 31dd8c8be27818..80169b3c8cb7e5 100644
--- a/llvm/lib/Target/AMDGPU/GCNSubtarget.cpp
+++ b/llvm/lib/Target/AMDGPU/GCNSubtarget.cpp
@@ -181,10 +181,12 @@ GCNSubtarget &GCNSubtarget::initializeSubtargetDependencies(const Triple &TT,
   if (FlatOffsetBitWidth == 0)
     FlatOffsetBitWidth = 13;
 
-  LocalMemorySize =
-      AMDGPU::getLocalMemorySize(getTargetID().getGPUKind(), isFullSIMDMode());
+  unsigned LDSLimit =
+      hasSupportsLocalMemorySizeLimit() ? LocalMemorySizeLimit : 0;
+  LocalMemorySize = AMDGPU::getLocalMemorySize(getTargetID().getGPUKind(),
+                                               isFullSIMDMode(), LDSLimit);
   AddressableLocalMemorySize = AMDGPU::getAddressableLocalMemorySize(
-      getTargetID().getGPUKind(), isFullSIMDMode());
+      getTargetID().getGPUKind(), isFullSIMDMode(), LDSLimit);
   // LDS allocation granularity is in bytes.
   LDSAllocationGranularity =
       AMDGPU::getLDSAllocGranule(getTargetID().getGPUKind());
@@ -211,6 +213,15 @@ void GCNSubtarget::checkSubtargetFeatures(const Function &F) const {
     Ctx.diagnose(DiagnosticInfoUnsupported(
         F, "must specify exactly one of wavefrontsize32 and wavefrontsize64"));
   }
+  if (hasFeature(AMDGPU::FeatureLocalMemorySizeLimit65536) &&
+      hasFeature(AMDGPU::FeatureLocalMemorySizeLimit131072)) {
+    Ctx.diagnose(DiagnosticInfoUnsupported(
+        F, "only one local-memory-size-limit feature can be used"));
+  }
+  if (LocalMemorySizeLimit && !hasSupportsLocalMemorySizeLimit()) {
+    Ctx.diagnose(DiagnosticInfoUnsupported(
+        F, "local-memory-size-limit is not supported on this target"));
+  }
 }
 
 // TODO: Validate subarch for subtarget
diff --git a/llvm/lib/TargetParser/AMDGPUTargetParser.cpp b/llvm/lib/TargetParser/AMDGPUTargetParser.cpp
index 116014826ed679..e8933e16a87a4e 100644
--- a/llvm/lib/TargetParser/AMDGPUTargetParser.cpp
+++ b/llvm/lib/TargetParser/AMDGPUTargetParser.cpp
@@ -478,9 +478,12 @@ AMDGPU::getMaxHWAddressableLocalMemorySize(Triple::SubArchType SubArch) {
   return getMaxHWAddressableLocalMemorySize(getGPUKindFromSubArch(SubArch));
 }
 
-unsigned AMDGPU::getLocalMemorySize(GPUKind AK, bool FullSIMDMode) {
+unsigned AMDGPU::getLocalMemorySize(GPUKind AK, bool FullSIMDMode,
+                                    unsigned LimitBytes) {
   // gfx6 and gfx10/11/12 address half of the physical block.
   unsigned Size = getMaxHWAddressableLocalMemorySize(AK);
+  if (LimitBytes)
+    Size = std::min(Size, LimitBytes);
   if (getFeatureBitset(AK).test(FEAT_HALF_ADDRESSABLE_PHYSICAL_LOCAL_MEMORY))
     Size *= 2;
 
@@ -492,19 +495,25 @@ unsigned AMDGPU::getLocalMemorySize(GPUKind AK, bool FullSIMDMode) {
 }
 
 unsigned AMDGPU::getLocalMemorySize(Triple::SubArchType SubArch,
-                                    bool FullSIMDMode) {
-  return getLocalMemorySize(getGPUKindFromSubArch(SubArch), FullSIMDMode);
+                                    bool FullSIMDMode, unsigned LimitBytes) {
+  return getLocalMemorySize(getGPUKindFromSubArch(SubArch), FullSIMDMode,
+                            LimitBytes);
 }
 
-unsigned AMDGPU::getAddressableLocalMemorySize(GPUKind AK, bool FullSIMDMode) {
-  return std::min(getMaxHWAddressableLocalMemorySize(AK),
-                  getLocalMemorySize(AK, FullSIMDMode));
+unsigned AMDGPU::getAddressableLocalMemorySize(GPUKind AK, bool FullSIMDMode,
+                                               unsigned LimitBytes) {
+  unsigned MaxAddressable = getMaxHWAddressableLocalMemorySize(AK);
+  if (LimitBytes)
+    MaxAddressable = std::min(MaxAddressable, LimitBytes);
+  return std::min(MaxAddressable,
+                  getLocalMemorySize(AK, FullSIMDMode, LimitBytes));
 }
 
 unsigned AMDGPU::getAddressableLocalMemorySize(Triple::SubArchType SubArch,
-                                               bool FullSIMDMode) {
+                                               bool FullSIMDMode,
+                                               unsigned LimitBytes) {
   return getAddressableLocalMemorySize(getGPUKindFromSubArch(SubArch),
-                                       FullSIMDMode);
+                                       FullSIMDMode, LimitBytes);
 }
 
 unsigned AMDGPU::getLDSBankCount(GPUKind AK) {
diff --git a/llvm/test/CodeGen/AMDGPU/check-subtarget-features.ll b/llvm/test/CodeGen/AMDGPU/check-subtarget-features.ll
index d6f25e3059faf1..1be89d47f64bfe 100644
--- a/llvm/test/CodeGen/AMDGPU/check-subtarget-features.ll
+++ b/llvm/test/CodeGen/AMDGPU/check-subtarget-features.ll
@@ -1,7 +1,13 @@
 ; RUN: not llc -global-isel=0 -mtriple=amdgpu11.00 -mattr=+wavefrontsize32,+wavefrontsize64 < %s 2>&1 | FileCheck %s -check-prefix=ERR -implicit-check-not=error:
 ; RUN: not llc -global-isel=1 -mtriple=amdgpu11.00 -mattr=+wavefrontsize32,+wavefrontsize64 < %s 2>&1 | FileCheck %s -check-prefix=ERR -implicit-check-not=error:
+; RUN: not llc -global-isel=0 -mtriple=amdgpu13.10 -mattr=+local-memory-size-limit-65536,+local-memory-size-limit-131072 < %s 2>&1 | FileCheck %s -check-prefix=LDS-LIMIT-ERR -implicit-check-not=error:
+; RUN: not llc -global-isel=1 -mtriple=amdgpu13.10 -mattr=+local-memory-size-limit-65536,+local-memory-size-limit-131072 < %s 2>&1 | FileCheck %s -check-prefix=LDS-LIMIT-ERR -implicit-check-not=error:
+; RUN: not llc -global-isel=0 -mtriple=amdgpu12.00 -mattr=+local-memory-size-limit-131072 < %s 2>&1 | FileCheck %s -check-prefix=LDS-LIMIT-UNSUPPORTED-ERR -implicit-check-not=error:
+; RUN: not llc -global-isel=1 -mtriple=amdgpu12.00 -mattr=+local-memory-size-limit-131072 < %s 2>&1 | FileCheck %s -check-prefix=LDS-LIMIT-UNSUPPORTED-ERR -implicit-check-not=error:
 
 ; ERR: error: {{.*}} in function f void (): must specify exactly one of wavefrontsize32 and wavefrontsize64
+; LDS-LIMIT-ERR: error: {{.*}} in function f void (): only one local-memory-size-limit feature can be used
+; LDS-LIMIT-UNSUPPORTED-ERR: error: {{.*}} in function f void (): local-memory-size-limit is not supported on this target
 
 define void @f() {
   ret void
diff --git a/llvm/test/CodeGen/AMDGPU/lds-limit-diagnostics-gfx13-limit.ll b/llvm/test/CodeGen/AMDGPU/lds-limit-diagnostics-gfx13-limit.ll
new file mode 100644
index 00000000000000..42c25221e45031
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/lds-limit-diagnostics-gfx13-limit.ll
@@ -0,0 +1,14 @@
+; RUN: not llc -mtriple=amdgpu13.10-amd-amdhsa -mattr=+local-memory-size-limit-131072 < %s 2>&1 | FileCheck -check-prefix=ERROR-128K %s
+; RUN: not llc -mtriple=amdgpu13.10-amd-amdhsa -mattr=+local-memory-size-limit-65536 < %s 2>&1 | FileCheck -check-prefix=ERROR-64K %s
+; RUN: not llc -mtriple=amdgpu13.10-amd-amdhsa -mattr=+local-memory-size-limit-131072,+cumode < %s 2>&1 | FileCheck -check-prefix=ERROR-128K-CU %s
+
+; ERROR-128K: error: <unknown>:0:0: local memory (131076) exceeds limit (131072) in function 'test_lds_limit'
+; ERROR-64K: error: <unknown>:0:0: local memory (131076) exceeds limit (65536) in function 'test_lds_limit'
+; ERROR-128K-CU: error: <unknown>:0:0: local memory (131076) exceeds limit (65536) in function 'test_lds_limit'
+ at dst = addrspace(3) global [131076 x i8] poison
+
+define amdgpu_kernel void @test_lds_limit(i8 %val) {
+  %gep = getelementptr [131076 x i8], ptr addrspace(3) @dst, i32 0, i32 100
+  store i8 %val, ptr addrspace(3) %gep
+  ret void
+}
diff --git a/llvm/test/CodeGen/AMDGPU/occupancy-levels-gfx1310-lds-limit.ll b/llvm/test/CodeGen/AMDGPU/occupancy-levels-gfx1310-lds-limit.ll
new file mode 100644
index 00000000000000..a2cd68dd7139f7
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/occupancy-levels-gfx1310-lds-limit.ll
@@ -0,0 +1,148 @@
+; RUN: llc -mtriple=amdgpu13.10 < %s | FileCheck --check-prefixes=GCN,W32WG-LDS192 %s
+; RUN: llc -mtriple=amdgpu13.10 -mattr=+wavefrontsize64 < %s | FileCheck --check-prefixes=GCN,W64WG-LDS192 %s
+; RUN: llc -mtriple=amdgpu13.10 -mattr=+cumode < %s | FileCheck --check-prefixes=GCN,W32CU-LDS192 %s
+; RUN: llc -mtriple=amdgpu13.10 -mattr=+wavefrontsize64,+cumode < %s | FileCheck --check-prefixes=GCN,W64CU-LDS192 %s
+; RUN: llc -mtriple=amdgpu13.10 -mattr=+local-memory-size-limit-131072 < %s | FileCheck --check-prefixes=GCN,W32WG-LDS128 %s
+; RUN: llc -mtriple=amdgpu13.10 -mattr=+wavefrontsize64,+local-memory-size-limit-131072 < %s | FileCheck --check-prefixes=GCN,W64WG-LDS128 %s
+; RUN: llc -mtriple=amdgpu13.10 -mattr=+cumode,+local-memory-size-limit-131072 < %s | FileCheck --check-prefixes=GCN,W32CU-LDS128 %s
+; RUN: llc -mtriple=amdgpu13.10 -mattr=+wavefrontsize64,+cumode,+local-memory-size-limit-131072 < %s | FileCheck --check-prefixes=GCN,W64CU-LDS128 %s
+; RUN: llc -mtriple=amdgpu13.10 -mattr=+local-memory-size-limit-65536 < %s | FileCheck --check-prefixes=GCN,W32WG-LDS64 %s
+; RUN: llc -mtriple=amdgpu13.10 -mattr=+wavefrontsize64,+local-memory-size-limit-65536 < %s | FileCheck --check-prefixes=GCN,W64WG-LDS64 %s
+; RUN: llc -mtriple=amdgpu13.10 -mattr=+cumode,+local-memory-size-limit-65536 < %s | FileCheck --check-prefixes=GCN,W32CU-LDS64 %s
+; RUN: llc -mtriple=amdgpu13.10 -mattr=+wavefrontsize64,+cumode,+local-memory-size-limit-65536 < %s | FileCheck --check-prefixes=GCN,W64CU-LDS64 %s
+
+ at lds8252 = internal addrspace(3) global [8252 x i8] poison, align 4
+
+; GCN-LABEL: {{^}}used_lds_8252_max_group_size_32:
+; W32WG-LDS192: ; Occupancy: 6{{$}}
+; W32CU-LDS192: ; Occupancy: 5{{$}}
+; W64WG-LDS192: ; Occupancy: 6{{$}}
+; W64CU-LDS192: ; Occupancy: 5{{$}}
+; W32WG-LDS128: ; Occupancy: 4{{$}}
+; W32CU-LDS128: ; Occupancy: 4{{$}}
+; W64WG-LDS128: ; Occupancy: 4{{$}}
+; W64CU-LDS128: ; Occupancy: 4{{$}}
+; W32WG-LDS64: ; Occupancy: 2{{$}}
+; W32CU-LDS64: ; Occupancy: 2{{$}}
+; W64WG-LDS64: ; Occupancy: 2{{$}}
+; W64CU-LDS64: ; Occupancy: 2{{$}}
+define amdgpu_kernel void @used_lds_8252_max_group_size_32() #0 {
+  store volatile i8 1, ptr addrspace(3) @lds8252
+  ret void
+}
+
+; GCN-LABEL: {{^}}used_lds_8252_max_group_size_64:
+; W32WG-LDS192: ; Occupancy: 11{{$}}
+; W32CU-LDS192: ; Occupancy: 10{{$}}
+; W64WG-LDS192: ; Occupancy: 6{{$}}
+; W64CU-LDS192: ; Occupancy: 5{{$}}
+; W32WG-LDS128: ; Occupancy: 7{{$}}
+; W32CU-LDS128: ; Occupancy: 7{{$}}
+; W64WG-LDS128: ; Occupancy: 4{{$}}
+; W64CU-LDS128: ; Occupancy: 4{{$}}
+; W32WG-LDS64: ; Occupancy: 4{{$}}
+; W32CU-LDS64: ; Occupancy: 3{{$}}
+; W64WG-LDS64: ; Occupancy: 2{{$}}
+; W64CU-LDS64: ; Occupancy: 2{{$}}
+define amdgpu_kernel void @used_lds_8252_max_group_size_64() #1 {
+  store volatile i8 1, ptr addrspace(3) @lds8252
+  ret void
+}
+
+; GCN-LABEL: {{^}}used_lds_8252_max_group_size_96:
+; W32WG-LDS192: ; Occupancy: 16{{$}}
+; W32CU-LDS192: ; Occupancy: 15{{$}}
+; W64WG-LDS192: ; Occupancy: 11{{$}}
+; W64CU-LDS192: ; Occupancy: 10{{$}}
+; W32WG-LDS128: ; Occupancy: 11{{$}}
+; W32CU-LDS128: ; Occupancy: 11{{$}}
+; W64WG-LDS128: ; Occupancy: 7{{$}}
+; W64CU-LDS128: ; Occupancy: 7{{$}}
+; W32WG-LDS64: ; Occupancy: 6{{$}}
+; W32CU-LDS64: ; Occupancy: 5{{$}}
+; W64WG-LDS64: ; Occupancy: 4{{$}}
+; W64CU-LDS64: ; Occupancy: 3{{$}}
+define amdgpu_kernel void @used_lds_8252_max_group_size_96() #2 {
+  store volatile i8 1, ptr addrspace(3) @lds8252
+  ret void
+}
+
+; GCN-LABEL: {{^}}used_lds_8252_max_group_size_128:
+; W32WG-LDS192: ; Occupancy: 16{{$}}
+; W32CU-LDS192: ; Occupancy: 16{{$}}
+; W64WG-LDS192: ; Occupancy: 11{{$}}
+; W64CU-LDS192: ; Occupancy: 10{{$}}
+; W32WG-LDS128: ; Occupancy: 14{{$}}
+; W32CU-LDS128: ; Occupancy: 14{{$}}
+; W64WG-LDS128: ; Occupancy: 7{{$}}
+; W64CU-LDS128: ; Occupancy: 7{{$}}
+; W32WG-LDS64: ; Occupancy: 7{{$}}
+; W32CU-LDS64: ; Occupancy: 6{{$}}
+; W64WG-LDS64: ; Occupancy: 4{{$}}
+; W64CU-LDS64: ; Occupancy: 3{{$}}
+define amdgpu_kernel void @used_lds_8252_max_group_size_128() #3 {
+  store volatile i8 1, ptr addrspace(3) @lds8252
+  ret void
+}
+
+; GCN-LABEL: {{^}}used_lds_8252_max_group_size_192:
+; W32WG-LDS192: ; Occupancy: 15{{$}}
+; W32CU-LDS192: ; Occupancy: 15{{$}}
+; W64WG-LDS192: ; Occupancy: 16{{$}}
+; W64CU-LDS192: ; Occupancy: 15{{$}}
+; W32WG-LDS128: ; Occupancy: 15{{$}}
+; W32CU-LDS128: ; Occupancy: 15{{$}}
+; W64WG-LDS128: ; Occupancy: 11{{$}}
+; W64CU-LDS128: ; Occupancy: 11{{$}}
+; W32WG-LDS64: ; Occupancy: 11{{$}}
+; W32CU-LDS64: ; Occupancy: 9{{$}}
+; W64WG-LDS64: ; Occupancy: 6{{$}}
+; W64CU-LDS64: ; Occupancy: 5{{$}}
+define amdgpu_kernel void @used_lds_8252_max_group_size_192() #4 {
+  store volatile i8 1, ptr addrspace(3) @lds8252
+  ret void
+}
+
+; GCN-LABEL: {{^}}used_lds_8252_max_group_size_256:
+; W32WG-LDS192: ; Occupancy: 16{{$}}
+; W32CU-LDS192: ; Occupancy: 16{{$}}
+; W64WG-LDS192: ; Occupancy: 16{{$}}
+; W64CU-LDS192: ; Occupancy: 16{{$}}
+; W32WG-LDS128: ; Occupancy: 16{{$}}
+; W32CU-LDS128: ; Occupancy: 16{{$}}
+; W64WG-LDS128: ; Occupancy: 14{{$}}
+; W64CU-LDS128: ; Occupancy: 14{{$}}
+; W32WG-LDS64: ; Occupancy: 14{{$}}
+; W32CU-LDS64: ; Occupancy: 12{{$}}
+; W64WG-LDS64: ; Occupancy: 7{{$}}
+; W64CU-LDS64: ; Occupancy: 6{{$}}
+define amdgpu_kernel void @used_lds_8252_max_group_size_256() #5 {
+  store volatile i8 1, ptr addrspace(3) @lds8252
+  ret void
+}
+
+; GCN-LABEL: {{^}}used_lds_8252_max_group_size_512:
+; W32WG-LDS192: ; Occupancy: 16{{$}}
+; W32CU-LDS192: ; Occupancy: 16{{$}}
+; W64WG-LDS192: ; Occupancy: 16{{$}}
+; W64CU-LDS192: ; Occupancy: 16{{$}}
+; W32WG-LDS128: ; Occupancy: 16{{$}}
+; W32CU-LDS128: ; Occupancy: 16{{$}}
+; W64WG-LDS128: ; Occupancy: 16{{$}}
+; W64CU-LDS128: ; Occupancy: 16{{$}}
+; W32WG-LDS64: ; Occupancy: 16{{$}}
+; W32CU-LDS64: ; Occupancy: 16{{$}}
+; W64WG-LDS64: ; Occupancy: 14{{$}}
+; W64CU-LDS64: ; Occupancy: 12{{$}}
+define amdgpu_kernel void @used_lds_8252_max_group_size_512() #6 {
+  store volatile i8 1, ptr addrspace(3) @lds8252
+  ret void
+}
+
+attributes #0 = { "amdgpu-flat-work-group-size"="1,32" }
+attributes #1 = { "amdgpu-flat-work-group-size"="1,64" }
+attributes #2 = { "amdgpu-flat-work-group-size"="1,96" }
+attributes #3 = { "amdgpu-flat-work-group-size"="1,128" }
+attributes #4 = { "amdgpu-flat-work-group-size"="1,192" }
+attributes #5 = { "amdgpu-flat-work-group-size"="1,256" }
+attributes #6 = { "amdgpu-flat-work-group-size"="1,512" }
diff --git a/llvm/unittests/TargetParser/TargetParserTest.cpp b/llvm/unittests/TargetParser/TargetParserTest.cpp
index 78a13daac28678..7a148203d207e8 100644
--- a/llvm/unittests/TargetParser/TargetParserTest.cpp
+++ b/llvm/unittests/TargetParser/TargetParserTest.cpp
@@ -3374,6 +3374,17 @@ TEST(TargetParserTest, testAMDGPUgetLocalMemorySize) {
   EXPECT_EQ(AMDGPU::getLocalMemorySize(Triple::AMDGPUSubArch900, true), 65536u);
   EXPECT_EQ(AMDGPU::getLocalMemorySize(Triple::AMDGPUSubArch1030, true),
             131072u);
+
+  EXPECT_EQ(AMDGPU::getLocalMemorySize(AMDGPU::GK_GFX1310, true, 131072),
+            131072u);
+  EXPECT_EQ(AMDGPU::getLocalMemorySize(AMDGPU::GK_GFX1310, false, 131072),
+            65536u);
+  EXPECT_EQ(AMDGPU::getLocalMemorySize(AMDGPU::GK_GFX1310, true, 65536),
+            65536u);
+  EXPECT_EQ(AMDGPU::getLocalMemorySize(AMDGPU::GK_GFX1310, true, 262144),
+            196608u);
+  EXPECT_EQ(AMDGPU::getLocalMemorySize(AMDGPU::GK_GFX1310, true, 0), 196608u);
+  EXPECT_EQ(AMDGPU::getLocalMemorySize(AMDGPU::GK_GFX1310, true), 196608u);
 }
 
 TEST(TargetParserTest, testAMDGPUgetAddressableLocalMemorySize) {
@@ -3412,6 +3423,23 @@ TEST(TargetParserTest, testAMDGPUgetAddressableLocalMemorySize) {
   EXPECT_EQ(
       AMDGPU::getAddressableLocalMemorySize(Triple::AMDGPUSubArch1030, true),
       65536u);
+
+  EXPECT_EQ(
+      AMDGPU::getAddressableLocalMemorySize(AMDGPU::GK_GFX1310, true, 131072),
+      131072u);
+  EXPECT_EQ(
+      AMDGPU::getAddressableLocalMemorySize(AMDGPU::GK_GFX1310, false, 131072),
+      65536u);
+  EXPECT_EQ(
+      AMDGPU::getAddressableLocalMemorySize(AMDGPU::GK_GFX1310, true, 65536),
+      65536u);
+  EXPECT_EQ(
+      AMDGPU::getAddressableLocalMemorySize(AMDGPU::GK_GFX1310, true, 262144),
+      196608u);
+  EXPECT_EQ(AMDGPU::getAddressableLocalMemorySize(AMDGPU::GK_GFX1310, true, 0),
+            196608u);
+  EXPECT_EQ(AMDGPU::getAddressableLocalMemorySize(AMDGPU::GK_GFX1310, true),
+            196608u);
 }
 
 TEST(TargetParserTest, testAMDGPUgetLDSGranules) {



More information about the llvm-commits mailing list