Skip to content

Commit a21dc5c

Browse files
shiltianronlieb
authored andcommitted
[AMDGPU][Verifier] Check address space of alloca instruction (llvm#135820)
This PR updates the `Verifier` to enforce that `alloca` instructions on AMDGPU must be in AS5. This prevents hitting a misleading backend error like "unable to select FrameIndex," which makes it look like a backend bug when it's actually an IR-level issue.
1 parent c53358c commit a21dc5c

File tree

12 files changed

+4095
-4170
lines changed

12 files changed

+4095
-4170
lines changed

llvm/lib/IR/Verifier.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4418,6 +4418,11 @@ void Verifier::visitAllocaInst(AllocaInst &AI) {
44184418
verifySwiftErrorValue(&AI);
44194419
}
44204420

4421+
if (TT.isAMDGPU()) {
4422+
Check(AI.getAddressSpace() == AMDGPUAS::PRIVATE_ADDRESS,
4423+
"alloca on amdgpu must be in addrspace(5)", &AI);
4424+
}
4425+
44214426
visitInstruction(AI);
44224427
}
44234428

llvm/test/CodeGen/AMDGPU/assert-wrong-alloca-addrspace.ll

Lines changed: 0 additions & 16 deletions
This file was deleted.

llvm/test/CodeGen/AMDGPU/lower-indirect-lds-references.ll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ define amdgpu_kernel void @offloading_kernel() {
1616
}
1717

1818
define void @call_unknown() {
19-
%1 = alloca ptr, align 8
20-
%2 = call i32 %1()
19+
%alloca = alloca ptr, align 8, addrspace(5)
20+
%alloca.cast = addrspacecast ptr addrspace(5) %alloca to ptr
21+
%ret = call i32 %alloca.cast()
2122
ret void
2223
}
2324

llvm/test/CodeGen/Generic/llvm.dbg.def_kill-dag-isel.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ entry:
3535

3636
define void @alloca() {
3737
entry:
38-
%0 = alloca i1
39-
call void @llvm.dbg.def(metadata !11, metadata i1* %0), !dbg !5
38+
%0 = alloca i1, addrspace(5)
39+
call void @llvm.dbg.def(metadata !11, metadata ptr addrspace(5) %0), !dbg !5
4040
call void @llvm.dbg.kill(metadata !11), !dbg !7
4141
unreachable
4242
}

llvm/test/Transforms/InstCombine/alloca-in-non-alloca-as.ll

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33

44
; Gracefully handle the alloca that is not in the alloca AS (=5)
55

6-
target datalayout = "e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-p7:160:256:256:32-p8:128:128-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5-G1-ni:7:8:9"
7-
target triple = "amdgcn-amd-amdhsa"
8-
96
declare void @use(ptr)
107
declare void @use2(ptr, ptr)
118

llvm/test/Transforms/OpenMP/custom_state_machines.ll

Lines changed: 1202 additions & 947 deletions
Large diffs are not rendered by default.

llvm/test/Transforms/OpenMP/custom_state_machines_pre_lto.ll

Lines changed: 1582 additions & 1284 deletions
Large diffs are not rendered by default.

llvm/test/Transforms/OpenMP/spmdization.ll

Lines changed: 782 additions & 1506 deletions
Large diffs are not rendered by default.

llvm/test/Transforms/OpenMP/spmdization_constant_prop.ll

Lines changed: 124 additions & 129 deletions
Large diffs are not rendered by default.

llvm/test/Transforms/OpenMP/spmdization_indirect.ll

Lines changed: 291 additions & 279 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)