[llvm] [AMDGPU][LowerModuleLDS] Handle non-dynlds zero sized type (PR #84742)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 11 03:49:22 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-amdgpu
Author: Pierre van Houtryve (Pierre-vh)
<details>
<summary>Changes</summary>
Solves SWDEV-449592
---
Full diff: https://github.com/llvm/llvm-project/pull/84742.diff
2 Files Affected:
- (modified) llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp (+2-1)
- (added) llvm/test/CodeGen/AMDGPU/lower-module-lds-zero-sized-type.ll (+31)
``````````diff
diff --git a/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp b/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
index b85cb26fdc9565..621a1fe20ed467 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
@@ -1398,8 +1398,9 @@ class AMDGPULowerModuleLDS {
LDSVarsToTransform.begin(), LDSVarsToTransform.end()));
for (GlobalVariable *GV : Sorted) {
+ unsigned Size = DL.getTypeAllocSize(GV->getValueType());
OptimizedStructLayoutField F(GV,
- DL.getTypeAllocSize(GV->getValueType()),
+ Size ? Size : 1,
AMDGPU::getAlign(DL, GV));
LayoutFields.emplace_back(F);
}
diff --git a/llvm/test/CodeGen/AMDGPU/lower-module-lds-zero-sized-type.ll b/llvm/test/CodeGen/AMDGPU/lower-module-lds-zero-sized-type.ll
new file mode 100644
index 00000000000000..db5ba1154acca8
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/lower-module-lds-zero-sized-type.ll
@@ -0,0 +1,31 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
+; RUN: opt -S -mtriple=amdgcn-- -amdgpu-lower-module-lds --amdgpu-lower-module-lds-strategy=module < %s | FileCheck %s
+; RUN: opt -S -mtriple=amdgcn-- -passes=amdgpu-lower-module-lds --amdgpu-lower-module-lds-strategy=module < %s | FileCheck %s
+
+; Check that we don't crash when lowering an internal zero-sized LDS GV.
+; This specifically tests the LDS module lowering path, not the
+
+ at var0 = internal addrspace(3) global [0 x float] poison, align 4
+
+define void @func() {
+; CHECK-LABEL: define void @func() {
+; CHECK-NEXT: [[IDX:%.*]] = getelementptr inbounds [0 x float], ptr addrspace(3) @llvm.amdgcn.module.lds, i32 0, i32 1
+; CHECK-NEXT: [[V:%.*]] = load float, ptr addrspace(3) [[IDX]], align 4
+; CHECK-NEXT: ret void
+;
+ %idx = getelementptr inbounds [0 x float], ptr addrspace(3) @var0, i32 0, i32 1
+ %v = load float, ptr addrspace(3) %idx
+ ret void
+}
+
+define amdgpu_kernel void @kernel() {
+; CHECK-LABEL: define amdgpu_kernel void @kernel() {
+; CHECK-NEXT: call void @llvm.donothing() [ "ExplicitUse"(ptr addrspace(3) @llvm.amdgcn.module.lds) ]
+; CHECK-NEXT: call void @func()
+; CHECK-NEXT: [[TMP1:%.*]] = load float, ptr addrspace(3) @llvm.amdgcn.module.lds, align 4
+; CHECK-NEXT: ret void
+;
+ call void @func()
+ load float, ptr addrspace(3) @var0
+ ret void
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/84742
More information about the llvm-commits
mailing list