1 ; RUN: llc -march=amdgcn -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefix=GCN -check-prefix=SI %s
2 ; RUN: llc -march=amdgcn -mcpu=tonga -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefix=GCN -check-prefix=VI %s
4 ; Make sure we don't crash or assert on spir_kernel calling convention.
6 ; GCN-LABEL: {{^}}kernel:
8 define spir_kernel void @kernel(i32 addrspace(1)* %out) {
10 store i32 0, i32 addrspace(1)* %out
14 ; FIXME: This is treated like a kernel
15 ; XGCN-LABEL: {{^}}func:
17 ; define spir_func void @func(i32 addrspace(1)* %out) {
19 ; store i32 0, i32 addrspace(1)* %out
23 ; GCN-LABEL: {{^}}ps_ret_cc_f16:
24 ; SI: v_cvt_f16_f32_e32 v0, v0
25 ; SI: v_cvt_f32_f16_e32 v0, v0
26 ; SI: v_add_f32_e32 v0, 1.0, v0
28 ; VI: v_add_f16_e32 v0, 1.0, v0
30 define amdgpu_ps half @ps_ret_cc_f16(half %arg0) {
31 %add = fadd half %arg0, 1.0
35 ; GCN-LABEL: {{^}}ps_ret_cc_inreg_f16:
36 ; SI: v_cvt_f16_f32_e32 v0, s0
37 ; SI: v_cvt_f32_f16_e32 v0, v0
38 ; SI: v_add_f32_e32 v0, 1.0, v0
40 ; VI: v_add_f16_e64 v0, s0, 1.0
42 define amdgpu_ps half @ps_ret_cc_inreg_f16(half inreg %arg0) {
43 %add = fadd half %arg0, 1.0
47 ; GCN-LABEL: {{^}}fastcc:
48 ; GCN: v_add_f32_e32 v0, 4.0, v0
49 define fastcc float @fastcc(float %arg0) #0 {
50 %add = fadd float %arg0, 4.0
54 ; GCN-LABEL: {{^}}coldcc:
55 ; GCN: v_add_f32_e32 v0, 4.0, v0
56 define coldcc float @coldcc(float %arg0) #0 {
57 %add = fadd float %arg0, 4.0
61 ; GCN-LABEL: {{^}}call_coldcc:
62 ; GCN: v_mov_b32_e32 v0, 1.0
64 define amdgpu_kernel void @call_coldcc() #0 {
65 %val = call float @coldcc(float 1.0)
66 store float %val, float addrspace(1)* undef
70 ; GCN-LABEL: {{^}}call_fastcc:
71 ; GCN: v_mov_b32_e32 v0, 1.0
73 define amdgpu_kernel void @call_fastcc() #0 {
74 %val = call float @fastcc(float 1.0)
75 store float %val, float addrspace(1)* undef
79 ; Mesa compute shader: check for 47176 (COMPUTE_PGM_RSRC1) in .AMDGPU.config
80 ; GCN-LABEL: .AMDGPU.config
82 ; GCN-LABEL: {{^}}cs_mesa:
83 define amdgpu_cs half @cs_mesa(half %arg0) {
84 %add = fadd half %arg0, 1.0
88 ; Mesa pixel shader: check for 45096 (SPI_SHADER_PGM_RSRC1_PS) in .AMDGPU.config
89 ; GCN-LABEL: .AMDGPU.config
91 ; GCN-LABEL: {{^}}ps_mesa_f16:
92 define amdgpu_ps half @ps_mesa_f16(half %arg0) {
93 %add = fadd half %arg0, 1.0
97 ; Mesa vertex shader: check for 45352 (SPI_SHADER_PGM_RSRC1_VS) in .AMDGPU.config
98 ; GCN-LABEL: .AMDGPU.config
100 ; GCN-LABEL: {{^}}vs_mesa:
101 define amdgpu_vs half @vs_mesa(half %arg0) {
102 %add = fadd half %arg0, 1.0
106 ; Mesa geometry shader: check for 45608 (SPI_SHADER_PGM_RSRC1_GS) in .AMDGPU.config
107 ; GCN-LABEL: .AMDGPU.config
109 ; GCN-LABEL: {{^}}gs_mesa:
110 define amdgpu_gs half @gs_mesa(half %arg0) {
111 %add = fadd half %arg0, 1.0
115 ; Mesa hull shader: check for 46120 (SPI_SHADER_PGM_RSRC1_HS) in .AMDGPU.config
116 ; GCN-LABEL: .AMDGPU.config
118 ; GCN-LABEL: {{^}}hs_mesa:
119 define amdgpu_hs half @hs_mesa(half %arg0) {
120 %add = fadd half %arg0, 1.0
124 ; FIXME: Inconsistent ABI between targets
125 ; GCN-LABEL: {{^}}ps_mesa_v2f16:
126 ; VI: v_mov_b32_e32 v1, 0x3c00
127 ; VI-NEXT: v_add_f16_sdwa v1, v0, v1 dst_sel:WORD_1 dst_unused:UNUSED_PAD src0_sel:WORD_1 src1_sel:DWORD
128 ; VI-NEXT: v_add_f16_e32 v0, 1.0, v0
129 ; VI-NEXT: v_or_b32_e32 v0, v0, v1
132 ; SI-DAG: v_cvt_f16_f32_e32 [[CVT_ELT0:v[0-9]+]], v0
133 ; SI-DAG: v_cvt_f16_f32_e32 [[CVT_ELT1:v[0-9]+]], v1
134 ; SI-DAG: v_cvt_f32_f16_e32 [[RECVT_ELT0:v[0-9]+]], [[CVT_ELT0]]
135 ; SI-DAG: v_cvt_f32_f16_e32 [[RECVT_ELT1:v[0-9]+]], [[CVT_ELT1]]
136 ; SI-DAG: v_add_f32_e32 v0, 1.0, [[RECVT_ELT0]]
137 ; SI-DAG: v_add_f32_e32 v1, 1.0, [[RECVT_ELT1]]
138 ; SI: ; return to shader part epilog
139 define amdgpu_ps <2 x half> @ps_mesa_v2f16(<2 x half> %arg0) {
140 %add = fadd <2 x half> %arg0, <half 1.0, half 1.0>
144 ; GCN-LABEL: {{^}}ps_mesa_inreg_v2f16:
145 ; VI: s_lshr_b32 s1, s0, 16
146 ; VI-NEXT: v_mov_b32_e32 v0, s1
147 ; VI-NEXT: v_mov_b32_e32 v1, 0x3c00
148 ; VI-NEXT: v_add_f16_sdwa v0, v0, v1 dst_sel:WORD_1 dst_unused:UNUSED_PAD src0_sel:DWORD src1_sel:DWORD
149 ; VI-NEXT: v_add_f16_e64 v1, s0, 1.0
150 ; VI-NEXT: v_or_b32_e32 v0, v1, v0
151 ; VI-NEXT: ; return to shader part epilog
153 ; SI-DAG: v_cvt_f16_f32_e32 [[CVT_ELT0:v[0-9]+]], s0
154 ; SI-DAG: v_cvt_f16_f32_e32 [[CVT_ELT1:v[0-9]+]], s1
155 ; SI-DAG: v_cvt_f32_f16_e32 [[RECVT_ELT0:v[0-9]+]], [[CVT_ELT0]]
156 ; SI-DAG: v_cvt_f32_f16_e32 [[RECVT_ELT1:v[0-9]+]], [[CVT_ELT1]]
157 ; SI-DAG: v_add_f32_e32 v0, 1.0, [[RECVT_ELT0]]
158 ; SI-DAG: v_add_f32_e32 v1, 1.0, [[RECVT_ELT1]]
159 ; SI: ; return to shader part epilog
160 define amdgpu_ps <2 x half> @ps_mesa_inreg_v2f16(<2 x half> inreg %arg0) {
161 %add = fadd <2 x half> %arg0, <half 1.0, half 1.0>
165 ; GCN-LABEL: {{^}}ps_mesa_v2i16:
166 ; VI: v_mov_b32_e32 v2, 1
167 ; VI: v_add_u16_e32 v1, 1, v0
168 ; VI: v_add_u16_sdwa v0, v0, v2 dst_sel:WORD_1 dst_unused:UNUSED_PAD src0_sel:WORD_1 src1_sel:DWORD
169 ; VI: v_or_b32_e32 v0, v1, v0
172 ; SI: v_lshlrev_b32_e32 v1, 16, v1
173 ; SI: v_add_i32_e32 v0, vcc, 1, v0
176 ; SI: v_add_i32_e32 v0, vcc, 0x10000, v0
177 define amdgpu_ps void @ps_mesa_v2i16(<2 x i16> %arg0) {
178 %add = add <2 x i16> %arg0, <i16 1, i16 1>
179 store <2 x i16> %add, <2 x i16> addrspace(1)* undef
183 ; GCN-LABEL: {{^}}ps_mesa_inreg_v2i16:
184 ; VI: s_and_b32 s1, s0, 0xffff0000
185 ; VI: s_add_i32 s0, s0, 1
186 ; VI: s_and_b32 s0, s0, 0xffff
187 ; VI: s_or_b32 s0, s1, s0
188 ; VI: s_add_i32 s0, s0, 0x10000
189 ; VI: v_mov_b32_e32 v0, s0
191 ; SI: s_lshl_b32 s1, s1, 16
192 ; SI: s_add_i32 s0, s0, 1
193 ; SI: s_and_b32 s0, s0, 0xffff
194 ; SI: s_or_b32 s0, s1, s0
195 ; SI: s_add_i32 s0, s0, 0x10000
196 define amdgpu_ps void @ps_mesa_inreg_v2i16(<2 x i16> inreg %arg0) {
197 %add = add <2 x i16> %arg0, <i16 1, i16 1>
198 store <2 x i16> %add, <2 x i16> addrspace(1)* undef
202 ; FIXME: Differenet ABI for VI+
203 ; GCN-LABEL: {{^}}ps_mesa_v4f16:
204 ; SI: v_cvt_f16_f32_e32 v3, v3
205 ; SI: v_cvt_f16_f32_e32 v2, v2
206 ; SI: v_cvt_f16_f32_e32 v1, v1
207 ; SI: v_cvt_f16_f32_e32 v0, v0
209 ; VI: v_add_f16_e32 v2, 1.0, v1
210 ; VI: v_add_f16_sdwa v1, v1, v3 dst_sel:WORD_1 dst_unused:UNUSED_PAD src0_sel:WORD_1 src1_sel:DWORD
211 ; VI: v_add_f16_e32 v4, 1.0, v0
212 ; VI: v_add_f16_sdwa v0, v0, v3 dst_sel:WORD_1 dst_unused:UNUSED_PAD src0_sel:WORD_1 src1_sel:DWORD
213 define amdgpu_ps <4 x half> @ps_mesa_v4f16(<4 x half> %arg0) {
214 %add = fadd <4 x half> %arg0, <half 1.0, half 1.0, half 1.0, half 1.0>
218 ; GCN-LABEL: {{^}}ps_mesa_inreg_v4f16:
219 ; SI: v_cvt_f16_f32_e32 v{{[0-9]+}}, s3
220 ; SI: v_cvt_f16_f32_e32 v{{[0-9]+}}, s2
221 ; SI: v_cvt_f16_f32_e32 v{{[0-9]+}}, s1
222 ; SI: v_cvt_f16_f32_e32 v{{[0-9]+}}, s0
228 define amdgpu_ps <4 x half> @ps_mesa_inreg_v4f16(<4 x half> inreg %arg0) {
229 %add = fadd <4 x half> %arg0, <half 1.0, half 1.0, half 1.0, half 1.0>
233 ; GCN-LABEL: {{^}}ps_mesa_inreg_v3i32:
234 ; GCN-DAG: s_add_i32 s0, s0, 1
235 ; GCN-DAG: s_add_i32 s{{[0-9]*}}, s1, 2
236 ; GCN-DAG: s_add_i32 s{{[0-9]*}}, s2, 3
237 define amdgpu_ps void @ps_mesa_inreg_v3i32(<3 x i32> inreg %arg0) {
238 %add = add <3 x i32> %arg0, <i32 1, i32 2, i32 3>
239 store <3 x i32> %add, <3 x i32> addrspace(1)* undef
243 ; GCN-LABEL: {{^}}ps_mesa_inreg_v3f32:
244 ; GCN-DAG: v_add_f32{{.*}}, s0, 1.0
245 ; GCN-DAG: v_add_f32{{.*}}, s1, 2.0
246 ; GCN-DAG: v_add_f32{{.*}}, s2, 4.0
247 define amdgpu_ps void @ps_mesa_inreg_v3f32(<3 x float> inreg %arg0) {
248 %add = fadd <3 x float> %arg0, <float 1.0, float 2.0, float 4.0>
249 store <3 x float> %add, <3 x float> addrspace(1)* undef
253 ; GCN-LABEL: {{^}}ps_mesa_inreg_v5i32:
254 ; GCN-DAG: s_add_i32 s0, s0, 1
255 ; GCN-DAG: s_add_i32 s{{[0-9]*}}, s1, 2
256 ; GCN-DAG: s_add_i32 s{{[0-9]*}}, s2, 3
257 ; GCN-DAG: s_add_i32 s{{[0-9]*}}, s3, 4
258 ; GCN-DAG: s_add_i32 s{{[0-9]*}}, s4, 5
259 define amdgpu_ps void @ps_mesa_inreg_v5i32(<5 x i32> inreg %arg0) {
260 %add = add <5 x i32> %arg0, <i32 1, i32 2, i32 3, i32 4, i32 5>
261 store <5 x i32> %add, <5 x i32> addrspace(1)* undef
265 ; GCN-LABEL: {{^}}ps_mesa_inreg_v5f32:
266 ; GCN-DAG: v_add_f32{{.*}}, s0, 1.0
267 ; GCN-DAG: v_add_f32{{.*}}, s1, 2.0
268 ; GCN-DAG: v_add_f32{{.*}}, s2, 4.0
269 ; GCN-DAG: v_add_f32{{.*}}, s3, -1.0
270 ; GCN-DAG: v_add_f32{{.*}}, s4, 0.5
271 define amdgpu_ps void @ps_mesa_inreg_v5f32(<5 x float> inreg %arg0) {
272 %add = fadd <5 x float> %arg0, <float 1.0, float 2.0, float 4.0, float -1.0, float 0.5>
273 store <5 x float> %add, <5 x float> addrspace(1)* undef
277 ; GCN-LABEL: {{^}}ps_mesa_v3i32:
278 ; GCN-DAG: v_add_{{.*}}, 1, v0
279 ; GCN-DAG: v_add_{{.*}}, 2, v1
280 ; GCN-DAG: v_add_{{.*}}, 3, v2
281 define amdgpu_ps void @ps_mesa_v3i32(<3 x i32> %arg0) {
282 %add = add <3 x i32> %arg0, <i32 1, i32 2, i32 3>
283 store <3 x i32> %add, <3 x i32> addrspace(1)* undef
287 ; GCN-LABEL: {{^}}ps_mesa_v3f32:
288 ; GCN-DAG: v_add_{{.*}}, 1.0, v0
289 ; GCN-DAG: v_add_{{.*}}, 2.0, v1
290 ; GCN-DAG: v_add_{{.*}}, 4.0, v2
291 define amdgpu_ps void @ps_mesa_v3f32(<3 x float> %arg0) {
292 %add = fadd <3 x float> %arg0, <float 1.0, float 2.0, float 4.0>
293 store <3 x float> %add, <3 x float> addrspace(1)* undef
297 ; GCN-LABEL: {{^}}ps_mesa_v5i32:
298 ; GCN-DAG: v_add_{{.*}}, 1, v0
299 ; GCN-DAG: v_add_{{.*}}, 2, v1
300 ; GCN-DAG: v_add_{{.*}}, 3, v2
301 ; GCN-DAG: v_add_{{.*}}, 4, v3
302 ; GCN-DAG: v_add_{{.*}}, 5, v4
303 define amdgpu_ps void @ps_mesa_v5i32(<5 x i32> %arg0) {
304 %add = add <5 x i32> %arg0, <i32 1, i32 2, i32 3, i32 4, i32 5>
305 store <5 x i32> %add, <5 x i32> addrspace(1)* undef
309 ; GCN-LABEL: {{^}}ps_mesa_v5f32:
310 ; GCN-DAG: v_add_f32{{.*}}, 1.0, v0
311 ; GCN-DAG: v_add_f32{{.*}}, 2.0, v1
312 ; GCN-DAG: v_add_f32{{.*}}, 4.0, v2
313 ; GCN-DAG: v_add_f32{{.*}}, -1.0, v3
314 ; GCN-DAG: v_add_f32{{.*}}, 0.5, v4
315 define amdgpu_ps void @ps_mesa_v5f32(<5 x float> %arg0) {
316 %add = fadd <5 x float> %arg0, <float 1.0, float 2.0, float 4.0, float -1.0, float 0.5>
317 store <5 x float> %add, <5 x float> addrspace(1)* undef
323 attributes #0 = { nounwind noinline }