1; RUN: opt -S -mtriple=amdgcn--  -amdgpu-replace-lds-use-with-pointer -amdgpu-enable-lds-replace-with-pointer=true < %s | FileCheck %s
2
3; DESCRIPTION:
4;
5; There is one lds global defined here, and this lds is used within a single non-kernel
6; function multiple times, and this non-kernel function is reachable from kernel. Hence
7; pointer takes place. But important note is - store-to/load-from pointer should happen
8; only once irrespective of number of uses.
9;
10
11; Original LDS should exist.
12; CHECK: @lds1 = internal addrspace(3) global [1 x i32] undef, align 4
13@lds1 = internal addrspace(3) global [1 x i32] undef, align 4
14
15; Pointers should be created.
16; CHECK: @lds1.ptr = internal unnamed_addr addrspace(3) global i16 undef, align 2
17
18; Pointer replacement code should be added.
19define internal void @function() {
20; CHECK-LABEL: entry:
21; CHECK:   %0 = load i16, i16 addrspace(3)* @lds1.ptr, align 2
22; CHECK:   %1 = getelementptr i8, i8 addrspace(3)* null, i16 %0
23; CHECK:   %2 = bitcast i8 addrspace(3)* %1 to [1 x i32] addrspace(3)*
24; CHECK:   %gep1 = getelementptr inbounds [1 x i32], [1 x i32] addrspace(3)* %2, i32 0, i32 0
25; CHECK:   %gep2 = getelementptr inbounds [1 x i32], [1 x i32] addrspace(3)* %2, i32 0, i32 0
26; CHECK:   %gep3 = getelementptr inbounds [1 x i32], [1 x i32] addrspace(3)* %2, i32 0, i32 0
27; CHECK:   ret void
28entry:
29  %gep1 = getelementptr inbounds [1 x i32], [1 x i32] addrspace(3)* @lds1, i32 0, i32 0
30  %gep2 = getelementptr inbounds [1 x i32], [1 x i32] addrspace(3)* @lds1, i32 0, i32 0
31  %gep3 = getelementptr inbounds [1 x i32], [1 x i32] addrspace(3)* @lds1, i32 0, i32 0
32  ret void
33}
34
35; Pointer initialization code shoud be added;
36define protected amdgpu_kernel void @kernel() {
37; CHECK-LABEL: entry:
38; CHECK:   %0 = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0)
39; CHECK:   %1 = icmp eq i32 %0, 0
40; CHECK:   br i1 %1, label %2, label %3
41;
42; CHECK-LABEL: 2:
43; CHECK:   store i16 ptrtoint ([1 x i32] addrspace(3)* @lds1 to i16), i16 addrspace(3)* @lds1.ptr, align 2
44; CHECK:   br label %3
45;
46; CHECK-LABEL: 3:
47; CHECK:   call void @llvm.amdgcn.wave.barrier()
48; CHECK:   call void @function()
49; CHECK:   ret void
50entry:
51  call void @function()
52  ret void
53}
54