1 ; RUN: opt -S -mtriple=amdgcn-- -amdgpu-replace-lds-use-with-pointer -amdgpu-enable-lds-replace-with-pointer=true < %s | FileCheck %s
5 ; There are three lds globals defined here, and these three lds are used within a single
6 ; non-kernel function, and this non-kernel function is reachable from kernel. Hence pointer
7 ; replacement is required for all three lds globals.
10 ; Original LDS should exist.
11 ; CHECK: @lds1 = internal addrspace(3) global [1 x i32] undef, align 4
12 ; CHECK: @lds2 = internal addrspace(3) global [2 x i32] undef, align 4
13 ; CHECK: @lds3 = internal addrspace(3) global [3 x i32] undef, align 4
14 @lds1 = internal addrspace(3) global [1 x i32] undef, align 4
15 @lds2 = internal addrspace(3) global [2 x i32] undef, align 4
16 @lds3 = internal addrspace(3) global [3 x i32] undef, align 4
18 ; Pointers should be created.
19 ; CHECK: @lds1.ptr = internal unnamed_addr addrspace(3) global i16 undef, align 2
20 ; CHECK: @lds2.ptr = internal unnamed_addr addrspace(3) global i16 undef, align 2
21 ; CHECK: @lds3.ptr = internal unnamed_addr addrspace(3) global i16 undef, align 2
23 ; Pointer replacement code should be added.
24 define internal void @function() {
26 ; CHECK: %0 = load i16, i16 addrspace(3)* @lds3.ptr, align 2
27 ; CHECK: %1 = getelementptr i8, i8 addrspace(3)* null, i16 %0
28 ; CHECK: %2 = bitcast i8 addrspace(3)* %1 to [3 x i32] addrspace(3)*
29 ; CHECK: %3 = load i16, i16 addrspace(3)* @lds2.ptr, align 2
30 ; CHECK: %4 = getelementptr i8, i8 addrspace(3)* null, i16 %3
31 ; CHECK: %5 = bitcast i8 addrspace(3)* %4 to [2 x i32] addrspace(3)*
32 ; CHECK: %6 = load i16, i16 addrspace(3)* @lds1.ptr, align 2
33 ; CHECK: %7 = getelementptr i8, i8 addrspace(3)* null, i16 %6
34 ; CHECK: %8 = bitcast i8 addrspace(3)* %7 to [1 x i32] addrspace(3)*
35 ; CHECK: %gep1 = getelementptr inbounds [1 x i32], [1 x i32] addrspace(3)* %8, i32 0, i32 0
36 ; CHECK: %gep2 = getelementptr inbounds [2 x i32], [2 x i32] addrspace(3)* %5, i32 0, i32 0
37 ; CHECK: %gep3 = getelementptr inbounds [3 x i32], [3 x i32] addrspace(3)* %2, i32 0, i32 0
40 %gep1 = getelementptr inbounds [1 x i32], [1 x i32] addrspace(3)* @lds1, i32 0, i32 0
41 %gep2 = getelementptr inbounds [2 x i32], [2 x i32] addrspace(3)* @lds2, i32 0, i32 0
42 %gep3 = getelementptr inbounds [3 x i32], [3 x i32] addrspace(3)* @lds3, i32 0, i32 0
46 ; Pointer initialization code shoud be added;
47 define protected amdgpu_kernel void @kernel() {
49 ; CHECK: %0 = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0)
50 ; CHECK: %1 = icmp eq i32 %0, 0
51 ; CHECK: br i1 %1, label %2, label %3
54 ; CHECK: store i16 ptrtoint ([3 x i32] addrspace(3)* @lds3 to i16), i16 addrspace(3)* @lds3.ptr, align 2
55 ; CHECK: store i16 ptrtoint ([2 x i32] addrspace(3)* @lds2 to i16), i16 addrspace(3)* @lds2.ptr, align 2
56 ; CHECK: store i16 ptrtoint ([1 x i32] addrspace(3)* @lds1 to i16), i16 addrspace(3)* @lds1.ptr, align 2
60 ; CHECK: call void @llvm.amdgcn.wave.barrier()
61 ; CHECK: call void @function()