1 ; RUN: opt -S -mtriple=amdgcn-- -amdgpu-replace-lds-use-with-pointer -amdgpu-enable-lds-replace-with-pointer=true < %s | FileCheck %s
5 ; The lds global @lds_used_within_func is used within non-kernel function @func_uses_lds
6 ; which is *indirectly* recheable from kernel @kernel_reaches_lds, hence pointer replacement
7 ; takes place for @lds_used_within_func.
9 ; Original LDS should exit.
10 ; CHECK: @lds_used_within_func = internal addrspace(3) global [4 x i32] undef, align 4
11 @lds_used_within_func = internal addrspace(3) global [4 x i32] undef, align 4
13 ; Function pointer should exist as it is.
14 ; CHECK: @ptr_to_func = internal local_unnamed_addr externally_initialized global void ()* @func_uses_lds, align 8
15 @ptr_to_func = internal local_unnamed_addr externally_initialized global void ()* @func_uses_lds, align 8
17 ; Pointer should be created.
18 ; CHECK: @lds_used_within_func.ptr = internal unnamed_addr addrspace(3) global i16 undef, align 2
20 ; Pointer replacement code should be added.
21 define internal void @func_uses_lds() {
23 ; CHECK: %0 = load i16, i16 addrspace(3)* @lds_used_within_func.ptr, align 2
24 ; CHECK: %1 = getelementptr i8, i8 addrspace(3)* null, i16 %0
25 ; CHECK: %2 = bitcast i8 addrspace(3)* %1 to [4 x i32] addrspace(3)*
26 ; CHECK: %gep = getelementptr inbounds [4 x i32], [4 x i32] addrspace(3)* %2, i32 0, i32 0
29 %gep = getelementptr inbounds [4 x i32], [4 x i32] addrspace(3)* @lds_used_within_func, i32 0, i32 0
34 define internal void @func_does_not_use_lds_3() {
36 ; CHECK: %fptr = load void ()*, void ()** @ptr_to_func, align 8
37 ; CHECK: call void %fptr()
40 %fptr = load void ()*, void ()** @ptr_to_func, align 8
46 define internal void @func_does_not_use_lds_2() {
48 ; CHECK: %fptr = load void ()*, void ()** @ptr_to_func, align 8
49 ; CHECK: call void %fptr()
52 %fptr = load void ()*, void ()** @ptr_to_func, align 8
58 define internal void @func_does_not_use_lds_1() {
60 ; CHECK: call void @func_does_not_use_lds_2()
61 ; CHECK: call void @func_does_not_use_lds_3()
64 call void @func_does_not_use_lds_2()
65 call void @func_does_not_use_lds_3()
69 ; Pointer initialization code shoud be added
70 define protected amdgpu_kernel void @kernel_reaches_lds() {
72 ; CHECK: %0 = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0)
73 ; CHECK: %1 = icmp eq i32 %0, 0
74 ; CHECK: br i1 %1, label %2, label %3
77 ; CHECK: store i16 ptrtoint ([4 x i32] addrspace(3)* @lds_used_within_func to i16), i16 addrspace(3)* @lds_used_within_func.ptr, align 2
81 ; CHECK: call void @llvm.amdgcn.wave.barrier()
82 ; CHECK: call void @func_does_not_use_lds_1()
85 call void @func_does_not_use_lds_1()
89 ; No change here since this kernel does not reach @func_uses_lds which uses lds.
90 define protected amdgpu_kernel void @kernel_does_not_reach_lds() {