Skip to content

[AMDGPU] Let LowerModuleLDS run twice on the same module #81729

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,25 @@ class AMDGPULowerModuleLDS {

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

if (GV.isAbsoluteSymbolRef()) {
report_fatal_error(
"LDS variables with absolute addresses are unimplemented.");
}
// Check if the module is consistent: either all GVs are absolute (happens
// when we run the pass more than once), or none are.
const bool IsAbsolute = GV.isAbsoluteSymbolRef();
if (HasAbsoluteGVs.has_value()) {
if (*HasAbsoluteGVs != IsAbsolute) {
report_fatal_error(
"Module cannot mix absolute and non-absolute LDS GVs");
}
} else
HasAbsoluteGVs = IsAbsolute;

if (IsAbsolute)
continue;

for (User *V : GV.users()) {
if (auto *I = dyn_cast<Instruction>(V)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
; RUN: not --crash opt -S -mtriple=amdgcn-- -passes=amdgpu-lower-module-lds < %s 2>&1 | FileCheck %s

@var1 = addrspace(3) global i32 undef, !absolute_symbol !0
@var2 = addrspace(3) global i32 undef

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

!0 = !{i32 0, i32 1}

16 changes: 16 additions & 0 deletions llvm/test/CodeGen/AMDGPU/lds-run-twice-absolute-md.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
; RUN: opt -S -mtriple=amdgcn-- -amdgpu-lower-module-lds %s -o %t.ll
; RUN: opt -S -mtriple=amdgcn-- -amdgpu-lower-module-lds %t.ll -o %t.second.ll
; RUN: diff -ub %t.ll %t.second.ll -I ".*ModuleID.*"

; Check AMDGPULowerModuleLDS can run more than once on the same module, and that
; the second run is a no-op.

@lds = internal unnamed_addr addrspace(3) global i32 undef, align 4, !absolute_symbol !0

define amdgpu_kernel void @test() {
entry:
store i32 1, ptr addrspace(3) @lds
ret void
}

!0 = !{i32 0, i32 1}
14 changes: 14 additions & 0 deletions llvm/test/CodeGen/AMDGPU/lds-run-twice.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
; RUN: opt -S -mtriple=amdgcn-- -amdgpu-lower-module-lds %s -o %t.ll
; RUN: opt -S -mtriple=amdgcn-- -amdgpu-lower-module-lds %t.ll -o %t.second.ll
; RUN: diff -ub %t.ll %t.second.ll -I ".*ModuleID.*"

; Check AMDGPULowerModuleLDS can run more than once on the same module, and that
; the second run is a no-op.

@lds = internal unnamed_addr addrspace(3) global i32 undef, align 4

define amdgpu_kernel void @test() {
entry:
store i32 1, ptr addrspace(3) @lds
ret void
}