[AMDGPU] Fix LDS reporting for targets without CU mode #223587
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-amdgpu
Author: Chinmay Deshpande (chinmaydd)
<details>
<summary>Changes</summary>
CU mode is only meaningful on targets that support WGP execution. However,isFullSIMDMode() currently treats +cumode as effective on every target.
On pre-gfx10 targets this incorrectly selects half-SIMD mode, halving both the
physical and addressable LDS sizes. For example, gfx942 reports a 32 KiB limit
instead of 64 KiB, while gfx950 reports 80 KiB instead of 160 KiB. This causedCodeGen/AMDGPU/lds-limit-diagnostics.ll to fail in ROCm CI after #<!-- -->220718.
---
Full diff: https://github.com/llvm/llvm-project/pull/223587.diff
3 Files Affected:
````````````diff --git a/llvm/lib/Target/AMDGPU/GCNSubtarget.h b/llvm/lib/Target/AMDGPU/GCNSubtarget.h
index 3c42fd40fbabc..c08134119d874 100644
--- a/llvm/lib/Target/AMDGPU/GCNSubtarget.h
+++ b/llvm/lib/Target/AMDGPU/GCNSubtarget.h
@@ -366,7 +366,7 @@ class GCNSubtarget final : public AMDGPUGenSubtargetInfo,
/// \returns Whether a work-group runs on all of the block's SIMDs.
bool isFullSIMDMode() const {
- return (HasGFX1250Insts && getGeneration() < GFX13) || !EnableCuMode;
+ return !hasSupportsWGP() || !EnableCuMode;
}
bool isPreciseMemoryEnabled() const { return EnablePreciseMemory; }
diff --git a/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp b/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
index 58ca7e69cecf8..39754cdd2e7e9 100644
--- a/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
@@ -2528,7 +2528,9 @@ bool isGFX1250(const MCSubtargetInfo &STI) {
}
bool isFullSIMDMode(const MCSubtargetInfo &STI) {
- return isGFX1250(STI) || !STI.getFeatureBits().test(FeatureCuMode);
+ // CU mode is only meaningful on targets that have WGP mode. Elsewhere the
+ // feature may still be requested, but it has no effect.
+ return !supportsWGP(STI) || !STI.getFeatureBits().test(FeatureCuMode);
}
bool isGFX1250Plus(const MCSubtargetInfo &STI) {
diff --git a/llvm/test/CodeGen/AMDGPU/lds-limit-diagnostics.ll b/llvm/test/CodeGen/AMDGPU/lds-limit-diagnostics.ll
index 008f8e74de8b1..5f6e22c978760 100644
--- a/llvm/test/CodeGen/AMDGPU/lds-limit-diagnostics.ll
+++ b/llvm/test/CodeGen/AMDGPU/lds-limit-diagnostics.ll
@@ -15,6 +15,11 @@
; RUN: not llc -mtriple=amdgpu7.00-amd-amdhsa -filetype=null %s 2>&1 | FileCheck -check-prefix=ERROR-LIMIT64K %s
; RUN: not llc -mtriple=amdgpu6.00-amd-amdpal -filetype=null %s 2>&1 | FileCheck -check-prefix=ERROR-LIMIT32K %s
+; Pre-gfx10 has no WGP mode, so +cumode must not change the limit.
+; RUN: not llc -mtriple=amdgpu9.42-amd-amdhsa -mattr=+cumode -filetype=null %s 2>&1 | FileCheck -check-prefix=ERROR-LIMIT64K %s
+; RUN: not llc -mtriple=amdgpu9.0a-amd-amdhsa -mattr=+cumode -filetype=null %s 2>&1 | FileCheck -check-prefix=ERROR-LIMIT64K %s
+; RUN: not llc -mtriple=amdgpu9.50-amd-amdhsa -mattr=+cumode -filetype=null %s 2>&1 | FileCheck -check-prefix=ERROR-LIMIT160K %s
+
; gfx950 supports upto 160 KB LDS memory. The generic target does not.
; This is a negative test to check when the LDS size exceeds the max usable limit.
</details>
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:white_check_mark: With the latest revision this PR passed the C/C++ code formatter.
bool isFullSIMDMode() const { return !hasSupportsWGP() || !EnableCuMode; }
Yeah, I actually wondered what kind of mode before gfx10? How many SIMDs does a target support?
Looks like before gfx10 there is no selectable CU/WGP execution mode. A pre-gfx10 CU contains four SIMDs, and a work-group's waves can run across all four.
But the +cumode selects the two-SIMD mode (what we are calling half-SIMD) on targets with WGP support (gfx10+)
Matt wanted to entirely remove the cumode feature
This is all too confusing...
chinmaydd
CU mode is only meaningful on targets that support WGP execution. However,
isFullSIMDMode()currently treats+cumodeas effective on every target.On pre-gfx10 targets this incorrectly selects half-SIMD mode, halving both the
physical and addressable LDS sizes. For example, gfx942 reports a 32 KiB limit
instead of 64 KiB, while gfx950 reports 80 KiB instead of 160 KiB. This caused
CodeGen/AMDGPU/lds-limit-diagnostics.llto fail in ROCm CI after #220718.