1 ; RUN: llc -mtriple=amdgcn -mcpu=tahiti -verify-machineinstrs < %s | FileCheck -check-prefixes=CHECK,NOHSA %s
2 ; RUN: llc -mtriple=amdgcn--amdhsa -mcpu=kaveri -verify-machineinstrs < %s | FileCheck -check-prefixes=CHECK,HSA %s
3 ; RUN: llc -mtriple=amdgcn--amdhsa -mcpu=fiji -verify-machineinstrs < %s | FileCheck -check-prefixes=CHECK,HSA %s
5 ; RUN: llc -global-isel -mtriple=amdgcn -mcpu=tahiti -verify-machineinstrs < %s | FileCheck -check-prefixes=CHECK,NOHSA %s
6 ; RUN: llc -global-isel -mtriple=amdgcn--amdhsa -mcpu=kaveri -verify-machineinstrs < %s | FileCheck -check-prefixes=CHECK,HSA %s
7 ; RUN: llc -global-isel -mtriple=amdgcn--amdhsa -mcpu=fiji -verify-machineinstrs < %s | FileCheck -check-prefixes=CHECK,HSA %s
9 @lds0 = addrspace(3) global [512 x float] undef, align 4
10 @lds1 = addrspace(3) global [256 x float] undef, align 4
12 @large = addrspace(3) global [4096 x i32] undef, align 4
14 ; CHECK-LABEL: {{^}}groupstaticsize_test0:
15 ; NOHSA: v_mov_b32_e32 v{{[0-9]+}}, llvm.amdgcn.groupstaticsize@abs32@lo
16 ; HSA: v_mov_b32_e32 v{{[0-9]+}}, 0x800{{$}}
17 define amdgpu_kernel void @groupstaticsize_test0(ptr addrspace(1) %out, ptr addrspace(1) %lds_size) #0 {
18 %tid.x = tail call i32 @llvm.amdgcn.workitem.id.x() #1
19 %idx.0 = add nsw i32 %tid.x, 64
20 %static_lds_size = call i32 @llvm.amdgcn.groupstaticsize() #1
21 store i32 %static_lds_size, ptr addrspace(1) %lds_size, align 4
22 %arrayidx0 = getelementptr inbounds [512 x float], ptr addrspace(3) @lds0, i32 0, i32 %idx.0
23 %val0 = load float, ptr addrspace(3) %arrayidx0, align 4
24 store float %val0, ptr addrspace(1) %out, align 4
29 ; CHECK-LABEL: {{^}}groupstaticsize_test1:
30 ; NOHSA: v_mov_b32_e32 v{{[0-9]+}}, llvm.amdgcn.groupstaticsize@abs32@lo
31 ; HSA: v_mov_b32_e32 v{{[0-9]+}}, 0xc00{{$}}
32 define amdgpu_kernel void @groupstaticsize_test1(ptr addrspace(1) %out, i32 %cond, ptr addrspace(1) %lds_size) {
34 %static_lds_size = call i32 @llvm.amdgcn.groupstaticsize() #1
35 store i32 %static_lds_size, ptr addrspace(1) %lds_size, align 4
36 %tid.x = tail call i32 @llvm.amdgcn.workitem.id.x() #1
37 %idx.0 = add nsw i32 %tid.x, 64
38 %tmp = icmp eq i32 %cond, 0
39 br i1 %tmp, label %if, label %else
42 %arrayidx0 = getelementptr inbounds [512 x float], ptr addrspace(3) @lds0, i32 0, i32 %idx.0
43 %val0 = load float, ptr addrspace(3) %arrayidx0, align 4
44 store float %val0, ptr addrspace(1) %out, align 4
47 else: ; preds = %entry
48 %arrayidx1 = getelementptr inbounds [256 x float], ptr addrspace(3) @lds1, i32 0, i32 %idx.0
49 %val1 = load float, ptr addrspace(3) %arrayidx1, align 4
50 store float %val1, ptr addrspace(1) %out, align 4
53 endif: ; preds = %else, %if
57 ; Exceeds 16-bit simm limit of s_movk_i32
58 ; CHECK-LABEL: {{^}}large_groupstaticsize:
59 ; NOHSA: v_mov_b32_e32 v{{[0-9]+}}, llvm.amdgcn.groupstaticsize@abs32@lo
60 ; HSA: v_mov_b32_e32 [[REG:v[0-9]+]], 0x4000{{$}}
61 define amdgpu_kernel void @large_groupstaticsize(ptr addrspace(1) %size, i32 %idx) #0 {
62 %gep = getelementptr inbounds [4096 x i32], ptr addrspace(3) @large, i32 0, i32 %idx
63 store volatile i32 0, ptr addrspace(3) %gep
64 %static_lds_size = call i32 @llvm.amdgcn.groupstaticsize()
65 store i32 %static_lds_size, ptr addrspace(1) %size
69 declare i32 @llvm.amdgcn.groupstaticsize() #1
70 declare i32 @llvm.amdgcn.workitem.id.x() #1
72 attributes #0 = { nounwind }
73 attributes #1 = { nounwind readnone }