1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2; RUN: llc -march=amdgcn -mcpu=verde -verify-machineinstrs < %s | FileCheck %s -check-prefixes=GCN,SI
3; RUN: llc -march=amdgcn -mcpu=bonaire -verify-machineinstrs < %s | FileCheck %s -check-prefixes=GCN,CI
4
5@local_memory.local_mem = internal unnamed_addr addrspace(3) global [128 x i32] undef, align 4
6
7define amdgpu_kernel void @local_memory(i32 addrspace(1)* %out) #0 {
8; GCN-LABEL: local_memory:
9; GCN:       ; %bb.0: ; %entry
10; GCN-NEXT:    v_lshlrev_b32_e32 v1, 2, v0
11; GCN-NEXT:    s_mov_b32 m0, -1
12; GCN-NEXT:    ds_write_b32 v1, v0
13; GCN-NEXT:    v_add_i32_e32 v0, vcc, 1, v0
14; GCN-NEXT:    v_cmp_ne_u32_e32 vcc, 16, v0
15; GCN-NEXT:    v_cndmask_b32_e32 v0, 0, v0, vcc
16; GCN-NEXT:    v_lshlrev_b32_e32 v0, 2, v0
17; GCN-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0x9
18; GCN-NEXT:    s_waitcnt lgkmcnt(0)
19; GCN-NEXT:    s_barrier
20; GCN-NEXT:    ds_read_b32 v0, v0
21; GCN-NEXT:    s_mov_b32 s2, 0
22; GCN-NEXT:    s_mov_b32 s3, 0xf000
23; GCN-NEXT:    v_mov_b32_e32 v2, 0
24; GCN-NEXT:    s_waitcnt lgkmcnt(0)
25; GCN-NEXT:    buffer_store_dword v0, v[1:2], s[0:3], 0 addr64
26; GCN-NEXT:    s_endpgm
27entry:
28  %y.i = call i32 @llvm.amdgcn.workitem.id.x() #1
29  %arrayidx = getelementptr inbounds [128 x i32], [128 x i32] addrspace(3)* @local_memory.local_mem, i32 0, i32 %y.i
30  store i32 %y.i, i32 addrspace(3)* %arrayidx, align 4
31  %add = add nsw i32 %y.i, 1
32  %cmp = icmp eq i32 %add, 16
33  %.add = select i1 %cmp, i32 0, i32 %add
34  call void @llvm.amdgcn.s.barrier()
35  %arrayidx1 = getelementptr inbounds [128 x i32], [128 x i32] addrspace(3)* @local_memory.local_mem, i32 0, i32 %.add
36  %tmp = load i32, i32 addrspace(3)* %arrayidx1, align 4
37  %arrayidx2 = getelementptr inbounds i32, i32 addrspace(1)* %out, i32 %y.i
38  store i32 %tmp, i32 addrspace(1)* %arrayidx2, align 4
39  ret void
40}
41
42@local_memory_two_objects.local_mem0 = internal unnamed_addr addrspace(3) global [4 x i32] undef, align 4
43@local_memory_two_objects.local_mem1 = internal unnamed_addr addrspace(3) global [4 x i32] undef, align 4
44
45; Check that the LDS size emitted correctly
46define amdgpu_kernel void @local_memory_two_objects(i32 addrspace(1)* %out) #0 {
47; SI-LABEL: local_memory_two_objects:
48; SI:       ; %bb.0: ; %entry
49; SI-NEXT:    v_lshlrev_b32_e32 v1, 2, v0
50; SI-NEXT:    v_lshlrev_b32_e32 v2, 1, v0
51; SI-NEXT:    s_mov_b32 m0, -1
52; SI-NEXT:    ds_write2_b32 v1, v0, v2 offset1:4
53; SI-NEXT:    v_sub_i32_e32 v0, vcc, 12, v1
54; SI-NEXT:    v_sub_i32_e32 v2, vcc, 16, v1
55; SI-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0x9
56; SI-NEXT:    s_waitcnt lgkmcnt(0)
57; SI-NEXT:    s_barrier
58; SI-NEXT:    v_add_i32_e32 v2, vcc, 12, v2
59; SI-NEXT:    ds_read_b32 v0, v0
60; SI-NEXT:    ds_read_b32 v3, v2
61; SI-NEXT:    s_mov_b32 s3, 0xf000
62; SI-NEXT:    s_mov_b32 s2, 0
63; SI-NEXT:    v_mov_b32_e32 v2, 0
64; SI-NEXT:    s_waitcnt lgkmcnt(1)
65; SI-NEXT:    buffer_store_dword v0, v[1:2], s[0:3], 0 addr64
66; SI-NEXT:    s_waitcnt lgkmcnt(0)
67; SI-NEXT:    buffer_store_dword v3, v[1:2], s[0:3], 0 addr64 offset:16
68; SI-NEXT:    s_endpgm
69;
70; CI-LABEL: local_memory_two_objects:
71; CI:       ; %bb.0: ; %entry
72; CI-NEXT:    v_lshlrev_b32_e32 v1, 2, v0
73; CI-NEXT:    v_lshlrev_b32_e32 v2, 1, v0
74; CI-NEXT:    s_mov_b32 m0, -1
75; CI-NEXT:    ds_write2_b32 v1, v0, v2 offset1:4
76; CI-NEXT:    v_sub_i32_e32 v0, vcc, 0, v1
77; CI-NEXT:    s_load_dwordx2 s[0:1], s[0:1], 0x9
78; CI-NEXT:    s_waitcnt lgkmcnt(0)
79; CI-NEXT:    s_barrier
80; CI-NEXT:    v_sub_i32_e32 v2, vcc, 16, v1
81; CI-NEXT:    ds_read_b32 v0, v0 offset:12
82; CI-NEXT:    ds_read_b32 v3, v2 offset:12
83; CI-NEXT:    s_mov_b32 s3, 0xf000
84; CI-NEXT:    s_mov_b32 s2, 0
85; CI-NEXT:    v_mov_b32_e32 v2, 0
86; CI-NEXT:    s_waitcnt lgkmcnt(1)
87; CI-NEXT:    buffer_store_dword v0, v[1:2], s[0:3], 0 addr64
88; CI-NEXT:    s_waitcnt lgkmcnt(0)
89; CI-NEXT:    buffer_store_dword v3, v[1:2], s[0:3], 0 addr64 offset:16
90; CI-NEXT:    s_endpgm
91entry:
92  %x.i = call i32 @llvm.amdgcn.workitem.id.x()
93  %arrayidx = getelementptr inbounds [4 x i32], [4 x i32] addrspace(3)* @local_memory_two_objects.local_mem0, i32 0, i32 %x.i
94  store i32 %x.i, i32 addrspace(3)* %arrayidx, align 4
95  %mul = shl nsw i32 %x.i, 1
96  %arrayidx1 = getelementptr inbounds [4 x i32], [4 x i32] addrspace(3)* @local_memory_two_objects.local_mem1, i32 0, i32 %x.i
97  store i32 %mul, i32 addrspace(3)* %arrayidx1, align 4
98  %sub = sub nsw i32 3, %x.i
99  call void @llvm.amdgcn.s.barrier()
100  %arrayidx2 = getelementptr inbounds [4 x i32], [4 x i32] addrspace(3)* @local_memory_two_objects.local_mem0, i32 0, i32 %sub
101  %tmp = load i32, i32 addrspace(3)* %arrayidx2, align 4
102  %arrayidx3 = getelementptr inbounds i32, i32 addrspace(1)* %out, i32 %x.i
103  store i32 %tmp, i32 addrspace(1)* %arrayidx3, align 4
104  %arrayidx4 = getelementptr inbounds [4 x i32], [4 x i32] addrspace(3)* @local_memory_two_objects.local_mem1, i32 0, i32 %sub
105  %tmp1 = load i32, i32 addrspace(3)* %arrayidx4, align 4
106  %add = add nsw i32 %x.i, 4
107  %arrayidx5 = getelementptr inbounds i32, i32 addrspace(1)* %out, i32 %add
108  store i32 %tmp1, i32 addrspace(1)* %arrayidx5, align 4
109  ret void
110}
111
112declare i32 @llvm.amdgcn.workitem.id.x() #1
113declare void @llvm.amdgcn.s.barrier() #2
114
115attributes #0 = { nounwind }
116attributes #1 = { nounwind readnone }
117attributes #2 = { convergent nounwind }
118