1; RUN: opt -O1 -S -mtriple=amdgcn-unknown-amdhsa -amdgpu-internalize-symbols < %s | FileCheck -check-prefix=ALL -check-prefix=OPT %s
2; RUN: opt -O0 -S -mtriple=amdgcn-unknown-amdhsa -amdgpu-internalize-symbols < %s | FileCheck -check-prefix=ALL -check-prefix=OPTNONE %s
3
4; OPT-NOT: gvar_unused
5; OPTNONE: gvar_unused
6@gvar_unused = addrspace(1) global i32 undef, align 4
7
8; ALL: gvar_used
9@gvar_used = addrspace(1) global i32 undef, align 4
10
11; OPT: define internal fastcc void @func_used_noinline(
12; OPT-NONE: define fastcc void @func_used_noinline(
13define fastcc void @func_used_noinline(i32 addrspace(1)* %out, i32 %tid) #1 {
14entry:
15  store volatile i32 %tid, i32 addrspace(1)* %out
16  ret void
17}
18
19; OPTNONE: define fastcc void @func_used_alwaysinline(
20; OPT-NOT: @func_used_alwaysinline
21define fastcc void @func_used_alwaysinline(i32 addrspace(1)* %out, i32 %tid) #2 {
22entry:
23  store volatile i32 %tid, i32 addrspace(1)* %out
24  ret void
25}
26
27; OPTNONE: define void @func_unused(
28; OPT-NOT: @func_unused
29define void @func_unused(i32 addrspace(1)* %out, i32 %tid) #1 {
30entry:
31  store volatile i32 %tid, i32 addrspace(1)* %out
32  ret void
33}
34
35; ALL: define amdgpu_kernel void @kernel_unused(
36define amdgpu_kernel void @kernel_unused(i32 addrspace(1)* %out) #1 {
37entry:
38  store volatile i32 1, i32 addrspace(1)* %out
39  ret void
40}
41
42; ALL: define amdgpu_kernel void @main_kernel()
43; ALL: tail call i32 @llvm.amdgcn.workitem.id.x
44; ALL: tail call fastcc void @func_used_noinline
45; ALL: store volatile
46; ALL: ret void
47define amdgpu_kernel void @main_kernel() {
48entry:
49  %tid = tail call i32 @llvm.amdgcn.workitem.id.x()
50  tail call fastcc void @func_used_noinline(i32 addrspace(1)* @gvar_used, i32 %tid)
51  tail call fastcc void @func_used_alwaysinline(i32 addrspace(1)* @gvar_used, i32 %tid)
52  ret void
53}
54
55declare i32 @llvm.amdgcn.workitem.id.x() #0
56
57attributes #0 = { nounwind readnone }
58attributes #1 = { noinline nounwind }
59attributes #2 = { alwaysinline nounwind }
60