[llvm] [AMDGPU] Stop rounding up LDS block size for gfx950 (PR #208046)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 8 06:14:36 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-amdgpu
Author: Frederik Harwath (frederik-h)
<details>
<summary>Changes</summary>
The AMDGPUAsmPrinter::getSIProgramInfo function calculates the number of LDS blocks in a somewhat indirect way: It obtains the LDS granularity from another function, determines an "LDSAlignShift" based on this and then uses shifts to perform multiplication and division. The use of shifts forces the factor to be a power of two which works for all LDS granularity values except for the value of 1280 bytes used for gfx950. For this, the function uses LDSAlignShift = 11 which means that the block size gets rounded up to 2048. This implies that the computed number of LDS blocks is too small.
Remove the use of LDSAlignShift from getSIProgramInfo and divide by the LDS granularity directly.
---
Full diff: https://github.com/llvm/llvm-project/pull/208046.diff
4 Files Affected:
- (modified) llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp (+3-18)
- (modified) llvm/test/CodeGen/AMDGPU/extra-lds-size.ll (+2-2)
- (modified) llvm/test/CodeGen/AMDGPU/lds-size-hsa-gfx950.ll (+2-2)
- (modified) llvm/test/CodeGen/AMDGPU/pal-metadata-3.0.gfx950.ll (+1-1)
``````````diff
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp b/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
index 3d191125aac47..7e82d5e7a9e0b 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
@@ -1420,29 +1420,14 @@ void AMDGPUAsmPrinter::getSIProgramInfo(SIProgramInfo &ProgInfo,
// Make clamp modifier on NaN input returns 0.
ProgInfo.DX10Clamp = Mode.DX10Clamp;
-
- unsigned LDSAlignShift = 8;
- switch (getLdsDwGranularity(STM)) {
- case 512:
- case 320:
- LDSAlignShift = 11;
- break;
- case 128:
- LDSAlignShift = 9;
- break;
- case 64:
- LDSAlignShift = 8;
- 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, 1ULL << LDSAlignShift) >> LDSAlignShift;
+ alignTo(ProgInfo.LDSSize, LDSGranularityBytes) / LDSGranularityBytes;
// The MCExpr equivalent of divideCeil.
auto DivideCeil = [&Ctx](const MCExpr *Numerator, const MCExpr *Denominator) {
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/208046
More information about the llvm-commits
mailing list