1 ; RUN: llc -mtriple=amdgcn-amd-amdhsa -mattr=-code-object-v3 -enable-ipra=0 -verify-machineinstrs < %s | FileCheck -check-prefixes=GCN,CI %s
2 ; RUN: llc -mtriple=amdgcn-amd-amdhsa -mattr=-code-object-v3 -mcpu=fiji -enable-ipra=0 -verify-machineinstrs < %s | FileCheck -check-prefixes=GCN,VI,VI-NOBUG %s
3 ; RUN: llc -mtriple=amdgcn-amd-amdhsa -mattr=-code-object-v3 -mcpu=iceland -enable-ipra=0 -verify-machineinstrs < %s | FileCheck -check-prefixes=GCN,VI,VI-BUG %s
5 ; Make sure to run a GPU with the SGPR allocation bug.
7 ; GCN-LABEL: {{^}}use_vcc:
10 define void @use_vcc() #1 {
11 call void asm sideeffect "", "~{vcc}" () #0
15 ; GCN-LABEL: {{^}}indirect_use_vcc:
16 ; GCN: v_writelane_b32 v32, s34, 2
17 ; GCN: v_writelane_b32 v32, s30, 0
18 ; GCN: v_writelane_b32 v32, s31, 1
20 ; GCN: v_readlane_b32 s4, v32, 0
21 ; GCN: v_readlane_b32 s5, v32, 1
22 ; GCN: v_readlane_b32 s34, v32, 2
25 define void @indirect_use_vcc() #1 {
30 ; GCN-LABEL: {{^}}indirect_2level_use_vcc_kernel:
31 ; GCN: is_dynamic_callstack = 0
33 ; VI-NOBUG: ; NumSgprs: 41
34 ; VI-BUG: ; NumSgprs: 96
36 define amdgpu_kernel void @indirect_2level_use_vcc_kernel(i32 addrspace(1)* %out) #0 {
37 call void @indirect_use_vcc()
41 ; GCN-LABEL: {{^}}use_flat_scratch:
45 define void @use_flat_scratch() #1 {
46 call void asm sideeffect "", "~{flat_scratch}" () #0
50 ; GCN-LABEL: {{^}}indirect_use_flat_scratch:
54 define void @indirect_use_flat_scratch() #1 {
55 call void @use_flat_scratch()
59 ; GCN-LABEL: {{^}}indirect_2level_use_flat_scratch_kernel:
60 ; GCN: is_dynamic_callstack = 0
62 ; VI-NOBUG: ; NumSgprs: 41
63 ; VI-BUG: ; NumSgprs: 96
65 define amdgpu_kernel void @indirect_2level_use_flat_scratch_kernel(i32 addrspace(1)* %out) #0 {
66 call void @indirect_use_flat_scratch()
70 ; GCN-LABEL: {{^}}use_10_vgpr:
72 define void @use_10_vgpr() #1 {
73 call void asm sideeffect "", "~{v0},~{v1},~{v2},~{v3},~{v4}"() #0
74 call void asm sideeffect "", "~{v5},~{v6},~{v7},~{v8},~{v9}"() #0
78 ; GCN-LABEL: {{^}}indirect_use_10_vgpr:
80 define void @indirect_use_10_vgpr() #0 {
81 call void @use_10_vgpr()
85 ; GCN-LABEL: {{^}}indirect_2_level_use_10_vgpr:
86 ; GCN: is_dynamic_callstack = 0
88 define amdgpu_kernel void @indirect_2_level_use_10_vgpr() #0 {
89 call void @indirect_use_10_vgpr()
93 ; GCN-LABEL: {{^}}use_40_vgpr:
95 define void @use_40_vgpr() #1 {
96 call void asm sideeffect "", "~{v39}"() #0
100 ; GCN-LABEL: {{^}}indirect_use_40_vgpr:
101 ; GCN: ; NumVgprs: 40
102 define void @indirect_use_40_vgpr() #0 {
103 call void @use_40_vgpr()
107 ; GCN-LABEL: {{^}}use_80_sgpr:
108 ; GCN: ; NumSgprs: 80
109 define void @use_80_sgpr() #1 {
110 call void asm sideeffect "", "~{s79}"() #0
114 ; GCN-LABEL: {{^}}indirect_use_80_sgpr:
115 ; GCN: ; NumSgprs: 82
116 define void @indirect_use_80_sgpr() #1 {
117 call void @use_80_sgpr()
121 ; GCN-LABEL: {{^}}indirect_2_level_use_80_sgpr:
122 ; GCN: is_dynamic_callstack = 0
124 ; VI-NOBUG: ; NumSgprs: 86
125 ; VI-BUG: ; NumSgprs: 96
126 define amdgpu_kernel void @indirect_2_level_use_80_sgpr() #0 {
127 call void @indirect_use_80_sgpr()
132 ; GCN-LABEL: {{^}}use_stack0:
133 ; GCN: ScratchSize: 2052
134 define void @use_stack0() #1 {
135 %alloca = alloca [512 x i32], align 4, addrspace(5)
136 call void asm sideeffect "; use $0", "v"([512 x i32] addrspace(5)* %alloca) #0
140 ; GCN-LABEL: {{^}}use_stack1:
141 ; GCN: ScratchSize: 404
142 define void @use_stack1() #1 {
143 %alloca = alloca [100 x i32], align 4, addrspace(5)
144 call void asm sideeffect "; use $0", "v"([100 x i32] addrspace(5)* %alloca) #0
148 ; GCN-LABEL: {{^}}indirect_use_stack:
149 ; GCN: ScratchSize: 2132
150 define void @indirect_use_stack() #1 {
151 %alloca = alloca [16 x i32], align 4, addrspace(5)
152 call void asm sideeffect "; use $0", "v"([16 x i32] addrspace(5)* %alloca) #0
153 call void @use_stack0()
157 ; GCN-LABEL: {{^}}indirect_2_level_use_stack:
158 ; GCN: is_dynamic_callstack = 0
159 ; GCN: ScratchSize: 2132
160 define amdgpu_kernel void @indirect_2_level_use_stack() #0 {
161 call void @indirect_use_stack()
166 ; Should be maximum of callee usage
167 ; GCN-LABEL: {{^}}multi_call_use_use_stack:
168 ; GCN: is_dynamic_callstack = 0
169 ; GCN: ScratchSize: 2052
170 define amdgpu_kernel void @multi_call_use_use_stack() #0 {
171 call void @use_stack0()
172 call void @use_stack1()
177 declare void @external() #0
179 ; GCN-LABEL: {{^}}usage_external:
180 ; GCN: is_dynamic_callstack = 1
183 ; GCN: ScratchSize: 16384
184 define amdgpu_kernel void @usage_external() #0 {
185 call void @external()
189 declare void @external_recurse() #2
191 ; GCN-LABEL: {{^}}usage_external_recurse:
192 ; GCN: is_dynamic_callstack = 1
195 ; GCN: ScratchSize: 16384
196 define amdgpu_kernel void @usage_external_recurse() #0 {
197 call void @external_recurse()
201 ; GCN-LABEL: {{^}}direct_recursion_use_stack:
202 ; GCN: ScratchSize: 2064
203 define void @direct_recursion_use_stack(i32 %val) #2 {
204 %alloca = alloca [512 x i32], align 4, addrspace(5)
205 call void asm sideeffect "; use $0", "v"([512 x i32] addrspace(5)* %alloca) #0
206 %cmp = icmp eq i32 %val, 0
207 br i1 %cmp, label %ret, label %call
210 %val.sub1 = sub i32 %val, 1
211 call void @direct_recursion_use_stack(i32 %val.sub1)
218 ; GCN-LABEL: {{^}}usage_direct_recursion:
220 ; GCN: is_dynamic_callstack = 1
221 ; GCN: workitem_private_segment_byte_size = 2064
222 define amdgpu_kernel void @usage_direct_recursion(i32 %n) #0 {
223 call void @direct_recursion_use_stack(i32 %n)
227 ; Make sure there's no assert when a sgpr96 is used.
228 ; GCN-LABEL: {{^}}count_use_sgpr96_external_call
229 ; GCN: ; sgpr96 s[{{[0-9]+}}:{{[0-9]+}}]
231 ; VI-NOBUG: NumSgprs: 48
232 ; VI-BUG: NumSgprs: 96
234 define amdgpu_kernel void @count_use_sgpr96_external_call() {
236 tail call void asm sideeffect "; sgpr96 $0", "s"(<3 x i32> <i32 10, i32 11, i32 12>) #1
237 call void @external()
241 attributes #0 = { nounwind noinline norecurse }
242 attributes #1 = { nounwind noinline norecurse }
243 attributes #2 = { nounwind noinline }