1 ; RUN: opt -S -mtriple=amdgcn-- -amdgpu-replace-lds-use-with-pointer -amdgpu-enable-lds-replace-with-pointer=true < %s | FileCheck %s
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.
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
15 ; Pointers should be created.
16 ; CHECK: @lds1.ptr = internal unnamed_addr addrspace(3) global i16 undef, align 2
18 ; Pointer replacement code should be added.
19 define internal void @function() {
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
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
35 ; Pointer initialization code shoud be added;
36 define protected amdgpu_kernel void @kernel() {
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
43 ; CHECK: store i16 ptrtoint ([1 x i32] addrspace(3)* @lds1 to i16), i16 addrspace(3)* @lds1.ptr, align 2
47 ; CHECK: call void @llvm.amdgcn.wave.barrier()
48 ; CHECK: call void @function()