[llvm] [AMDGPU][LowerModuleLDS] Handle non-dynlds zero sized type (PR #84742)
Pierre van Houtryve via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 20 02:10:16 PDT 2024
https://github.com/Pierre-vh updated https://github.com/llvm/llvm-project/pull/84742
>From 7700e6ccfe398d862c4afde25c9bbac64718e0aa Mon Sep 17 00:00:00 2001
From: pvanhout <pierre.vanhoutryve at amd.com>
Date: Wed, 20 Mar 2024 10:09:57 +0100
Subject: [PATCH] [AMDGPU][LowerModuleLDS] Avoid crash on zero-sized types
---
llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp | 4 ++++
.../CodeGen/AMDGPU/lower-module-lds-zero-size-type.ll | 10 ++++++++++
2 files changed, 14 insertions(+)
create mode 100644 llvm/test/CodeGen/AMDGPU/lower-module-lds-zero-size-type.ll
diff --git a/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp b/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
index b85cb26fdc9565..b18f820bd0b728 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
@@ -1398,6 +1398,10 @@ class AMDGPULowerModuleLDS {
LDSVarsToTransform.begin(), LDSVarsToTransform.end()));
for (GlobalVariable *GV : Sorted) {
+ if (DL.getTypeAllocSize(GV->getValueType()) == 0)
+ report_fatal_error("cannot lower LDS '" + GV->getName() +
+ "' because it has a zero-sized type");
+
OptimizedStructLayoutField F(GV,
DL.getTypeAllocSize(GV->getValueType()),
AMDGPU::getAlign(DL, GV));
diff --git a/llvm/test/CodeGen/AMDGPU/lower-module-lds-zero-size-type.ll b/llvm/test/CodeGen/AMDGPU/lower-module-lds-zero-size-type.ll
new file mode 100644
index 00000000000000..9a618ec07cced3
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/lower-module-lds-zero-size-type.ll
@@ -0,0 +1,10 @@
+; RUN: not --crash opt -S -mtriple=amdgcn-- -amdgpu-lower-module-lds --amdgpu-lower-module-lds-strategy=module < %s 2>&1 | FileCheck %s
+; RUN: not --crash opt -S -mtriple=amdgcn-- -passes=amdgpu-lower-module-lds --amdgpu-lower-module-lds-strategy=module < %s 2>&1 | FileCheck %s
+
+; CHECK: LLVM ERROR: cannot lower LDS 'var0' because it has a zero-sized type
+ at var0 = internal addrspace(3) global [0 x float] poison, align 4
+
+define amdgpu_kernel void @kernel() {
+ load float, ptr addrspace(3) @var0
+ ret void
+}
More information about the llvm-commits
mailing list