Skip to content

Commit d4569d4

Browse files
authored
[AMDGPU] Let LowerModuleLDS run twice on the same module (#81729)
If all variables in the module are absolute, this means we're running the pass again on an already lowered module, and that works. If none of them are absolute, lowering can proceed as usual. Only diagnose cases where we have a mix of absolute/non-absolute GVs, which means we added LDS GVs after lowering, which is broken. See #81491 Split from #75333
1 parent 3093d73 commit d4569d4

File tree

4 files changed

+46
-6
lines changed

4 files changed

+46
-6
lines changed

llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,15 +340,25 @@ class AMDGPULowerModuleLDS {
340340

341341
// Get uses from the current function, excluding uses by called functions
342342
// Two output variables to avoid walking the globals list twice
343+
std::optional<bool> HasAbsoluteGVs;
343344
for (auto &GV : M.globals()) {
344345
if (!AMDGPU::isLDSVariableToLower(GV)) {
345346
continue;
346347
}
347348

348-
if (GV.isAbsoluteSymbolRef()) {
349-
report_fatal_error(
350-
"LDS variables with absolute addresses are unimplemented.");
351-
}
349+
// Check if the module is consistent: either all GVs are absolute (happens
350+
// when we run the pass more than once), or none are.
351+
const bool IsAbsolute = GV.isAbsoluteSymbolRef();
352+
if (HasAbsoluteGVs.has_value()) {
353+
if (*HasAbsoluteGVs != IsAbsolute) {
354+
report_fatal_error(
355+
"Module cannot mix absolute and non-absolute LDS GVs");
356+
}
357+
} else
358+
HasAbsoluteGVs = IsAbsolute;
359+
360+
if (IsAbsolute)
361+
continue;
352362

353363
for (User *V : GV.users()) {
354364
if (auto *I = dyn_cast<Instruction>(V)) {

llvm/test/CodeGen/AMDGPU/lds-reject-absolute-addresses.ll renamed to llvm/test/CodeGen/AMDGPU/lds-reject-mixed-absolute-addresses.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
; RUN: not --crash opt -S -mtriple=amdgcn-- -passes=amdgpu-lower-module-lds < %s 2>&1 | FileCheck %s
33

44
@var1 = addrspace(3) global i32 undef, !absolute_symbol !0
5+
@var2 = addrspace(3) global i32 undef
56

6-
; CHECK: LLVM ERROR: LDS variables with absolute addresses are unimplemented.
7+
; CHECK: Module cannot mix absolute and non-absolute LDS GVs
78
define amdgpu_kernel void @kern() {
89
%val0 = load i32, ptr addrspace(3) @var1
910
%val1 = add i32 %val0, 4
@@ -12,4 +13,3 @@ define amdgpu_kernel void @kern() {
1213
}
1314

1415
!0 = !{i32 0, i32 1}
15-
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
; RUN: opt -S -mtriple=amdgcn-- -amdgpu-lower-module-lds %s -o %t.ll
2+
; RUN: opt -S -mtriple=amdgcn-- -amdgpu-lower-module-lds %t.ll -o %t.second.ll
3+
; RUN: diff -ub %t.ll %t.second.ll -I ".*ModuleID.*"
4+
5+
; Check AMDGPULowerModuleLDS can run more than once on the same module, and that
6+
; the second run is a no-op.
7+
8+
@lds = internal unnamed_addr addrspace(3) global i32 undef, align 4, !absolute_symbol !0
9+
10+
define amdgpu_kernel void @test() {
11+
entry:
12+
store i32 1, ptr addrspace(3) @lds
13+
ret void
14+
}
15+
16+
!0 = !{i32 0, i32 1}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
; RUN: opt -S -mtriple=amdgcn-- -amdgpu-lower-module-lds %s -o %t.ll
2+
; RUN: opt -S -mtriple=amdgcn-- -amdgpu-lower-module-lds %t.ll -o %t.second.ll
3+
; RUN: diff -ub %t.ll %t.second.ll -I ".*ModuleID.*"
4+
5+
; Check AMDGPULowerModuleLDS can run more than once on the same module, and that
6+
; the second run is a no-op.
7+
8+
@lds = internal unnamed_addr addrspace(3) global i32 undef, align 4
9+
10+
define amdgpu_kernel void @test() {
11+
entry:
12+
store i32 1, ptr addrspace(3) @lds
13+
ret void
14+
}

0 commit comments

Comments
 (0)