1 ; RUN: opt -S -mtriple=amdgcn-- -amdgpu-lower-module-lds --amdgpu-lower-module-lds-strategy=module < %s | FileCheck %s
2 ; RUN: opt -S -mtriple=amdgcn-- -passes=amdgpu-lower-module-lds --amdgpu-lower-module-lds-strategy=module < %s | FileCheck %s
4 ; CHECK: %llvm.amdgcn.module.lds.t = type { float, float }
5 ; CHECK: %llvm.amdgcn.kernel.timestwo.lds.t = type { float, float }
7 @a_func = addrspace(3) global float poison, align 4
9 @kern = addrspace(3) global float poison, align 4
11 ; @a_func is only used from a non-kernel function so is rewritten
13 ; @b_both is used from a non-kernel function so is rewritten
15 ; sorted both < func, so @b_both at null and @a_func at 4
16 @b_both = addrspace(3) global float poison, align 4
18 ; CHECK: @llvm.amdgcn.module.lds = internal addrspace(3) global %llvm.amdgcn.module.lds.t poison, align 4
19 ; CHECK: @llvm.amdgcn.kernel.timestwo.lds = internal addrspace(3) global %llvm.amdgcn.kernel.timestwo.lds.t poison, align 4
21 ; CHECK-LABEL: @get_func()
22 ; CHECK: %0 = addrspacecast ptr addrspace(3) @llvm.amdgcn.module.lds to ptr
23 ; CHECK: %1 = ptrtoint ptr %0 to i64
24 ; CHECK: %2 = addrspacecast ptr addrspace(3) @llvm.amdgcn.module.lds to ptr
25 ; CHECK: %3 = ptrtoint ptr %2 to i64
26 ; CHECK: %4 = add i64 %1, %3
27 ; CHECK: %5 = inttoptr i64 %4 to ptr
28 ; CHECK: %6 = load i32, ptr %5, align 4
30 define i32 @get_func() local_unnamed_addr #0 {
32 %0 = load i32, ptr inttoptr (i64 add (i64 ptrtoint (ptr addrspacecast (ptr addrspace(3) @a_func to ptr) to i64), i64 ptrtoint (ptr addrspacecast (ptr addrspace(3) @a_func to ptr) to i64)) to ptr), align 4
36 ; CHECK-LABEL: @set_func(i32 %x)
37 ; CHECK: %0 = addrspacecast ptr addrspace(3) getelementptr inbounds (%llvm.amdgcn.module.lds.t, ptr addrspace(3) @llvm.amdgcn.module.lds, i32 0, i32 1) to ptr
38 ; CHECK: %1 = ptrtoint ptr %0 to i64
39 ; CHECK: %2 = addrspacecast ptr addrspace(3) getelementptr inbounds (%llvm.amdgcn.module.lds.t, ptr addrspace(3) @llvm.amdgcn.module.lds, i32 0, i32 1) to ptr
40 ; CHECK: %3 = ptrtoint ptr %2 to i64
41 ; CHECK: %4 = add i64 %1, %3
42 ; CHECK: %5 = inttoptr i64 %4 to ptr
43 ; CHECK: store i32 %x, ptr %5, align 4
45 define void @set_func(i32 %x) {
47 store i32 %x, ptr inttoptr (i64 add (i64 ptrtoint (ptr addrspacecast (ptr addrspace(3) @b_both to ptr) to i64), i64 ptrtoint (ptr addrspacecast (ptr addrspace(3) @b_both to ptr) to i64)) to ptr), align 4
51 ; CHECK-LABEL: @timestwo() #0
52 ; CHECK-NOT: call void @llvm.donothing()
54 ; CHECK: %1 = addrspacecast ptr addrspace(3) @llvm.amdgcn.kernel.timestwo.lds to ptr
55 ; CHECK: %2 = ptrtoint ptr %1 to i64
56 ; CHECK: %3 = addrspacecast ptr addrspace(3) getelementptr inbounds (%llvm.amdgcn.kernel.timestwo.lds.t, ptr addrspace(3) @llvm.amdgcn.kernel.timestwo.lds, i32 0, i32 1) to ptr
57 ; CHECK: %4 = ptrtoint ptr %3 to i64
58 ; CHECK: %5 = add i64 %2, %4
59 ; CHECK: %6 = inttoptr i64 %5 to ptr
60 ; CHECK: %ld = load i32, ptr %6, align 4
61 ; CHECK: %mul = mul i32 %ld, 2
62 ; CHECK: %7 = addrspacecast ptr addrspace(3) getelementptr inbounds (%llvm.amdgcn.kernel.timestwo.lds.t, ptr addrspace(3) @llvm.amdgcn.kernel.timestwo.lds, i32 0, i32 1) to ptr
63 ; CHECK: %8 = ptrtoint ptr %7 to i64
64 ; CHECK: %9 = addrspacecast ptr addrspace(3) @llvm.amdgcn.kernel.timestwo.lds to ptr
65 ; CHECK: %10 = ptrtoint ptr %9 to i64
66 ; CHECK: %11 = add i64 %8, %10
67 ; CHECK: %12 = inttoptr i64 %11 to ptr
68 ; CHECK: store i32 %mul, ptr %12, align 4
70 define amdgpu_kernel void @timestwo() {
71 %ld = load i32, ptr inttoptr (i64 add (i64 ptrtoint (ptr addrspacecast (ptr addrspace(3) @b_both to ptr) to i64), i64 ptrtoint (ptr addrspacecast (ptr addrspace(3) @kern to ptr) to i64)) to ptr), align 4
73 store i32 %mul, ptr inttoptr (i64 add (i64 ptrtoint (ptr addrspacecast (ptr addrspace(3) @kern to ptr) to i64), i64 ptrtoint (ptr addrspacecast (ptr addrspace(3) @b_both to ptr) to i64)) to ptr), align 4
77 ; CHECK-LABEL: @through_functions() #0
78 define amdgpu_kernel void @through_functions() {
79 %ld = call i32 @get_func()
81 call void @set_func(i32 %mul)
85 ; CHECK: attributes #0 = { "amdgpu-lds-size"="8" }