Skip to content

Commit d2c817d

Browse files
authored
[AMDGPU] Fix DynLDS causing crash when LowerLDS is run at fullLTO pipeline (#96038)
Direct mapped dynamic LDS is not lowered in the LowerLDSModule pass. Hence it is not marked with an absolute symbol. When the LowerLDS pass is rerun in LTO, compilation fails with an assert "cannot mix abs and non-abs LDVs". This patch adds an additional check for direct mapped dynLDS to skip the assert. Fixes SWDEV-454281
1 parent bf52884 commit d2c817d

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

llvm/lib/Target/AMDGPU/Utils/AMDGPUMemoryUtils.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,14 +207,19 @@ LDSUsesInfoTy getTransitiveUsesOfLDS(const CallGraph &CG, Module &M) {
207207
}
208208

209209
// Verify that we fall into one of 2 cases:
210-
// - All variables are absolute: this is a re-run of the pass
210+
// - All variables are either absolute
211+
// or direct mapped dynamic LDS that is not lowered.
212+
// this is a re-run of the pass
211213
// so we don't have anything to do.
212214
// - No variables are absolute.
213215
std::optional<bool> HasAbsoluteGVs;
214216
for (auto &Map : {DirectMapKernel, IndirectMapKernel}) {
215217
for (auto &[Fn, GVs] : Map) {
216218
for (auto *GV : GVs) {
217219
bool IsAbsolute = GV->isAbsoluteSymbolRef();
220+
bool IsDirectMapDynLDSGV = AMDGPU::isDynamicLDS(*GV) && DirectMapKernel.contains(Fn);
221+
if (IsDirectMapDynLDSGV)
222+
continue;
218223
if (HasAbsoluteGVs.has_value()) {
219224
if (*HasAbsoluteGVs != IsAbsolute) {
220225
report_fatal_error(
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt -S -mtriple=amdgcn-- -amdgpu-lower-module-lds < %s 2>&1 | FileCheck %s
3+
; RUN: opt -S -mtriple=amdgcn-- -passes=amdgpu-lower-module-lds < %s 2>&1 | FileCheck %s
4+
5+
; Dynamic LDS that are direct mapped are not lowered in LowerModuleLDS pass.
6+
; In such cases, LowerModuleLDS is free to leave it in and ignore it, and we want to make sure
7+
; LowerModuleLDS doesn't crash if it re-runs on such modules.
8+
9+
@loweredlds = addrspace(3) global i32 poison, !absolute_symbol !0
10+
@dynlds = external addrspace(3) global [0 x i32]
11+
12+
define amdgpu_kernel void @kern(i32 %val0) {
13+
; CHECK-LABEL: define amdgpu_kernel void @kern(
14+
; CHECK-SAME: i32 [[VAL0:%.*]]) {
15+
; CHECK-NEXT: store i32 0, ptr addrspace(3) @loweredlds, align 4
16+
; CHECK-NEXT: store i32 1, ptr addrspace(3) @dynlds, align 4
17+
; CHECK-NEXT: ret void
18+
;
19+
store i32 0, ptr addrspace(3) @loweredlds
20+
store i32 1, ptr addrspace(3) @dynlds
21+
ret void
22+
}
23+
24+
25+
!0 = !{i32 0, i32 1}

llvm/test/CodeGen/AMDGPU/lds-run-twice.ll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
; Check AMDGPULowerModuleLDS can run more than once on the same module, and that
88
; the second run is a no-op.
99

10+
@dynlds = external addrspace(3) global [0 x i32], align 4
1011
@lds = internal unnamed_addr addrspace(3) global i32 undef, align 4
1112

1213
define amdgpu_kernel void @test() {
1314
entry:
15+
store i32 0, ptr addrspace(3) @dynlds
1416
store i32 1, ptr addrspace(3) @lds
1517
ret void
1618
}

0 commit comments

Comments
 (0)