1 ; RUN: llc -mtriple=amdgcn--amdhsa -mcpu=gfx900 -amdgpu-ir-lower-kernel-arguments=0 -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GCN,HSA-VI,FUNC %s
3 ; Repeat of some problematic tests in kernel-args.ll, with the IR
4 ; argument lowering pass disabled. Struct padding needs to be
5 ; accounted for, as well as legalization of types changing offsets.
7 ; FUNC-LABEL: {{^}}i1_arg:
12 ; HSA-VI: .amdhsa_kernarg_size 12
13 define amdgpu_kernel void @i1_arg(ptr addrspace(1) %out, i1 %x) #0 {
14 store i1 %x, ptr addrspace(1) %out, align 1
18 ; FUNC-LABEL: {{^}}v3i8_arg:
20 ; HSA-VI: s_load_dword s{{[0-9]+}}, s[8:9], 0x8
21 ; HSA-VI: s_load_dwordx2 s{{\[[0-9]+:[0-9]+\]}}, s[8:9], 0x0
23 ; HSA-VI: .amdhsa_kernarg_size 12
24 define amdgpu_kernel void @v3i8_arg(ptr addrspace(1) nocapture %out, <3 x i8> %in) #0 {
26 store <3 x i8> %in, ptr addrspace(1) %out, align 4
30 ; FUNC-LABEL: {{^}}i65_arg:
31 ; HSA-VI: s_load_dwordx4 s{{\[[0-9]+:[0-9]+\]}}, s[8:9], 0x0
33 ; HSA-VI: .amdhsa_kernarg_size 24
34 define amdgpu_kernel void @i65_arg(ptr addrspace(1) nocapture %out, i65 %in) #0 {
36 store i65 %in, ptr addrspace(1) %out, align 4
40 ; FUNC-LABEL: {{^}}empty_struct_arg:
41 ; HSA-VI: .amdhsa_kernarg_size 0
42 define amdgpu_kernel void @empty_struct_arg({} %in) #0 {
46 ; The correct load offsets for these:
52 ; With the SelectionDAG argument lowering, the alignments for the
53 ; struct members is not properly considered, making these wrong.
55 ; FIXME: Total argument size is computed wrong
56 ; FUNC-LABEL: {{^}}struct_argument_alignment:
57 ; HSA-VI: s_load_dword s{{[0-9]+}}, s[8:9], 0x0
58 ; HSA-VI: s_load_dwordx2 s{{\[[0-9]+:[0-9]+\]}}, s[8:9], 0x8
59 ; HSA-VI: s_load_dword s{{[0-9]+}}, s[8:9], 0x18
60 ; HSA-VI: s_load_dwordx2 s{{\[[0-9]+:[0-9]+\]}}, s[8:9], 0x20
62 ; HSA-VI: .amdhsa_kernarg_size 40
63 define amdgpu_kernel void @struct_argument_alignment({i32, i64} %arg0, i8, {i32, i64} %arg1) #0 {
64 %val0 = extractvalue {i32, i64} %arg0, 0
65 %val1 = extractvalue {i32, i64} %arg0, 1
66 %val2 = extractvalue {i32, i64} %arg1, 0
67 %val3 = extractvalue {i32, i64} %arg1, 1
68 store volatile i32 %val0, ptr addrspace(1) null
69 store volatile i64 %val1, ptr addrspace(1) null
70 store volatile i32 %val2, ptr addrspace(1) null
71 store volatile i64 %val3, ptr addrspace(1) null
75 ; No padding between i8 and next struct, but round up at end to 4 byte
77 ; FUNC-LABEL: {{^}}packed_struct_argument_alignment:
78 ; HSA-VI-DAG: v_mov_b32_e32 [[ZERO:v[0-9]+]], 0{{$}}
79 ; HSA-VI: global_load_dword v{{[0-9]+}}, [[ZERO]], s{{\[[0-9]+:[0-9]+\]}} offset:13
80 ; HSA-VI: global_load_dwordx2 v{{\[[0-9]+:[0-9]+\]}}, [[ZERO]], s{{\[[0-9]+:[0-9]+\]}} offset:17
81 ; HSA-VI: s_load_dword s{{[0-9]+}}, s[8:9], 0x0
82 ; HSA-VI: s_load_dwordx2 s{{\[[0-9]+:[0-9]+\]}}, s[8:9], 0x4
84 ; HSA-VI: .amdhsa_kernarg_size 28
85 define amdgpu_kernel void @packed_struct_argument_alignment(<{i32, i64}> %arg0, i8, <{i32, i64}> %arg1) #0 {
86 %val0 = extractvalue <{i32, i64}> %arg0, 0
87 %val1 = extractvalue <{i32, i64}> %arg0, 1
88 %val2 = extractvalue <{i32, i64}> %arg1, 0
89 %val3 = extractvalue <{i32, i64}> %arg1, 1
90 store volatile i32 %val0, ptr addrspace(1) null
91 store volatile i64 %val1, ptr addrspace(1) null
92 store volatile i32 %val2, ptr addrspace(1) null
93 store volatile i64 %val3, ptr addrspace(1) null
97 ; GCN-LABEL: {{^}}struct_argument_alignment_after:
98 ; HSA-VI: s_load_dword s{{[0-9]+}}, s[8:9], 0x0
99 ; HSA-VI: s_load_dwordx2 s{{\[[0-9]+:[0-9]+\]}}, s[8:9], 0x8
100 ; HSA-VI: s_load_dword s{{[0-9]+}}, s[8:9], 0x18
101 ; HSA-VI: s_load_dwordx2 s{{\[[0-9]+:[0-9]+\]}}, s[8:9], 0x20
102 ; HSA-VI: s_load_dwordx4 s{{\[[0-9]+:[0-9]+\]}}, s[8:9], 0x30
104 ; HSA-VI: .amdhsa_kernarg_size 64
105 define amdgpu_kernel void @struct_argument_alignment_after({i32, i64} %arg0, i8, {i32, i64} %arg2, i8, <4 x i32> %arg4) #0 {
106 %val0 = extractvalue {i32, i64} %arg0, 0
107 %val1 = extractvalue {i32, i64} %arg0, 1
108 %val2 = extractvalue {i32, i64} %arg2, 0
109 %val3 = extractvalue {i32, i64} %arg2, 1
110 store volatile i32 %val0, ptr addrspace(1) null
111 store volatile i64 %val1, ptr addrspace(1) null
112 store volatile i32 %val2, ptr addrspace(1) null
113 store volatile i64 %val3, ptr addrspace(1) null
114 store volatile <4 x i32> %arg4, ptr addrspace(1) null
118 ; GCN-LABEL: {{^}}array_3xi32:
119 ; HSA-VI: s_load_dwordx4 s{{\[[0-9]+:[0-9]+\]}}, s[8:9], 0x0
120 define amdgpu_kernel void @array_3xi32(i16 %arg0, [3 x i32] %arg1) {
121 store volatile i16 %arg0, ptr addrspace(1) undef
122 store volatile [3 x i32] %arg1, ptr addrspace(1) undef
126 ; GCN-LABEL: {{^}}array_3xi16:
127 ; HSA-VI: s_load_dwordx2 s{{\[[0-9]+:[0-9]+\]}}, s[8:9], 0x0
128 define amdgpu_kernel void @array_3xi16(i8 %arg0, [3 x i16] %arg1) {
129 store volatile i8 %arg0, ptr addrspace(1) undef
130 store volatile [3 x i16] %arg1, ptr addrspace(1) undef
134 ; GCN-LABEL: {{^}}v2i15_arg:
135 ; GCN: s_load_dword [[DWORD:s[0-9]+]]
136 ; GCN-DAG: s_bfe_u32 [[BFE:s[0-9]+]], [[DWORD]], 0x100010{{$}}
137 ; GCN-DAG: s_and_b32 [[AND:s[0-9]+]], [[DWORD]], 0x7fff{{$}}
138 define amdgpu_kernel void @v2i15_arg(ptr addrspace(1) nocapture %out, <2 x i15> %in) #0 {
140 store <2 x i15> %in, ptr addrspace(1) %out, align 4
144 ; GCN-LABEL: {{^}}v3i15_arg:
145 ; GCN: s_load_dwordx4 [[DWORDX4:s\[[0-9]+:[0-9]+\]]]
150 define amdgpu_kernel void @v3i15_arg(ptr addrspace(1) nocapture %out, <3 x i15> %in) #0 {
152 store <3 x i15> %in, ptr addrspace(1) %out, align 4
156 ; Byref pointers should only be treated as offsets from kernarg
157 ; GCN-LABEL: {{^}}byref_constant_i8_arg:
158 ; GCN: v_mov_b32_e32 [[ZERO:v[0-9]+]], 0{{$}}
159 ; GCN: global_load_ubyte v{{[0-9]+}}, [[ZERO]], s[8:9] offset:8
160 ; GCN: .amdhsa_kernarg_size 12
161 define amdgpu_kernel void @byref_constant_i8_arg(ptr addrspace(1) nocapture %out, ptr addrspace(4) byref(i8) %in.byref) #0 {
162 %in = load i8, ptr addrspace(4) %in.byref
163 %ext = zext i8 %in to i32
164 store i32 %ext, ptr addrspace(1) %out, align 4
168 ; GCN-LABEL: {{^}}byref_constant_i16_arg:
169 ; GCN: v_mov_b32_e32 [[ZERO:v[0-9]+]], 0{{$}}
170 ; GCN: global_load_ushort v{{[0-9]+}}, [[ZERO]], s[8:9] offset:8
171 ; GCN: .amdhsa_kernarg_size 12
172 define amdgpu_kernel void @byref_constant_i16_arg(ptr addrspace(1) nocapture %out, ptr addrspace(4) byref(i16) %in.byref) #0 {
173 %in = load i16, ptr addrspace(4) %in.byref
174 %ext = zext i16 %in to i32
175 store i32 %ext, ptr addrspace(1) %out, align 4
179 ; GCN-LABEL: {{^}}byref_constant_i32_arg:
180 ; GCN: s_load_dwordx4 [[LOAD:s\[[0-9]+:[0-9]+\]]], s[8:9], 0x0{{$}}
181 ; GCN: .amdhsa_kernarg_size 16
182 define amdgpu_kernel void @byref_constant_i32_arg(ptr addrspace(1) nocapture %out, ptr addrspace(4) byref(i32) %in.byref, i32 %after.offset) #0 {
183 %in = load i32, ptr addrspace(4) %in.byref
184 store volatile i32 %in, ptr addrspace(1) %out, align 4
185 store volatile i32 %after.offset, ptr addrspace(1) %out, align 4
189 ; GCN-LABEL: {{^}}byref_constant_v4i32_arg:
190 ; GCN: s_load_dwordx4 s{{\[[0-9]+:[0-9]+\]}}, s[8:9], 0x10{{$}}
191 ; GCN: s_load_dword s{{[0-9]+}}, s[8:9], 0x20{{$}}
192 ; GCN: .amdhsa_kernarg_size 36
193 define amdgpu_kernel void @byref_constant_v4i32_arg(ptr addrspace(1) nocapture %out, ptr addrspace(4) byref(<4 x i32>) %in.byref, i32 %after.offset) #0 {
194 %in = load <4 x i32>, ptr addrspace(4) %in.byref
195 store volatile <4 x i32> %in, ptr addrspace(1) %out, align 4
196 store volatile i32 %after.offset, ptr addrspace(1) %out, align 4
200 ; GCN-LABEL: {{^}}byref_align_constant_i32_arg:
201 ; GCN-DAG: s_load_dwordx2 s[[[IN:[0-9]+]]:[[AFTER_OFFSET:[0-9]+]]], s[8:9], 0x100{{$}}
202 ; GCN-DAG: v_mov_b32_e32 [[V_IN:v[0-9]+]], s[[IN]]
203 ; GCN-DAG: v_mov_b32_e32 [[V_AFTER_OFFSET:v[0-9]+]], s[[AFTER_OFFSET]]
204 ; GCN: global_store_dword v{{[0-9]+}}, [[V_IN]], s
205 ; GCN: global_store_dword v{{[0-9]+}}, [[V_AFTER_OFFSET]], s
206 ; GCN: .amdhsa_kernarg_size 264
207 define amdgpu_kernel void @byref_align_constant_i32_arg(ptr addrspace(1) nocapture %out, ptr addrspace(4) byref(i32) align(256) %in.byref, i32 %after.offset) #0 {
208 %in = load i32, ptr addrspace(4) %in.byref
209 store volatile i32 %in, ptr addrspace(1) %out, align 4
210 store volatile i32 %after.offset, ptr addrspace(1) %out, align 4
214 ; GCN-LABEL: {{^}}byref_natural_align_constant_v16i32_arg:
215 ; GCN-DAG: s_load_dword s{{[0-9]+}}, s[8:9], 0x80
216 ; GCN-DAG: s_load_dwordx16 s{{\[[0-9]+:[0-9]+\]}}, s[8:9], 0x40{{$}}
217 ; GCN: .amdhsa_kernarg_size 132
218 define amdgpu_kernel void @byref_natural_align_constant_v16i32_arg(ptr addrspace(1) nocapture %out, i8, ptr addrspace(4) byref(<16 x i32>) align(64) %in.byref, i32 %after.offset) #0 {
219 %in = load <16 x i32>, ptr addrspace(4) %in.byref
220 store volatile <16 x i32> %in, ptr addrspace(1) %out, align 4
221 store volatile i32 %after.offset, ptr addrspace(1) %out, align 4
225 ; Also accept byref kernel arguments with other global address spaces.
226 ; GCN-LABEL: {{^}}byref_global_i32_arg:
227 ; GCN: s_load_dword [[IN:s[0-9]+]], s[8:9], 0x8{{$}}
228 ; GCN: .amdhsa_kernarg_size 12
229 define amdgpu_kernel void @byref_global_i32_arg(ptr addrspace(1) nocapture %out, ptr addrspace(1) byref(i32) %in.byref) #0 {
230 %in = load i32, ptr addrspace(1) %in.byref
231 store i32 %in, ptr addrspace(1) %out, align 4
235 ; GCN-LABEL: {{^}}byref_flat_i32_arg:
236 ; GCN: flat_load_dword [[IN:v[0-9]+]], v{{\[[0-9]+:[0-9]+\]}} offset:8{{$}}
237 define amdgpu_kernel void @byref_flat_i32_arg(ptr addrspace(1) nocapture %out, ptr byref(i32) %in.byref) #0 {
238 %in = load i32, ptr %in.byref
239 store i32 %in, ptr addrspace(1) %out, align 4
243 ; GCN-LABEL: {{^}}byref_constant_32bit_i32_arg:
244 ; GCN: s_add_i32 s[[PTR_LO:[0-9]+]], s8, 8
245 ; GCN: s_mov_b32 s[[PTR_HI:[0-9]+]], 0{{$}}
246 ; GCN: s_load_dword s{{[0-9]+}}, s[[[PTR_LO]]:[[PTR_HI]]], 0x0{{$}}
247 define amdgpu_kernel void @byref_constant_32bit_i32_arg(ptr addrspace(1) nocapture %out, ptr addrspace(6) byref(i32) %in.byref) #0 {
248 %in = load i32, ptr addrspace(6) %in.byref
249 store i32 %in, ptr addrspace(1) %out, align 4
253 ; define amdgpu_kernel void @byref_unknown_as_i32_arg(ptr addrspace(1) nocapture %out, ptr addrspace(999) byref %in.byref) {
254 ; %in = load i32, ptr addrspace(999) %in.byref
255 ; store i32 %in, ptr addrspace(1) %out, align 4
259 ; GCN-LABEL: {{^}}multi_byref_constant_i32_arg:
260 ; GCN: s_load_dwordx4 {{s\[[0-9]+:[0-9]+\]}}, s[8:9], 0x0
261 ; GCN: .amdhsa_kernarg_size 20
262 define amdgpu_kernel void @multi_byref_constant_i32_arg(ptr addrspace(1) nocapture %out, ptr addrspace(4) byref(i32) %in0.byref, ptr addrspace(4) byref(i32) %in1.byref, i32 %after.offset) #0 {
263 %in0 = load i32, ptr addrspace(4) %in0.byref
264 %in1 = load i32, ptr addrspace(4) %in1.byref
265 store volatile i32 %in0, ptr addrspace(1) %out, align 4
266 store volatile i32 %in1, ptr addrspace(1) %out, align 4
267 store volatile i32 %after.offset, ptr addrspace(1) %out, align 4
271 ; GCN-LABEL: {{^}}byref_constant_i32_arg_offset0:
274 ; GCN: s_load_dword {{s[0-9]+}}, s[8:9], 0x0{{$}}
275 ; GCN: .amdhsa_kernarg_size 4
276 define amdgpu_kernel void @byref_constant_i32_arg_offset0(ptr addrspace(4) byref(i32) %in.byref) #0 {
277 %in = load i32, ptr addrspace(4) %in.byref
278 store i32 %in, ptr addrspace(1) undef, align 4
282 attributes #0 = { "amdgpu-no-implicitarg-ptr" }
284 !llvm.module.flags = !{!0}
285 !0 = !{i32 1, !"amdhsa_code_object_version", i32 400}