[llvm] [AMDGPU][LowerModuleLDS] Handle non-dynlds zero sized type (PR #84742)
Pierre van Houtryve via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 11 03:52:07 PDT 2024
https://github.com/Pierre-vh updated https://github.com/llvm/llvm-project/pull/84742
>From de505632d2ccbda8d79263d661733178725598d5 Mon Sep 17 00:00:00 2001
From: pvanhout <pierre.vanhoutryve at amd.com>
Date: Mon, 11 Mar 2024 11:48:22 +0100
Subject: [PATCH 1/2] [AMDGPU][LowerModuleLDS] Handle non-dynlds zero sized
type
Solves SWDEV-449592
---
.../AMDGPU/AMDGPULowerModuleLDSPass.cpp | 3 +-
.../lower-module-lds-zero-sized-type.ll | 31 +++++++++++++++++++
2 files changed, 33 insertions(+), 1 deletion(-)
create mode 100644 llvm/test/CodeGen/AMDGPU/lower-module-lds-zero-sized-type.ll
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
+}
>From ca66dda02dd51e2edc9611f6a84c6fc65e5a9074 Mon Sep 17 00:00:00 2001
From: pvanhout <pierre.vanhoutryve at amd.com>
Date: Mon, 11 Mar 2024 11:51:55 +0100
Subject: [PATCH 2/2] clang-format
---
llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp b/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
index 621a1fe20ed467..a03f1fc273a4cb 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
@@ -1399,8 +1399,7 @@ class AMDGPULowerModuleLDS {
for (GlobalVariable *GV : Sorted) {
unsigned Size = DL.getTypeAllocSize(GV->getValueType());
- OptimizedStructLayoutField F(GV,
- Size ? Size : 1,
+ OptimizedStructLayoutField F(GV, Size ? Size : 1,
AMDGPU::getAlign(DL, GV));
LayoutFields.emplace_back(F);
}
More information about the llvm-commits
mailing list