[llvm] [AMDGPU] Stop rounding LDS block size for gfx950 (PR #208046)
Frederik Harwath via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 8 03:06:11 PDT 2026
https://github.com/frederik-h updated https://github.com/llvm/llvm-project/pull/208046
>From 36dced8e0e86ffae5a47a9f57e2aaab2c1845d19 Mon Sep 17 00:00:00 2001
From: Frederik Harwath <fharwath at amd.com>
Date: Fri, 26 Jun 2026 07:49:50 -0400
Subject: [PATCH 1/2] [AMDGPU][NFC] Replace shift-based LDS granularity
calculation with division
Replace the shift-based LDS block calculation in getSIProgramInfo with
straightforward division. There seems to be no benefit to using
the more complicated shifting logic.
---
llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp b/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
index 3d191125aac47..726743e247775 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
@@ -1421,17 +1421,17 @@ void AMDGPUAsmPrinter::getSIProgramInfo(SIProgramInfo &ProgInfo,
// Make clamp modifier on NaN input returns 0.
ProgInfo.DX10Clamp = Mode.DX10Clamp;
- unsigned LDSAlignShift = 8;
+ unsigned LDSGranularityBytes;
switch (getLdsDwGranularity(STM)) {
case 512:
case 320:
- LDSAlignShift = 11;
+ LDSGranularityBytes = 2048;
break;
case 128:
- LDSAlignShift = 9;
+ LDSGranularityBytes = 512;
break;
case 64:
- LDSAlignShift = 8;
+ LDSGranularityBytes = 256;
break;
default:
llvm_unreachable("invald LDS block size");
@@ -1442,7 +1442,7 @@ void AMDGPUAsmPrinter::getSIProgramInfo(SIProgramInfo &ProgInfo,
ProgInfo.LDSSize = MFI->getLDSSize();
ProgInfo.LDSBlocks =
- alignTo(ProgInfo.LDSSize, 1ULL << LDSAlignShift) >> LDSAlignShift;
+ alignTo(ProgInfo.LDSSize, LDSGranularityBytes) / LDSGranularityBytes;
// The MCExpr equivalent of divideCeil.
auto DivideCeil = [&Ctx](const MCExpr *Numerator, const MCExpr *Denominator) {
>From 9cbd7c082e47385c531a6acd68d880ac570bf78e Mon Sep 17 00:00:00 2001
From: Frederik Harwath <fharwath at amd.com>
Date: Tue, 7 Jul 2026 12:18:08 -0400
Subject: [PATCH 2/2] [AMDGPU] AsmPrinter: Use getLdsDwGranularity directly
The previous removal of shifts for calculating LdsGranularityBytes
allows to use the return value of getLdsDwGranularity directly
without a conversion.
---
llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp | 19 ++-----------------
llvm/test/CodeGen/AMDGPU/extra-lds-size.ll | 4 ++--
.../CodeGen/AMDGPU/lds-size-hsa-gfx950.ll | 4 ++--
.../CodeGen/AMDGPU/pal-metadata-3.0.gfx950.ll | 2 +-
4 files changed, 7 insertions(+), 22 deletions(-)
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp b/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
index 726743e247775..7e82d5e7a9e0b 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
@@ -1420,27 +1420,12 @@ void AMDGPUAsmPrinter::getSIProgramInfo(SIProgramInfo &ProgInfo,
// Make clamp modifier on NaN input returns 0.
ProgInfo.DX10Clamp = Mode.DX10Clamp;
-
- unsigned LDSGranularityBytes;
- switch (getLdsDwGranularity(STM)) {
- case 512:
- case 320:
- LDSGranularityBytes = 2048;
- break;
- case 128:
- LDSGranularityBytes = 512;
- break;
- case 64:
- LDSGranularityBytes = 256;
- break;
- default:
- llvm_unreachable("invald LDS block size");
- }
-
ProgInfo.SGPRSpill = MFI->getNumSpilledSGPRs();
ProgInfo.VGPRSpill = MFI->getNumSpilledVGPRs();
ProgInfo.LDSSize = MFI->getLDSSize();
+
+ unsigned LDSGranularityBytes = getLdsDwGranularity(STM) * 4;
ProgInfo.LDSBlocks =
alignTo(ProgInfo.LDSSize, LDSGranularityBytes) / LDSGranularityBytes;
diff --git a/llvm/test/CodeGen/AMDGPU/extra-lds-size.ll b/llvm/test/CodeGen/AMDGPU/extra-lds-size.ll
index b31e87c54b563..3b9410a297cb3 100644
--- a/llvm/test/CodeGen/AMDGPU/extra-lds-size.ll
+++ b/llvm/test/CodeGen/AMDGPU/extra-lds-size.ll
@@ -21,10 +21,10 @@
; GFX11-MESA: .long 45100
; GFX11-MESA-NEXT: .long 1024
-; GFX950-PAL: '0x2c0b (SPI_SHADER_PGM_RSRC2_PS)': 0x200
+; GFX950-PAL: '0x2c0b (SPI_SHADER_PGM_RSRC2_PS)': 0x400
; GFX950-MESA: .long 45100
-; GFX950-MESA-NEXT: .long 512
+; GFX950-MESA-NEXT: .long 1024
; GFX1200-PAL: '0x2c0b (SPI_SHADER_PGM_RSRC2_PS)': 0x400
diff --git a/llvm/test/CodeGen/AMDGPU/lds-size-hsa-gfx950.ll b/llvm/test/CodeGen/AMDGPU/lds-size-hsa-gfx950.ll
index 878d204073b27..481af407b5faa 100644
--- a/llvm/test/CodeGen/AMDGPU/lds-size-hsa-gfx950.ll
+++ b/llvm/test/CodeGen/AMDGPU/lds-size-hsa-gfx950.ll
@@ -11,7 +11,7 @@
; GCN-LABEL: test_lds_array_size_131076:
; GCN: .amdhsa_group_segment_fixed_size 131076
; GCN: ; LDSByteSize: 131076 bytes/workgroup
-; MESA: granulated_lds_size = 65
+; MESA: granulated_lds_size = 103
define amdgpu_kernel void @test_lds_array_size_131076() {
%gep = getelementptr inbounds [32768 x i32], ptr addrspace(3) @lds.array.size.131076, i32 0, i32 20
%val = load i32, ptr addrspace(3) %gep
@@ -22,7 +22,7 @@ define amdgpu_kernel void @test_lds_array_size_131076() {
; GCN-LABEL: test_lds_array_size_163840:
; GCN: .amdhsa_group_segment_fixed_size 163840
; GCN: ; LDSByteSize: 163840 bytes/workgroup
-; MESA: granulated_lds_size = 80
+; MESA: granulated_lds_size = 128
define amdgpu_kernel void @test_lds_array_size_163840() {
%gep = getelementptr inbounds [40959 x i32], ptr addrspace(3) @lds.array.size.163840 , i32 0, i32 20
%val = load i32, ptr addrspace(3) %gep
diff --git a/llvm/test/CodeGen/AMDGPU/pal-metadata-3.0.gfx950.ll b/llvm/test/CodeGen/AMDGPU/pal-metadata-3.0.gfx950.ll
index 858a6a06eb029..f9eed7ea99843 100644
--- a/llvm/test/CodeGen/AMDGPU/pal-metadata-3.0.gfx950.ll
+++ b/llvm/test/CodeGen/AMDGPU/pal-metadata-3.0.gfx950.ll
@@ -131,7 +131,7 @@
; CHECK-NEXT: .entry_point_symbol: hs_shader
; CHECK-NEXT: .forward_progress: false
; CHECK-NEXT: .ieee_mode: false
-; CHECK-NEXT: .lds_size: 0xa00
+; CHECK-NEXT: .lds_size: 0x1400
; CHECK-NEXT: .mem_ordered: false
; CHECK-NEXT: .scratch_en: false
; CHECK-NEXT: .scratch_memory_size: 0
More information about the llvm-commits
mailing list