1 ; RUN: llc -march=amdgcn -mcpu=tahiti -verify-machineinstrs < %s | FileCheck -allow-deprecated-dag-overlap -check-prefix=GCN -check-prefix=SI %s
2 ; RUN: llc -march=amdgcn -mcpu=tonga -mattr=-flat-for-global -verify-machineinstrs < %s | FileCheck -allow-deprecated-dag-overlap -check-prefix=GCN -check-prefix=VI %s
4 declare i32 @llvm.amdgcn.workitem.id.x() nounwind readnone
5 declare i32 @llvm.amdgcn.workitem.id.y() nounwind readnone
7 ; GCN-LABEL: {{^}}load_i8_to_f32:
8 ; GCN: {{buffer|flat}}_load_ubyte [[LOADREG:v[0-9]+]],
11 ; GCN: v_cvt_f32_ubyte0_e32 [[CONV:v[0-9]+]], [[LOADREG]]
12 ; GCN: buffer_store_dword [[CONV]],
13 define amdgpu_kernel void @load_i8_to_f32(float addrspace(1)* noalias %out, i8 addrspace(1)* noalias %in) nounwind {
14 %tid = call i32 @llvm.amdgcn.workitem.id.x()
15 %gep = getelementptr i8, i8 addrspace(1)* %in, i32 %tid
16 %load = load i8, i8 addrspace(1)* %gep, align 1
17 %cvt = uitofp i8 %load to float
18 store float %cvt, float addrspace(1)* %out, align 4
22 ; GCN-LABEL: {{^}}load_v2i8_to_v2f32:
23 ; GCN: {{buffer|flat}}_load_ushort [[LD:v[0-9]+]]
24 ; GCN-DAG: v_cvt_f32_ubyte1_e32 v[[HIRESULT:[0-9]+]], [[LD]]
25 ; GCN-DAG: v_cvt_f32_ubyte0_e32 v[[LORESULT:[0-9]+]], [[LD]]
26 ; GCN: buffer_store_dwordx2 v{{\[}}[[LORESULT]]:[[HIRESULT]]{{\]}},
27 define amdgpu_kernel void @load_v2i8_to_v2f32(<2 x float> addrspace(1)* noalias %out, <2 x i8> addrspace(1)* noalias %in) nounwind {
28 %tid = call i32 @llvm.amdgcn.workitem.id.x()
29 %gep = getelementptr <2 x i8>, <2 x i8> addrspace(1)* %in, i32 %tid
30 %load = load <2 x i8>, <2 x i8> addrspace(1)* %gep, align 2
31 %cvt = uitofp <2 x i8> %load to <2 x float>
32 store <2 x float> %cvt, <2 x float> addrspace(1)* %out, align 16
36 ; GCN-LABEL: {{^}}load_v3i8_to_v3f32:
37 ; GCN: {{buffer|flat}}_load_dword [[VAL:v[0-9]+]]
38 ; GCN-NOT: v_cvt_f32_ubyte3_e32
39 ; GCN-DAG: v_cvt_f32_ubyte2_e32 v[[HIRESULT:[0-9]+]], [[VAL]]
40 ; GCN-DAG: v_cvt_f32_ubyte1_e32 v[[MDRESULT:[0-9]+]], [[VAL]]
41 ; GCN-DAG: v_cvt_f32_ubyte0_e32 v[[LORESULT:[0-9]+]], [[VAL]]
42 ; SI: buffer_store_dwordx2 v{{\[}}[[LORESULT]]:[[MDRESULT]]{{\]}},
43 ; VI: buffer_store_dwordx3 v{{\[}}[[LORESULT]]:[[HIRESULT]]{{\]}},
44 define amdgpu_kernel void @load_v3i8_to_v3f32(<3 x float> addrspace(1)* noalias %out, <3 x i8> addrspace(1)* noalias %in) nounwind {
45 %tid = call i32 @llvm.amdgcn.workitem.id.x()
46 %gep = getelementptr <3 x i8>, <3 x i8> addrspace(1)* %in, i32 %tid
47 %load = load <3 x i8>, <3 x i8> addrspace(1)* %gep, align 4
48 %cvt = uitofp <3 x i8> %load to <3 x float>
49 store <3 x float> %cvt, <3 x float> addrspace(1)* %out, align 16
53 ; GCN-LABEL: {{^}}load_v4i8_to_v4f32:
54 ; GCN: {{buffer|flat}}_load_dword [[LOADREG:v[0-9]+]]
57 ; GCN-DAG: v_cvt_f32_ubyte3_e32 v[[HIRESULT:[0-9]+]], [[LOADREG]]
58 ; GCN-DAG: v_cvt_f32_ubyte2_e32 v{{[0-9]+}}, [[LOADREG]]
59 ; GCN-DAG: v_cvt_f32_ubyte1_e32 v{{[0-9]+}}, [[LOADREG]]
60 ; GCN-DAG: v_cvt_f32_ubyte0_e32 v[[LORESULT:[0-9]+]], [[LOADREG]]
61 ; GCN: buffer_store_dwordx4 v{{\[}}[[LORESULT]]:[[HIRESULT]]{{\]}},
62 define amdgpu_kernel void @load_v4i8_to_v4f32(<4 x float> addrspace(1)* noalias %out, <4 x i8> addrspace(1)* noalias %in) nounwind {
63 %tid = call i32 @llvm.amdgcn.workitem.id.x()
64 %gep = getelementptr <4 x i8>, <4 x i8> addrspace(1)* %in, i32 %tid
65 %load = load <4 x i8>, <4 x i8> addrspace(1)* %gep, align 4
66 %cvt = uitofp <4 x i8> %load to <4 x float>
67 store <4 x float> %cvt, <4 x float> addrspace(1)* %out, align 16
71 ; This should not be adding instructions to shift into the correct
72 ; position in the word for the component.
74 ; FIXME: Packing bytes
75 ; GCN-LABEL: {{^}}load_v4i8_to_v4f32_unaligned:
76 ; GCN: {{buffer|flat}}_load_ubyte [[LOADREG3:v[0-9]+]]
77 ; GCN: {{buffer|flat}}_load_ubyte [[LOADREG2:v[0-9]+]]
78 ; GCN: {{buffer|flat}}_load_ubyte [[LOADREG1:v[0-9]+]]
79 ; GCN: {{buffer|flat}}_load_ubyte [[LOADREG0:v[0-9]+]]
80 ; GCN-DAG: v_lshlrev_b32
82 ; GCN-DAG: v_cvt_f32_ubyte0_e32 v[[LORESULT:[0-9]+]],
83 ; GCN-DAG: v_cvt_f32_ubyte0_e32 v{{[0-9]+}},
84 ; GCN-DAG: v_cvt_f32_ubyte0_e32 v{{[0-9]+}},
85 ; GCN-DAG: v_cvt_f32_ubyte0_e32 v[[HIRESULT:[0-9]+]]
87 ; GCN: buffer_store_dwordx4
88 define amdgpu_kernel void @load_v4i8_to_v4f32_unaligned(<4 x float> addrspace(1)* noalias %out, <4 x i8> addrspace(1)* noalias %in) nounwind {
89 %tid = call i32 @llvm.amdgcn.workitem.id.x()
90 %gep = getelementptr <4 x i8>, <4 x i8> addrspace(1)* %in, i32 %tid
91 %load = load <4 x i8>, <4 x i8> addrspace(1)* %gep, align 1
92 %cvt = uitofp <4 x i8> %load to <4 x float>
93 store <4 x float> %cvt, <4 x float> addrspace(1)* %out, align 16
97 ; FIXME: Need to handle non-uniform case for function below (load without gep).
98 ; Instructions still emitted to repack bytes for add use.
100 ; GCN-LABEL: {{^}}load_v4i8_to_v4f32_2_uses:
101 ; GCN: {{buffer|flat}}_load_dword
102 ; GCN-DAG: v_cvt_f32_ubyte0_e32
103 ; GCN-DAG: v_cvt_f32_ubyte1_e32
104 ; GCN-DAG: v_cvt_f32_ubyte2_e32
105 ; GCN-DAG: v_cvt_f32_ubyte3_e32
107 ; GCN-DAG: v_lshrrev_b32_e32 v{{[0-9]+}}, 24
109 ; SI-DAG: v_lshlrev_b32_e32 v{{[0-9]+}}, 16
110 ; SI-DAG: v_lshlrev_b32_e32 v{{[0-9]+}}, 8
111 ; SI-DAG: v_and_b32_e32 v{{[0-9]+}}, 0xffff,
112 ; SI-DAG: v_and_b32_e32 v{{[0-9]+}}, 0xff00,
115 ; VI-DAG: v_and_b32_e32 v{{[0-9]+}}, 0xffffff00,
116 ; VI-DAG: v_add_u16_e32
117 ; VI-DAG: v_add_u16_e32
119 ; GCN: {{buffer|flat}}_store_dwordx4
120 ; GCN: {{buffer|flat}}_store_dword
123 define amdgpu_kernel void @load_v4i8_to_v4f32_2_uses(<4 x float> addrspace(1)* noalias %out, <4 x i8> addrspace(1)* noalias %out2, <4 x i8> addrspace(1)* noalias %in) nounwind {
124 %tid.x = call i32 @llvm.amdgcn.workitem.id.x()
125 %in.ptr = getelementptr <4 x i8>, <4 x i8> addrspace(1)* %in, i32 %tid.x
126 %load = load <4 x i8>, <4 x i8> addrspace(1)* %in.ptr, align 4
127 %cvt = uitofp <4 x i8> %load to <4 x float>
128 store <4 x float> %cvt, <4 x float> addrspace(1)* %out, align 16
129 %add = add <4 x i8> %load, <i8 9, i8 9, i8 9, i8 9> ; Second use of %load
130 store <4 x i8> %add, <4 x i8> addrspace(1)* %out2, align 4
134 ; Make sure this doesn't crash.
135 ; GCN-LABEL: {{^}}load_v7i8_to_v7f32:
137 define amdgpu_kernel void @load_v7i8_to_v7f32(<7 x float> addrspace(1)* noalias %out, <7 x i8> addrspace(1)* noalias %in) nounwind {
138 %tid = call i32 @llvm.amdgcn.workitem.id.x()
139 %gep = getelementptr <7 x i8>, <7 x i8> addrspace(1)* %in, i32 %tid
140 %load = load <7 x i8>, <7 x i8> addrspace(1)* %gep, align 1
141 %cvt = uitofp <7 x i8> %load to <7 x float>
142 store <7 x float> %cvt, <7 x float> addrspace(1)* %out, align 16
146 ; GCN-LABEL: {{^}}load_v8i8_to_v8f32:
147 ; GCN: {{buffer|flat}}_load_dwordx2 v{{\[}}[[LOLOAD:[0-9]+]]:[[HILOAD:[0-9]+]]{{\]}},
150 ; GCN-DAG: v_cvt_f32_ubyte3_e32 v{{[0-9]+}}, v[[LOLOAD]]
151 ; GCN-DAG: v_cvt_f32_ubyte2_e32 v{{[0-9]+}}, v[[LOLOAD]]
152 ; GCN-DAG: v_cvt_f32_ubyte1_e32 v{{[0-9]+}}, v[[LOLOAD]]
153 ; GCN-DAG: v_cvt_f32_ubyte0_e32 v{{[0-9]+}}, v[[LOLOAD]]
154 ; GCN-DAG: v_cvt_f32_ubyte3_e32 v{{[0-9]+}}, v[[HILOAD]]
155 ; GCN-DAG: v_cvt_f32_ubyte2_e32 v{{[0-9]+}}, v[[HILOAD]]
156 ; GCN-DAG: v_cvt_f32_ubyte1_e32 v{{[0-9]+}}, v[[HILOAD]]
157 ; GCN-DAG: v_cvt_f32_ubyte0_e32 v{{[0-9]+}}, v[[HILOAD]]
160 ; GCN: buffer_store_dwordx4
161 ; GCN: buffer_store_dwordx4
162 define amdgpu_kernel void @load_v8i8_to_v8f32(<8 x float> addrspace(1)* noalias %out, <8 x i8> addrspace(1)* noalias %in) nounwind {
163 %tid = call i32 @llvm.amdgcn.workitem.id.x()
164 %gep = getelementptr <8 x i8>, <8 x i8> addrspace(1)* %in, i32 %tid
165 %load = load <8 x i8>, <8 x i8> addrspace(1)* %gep, align 8
166 %cvt = uitofp <8 x i8> %load to <8 x float>
167 store <8 x float> %cvt, <8 x float> addrspace(1)* %out, align 16
171 ; GCN-LABEL: {{^}}i8_zext_inreg_i32_to_f32:
172 ; GCN: {{buffer|flat}}_load_dword [[LOADREG:v[0-9]+]],
173 ; GCN: v_add_{{[iu]}}32_e32 [[ADD:v[0-9]+]], vcc, 2, [[LOADREG]]
174 ; GCN-NEXT: v_cvt_f32_ubyte0_e32 [[CONV:v[0-9]+]], [[ADD]]
175 ; GCN: buffer_store_dword [[CONV]],
176 define amdgpu_kernel void @i8_zext_inreg_i32_to_f32(float addrspace(1)* noalias %out, i32 addrspace(1)* noalias %in) nounwind {
177 %tid = call i32 @llvm.amdgcn.workitem.id.x()
178 %gep = getelementptr i32, i32 addrspace(1)* %in, i32 %tid
179 %load = load i32, i32 addrspace(1)* %gep, align 4
180 %add = add i32 %load, 2
181 %inreg = and i32 %add, 255
182 %cvt = uitofp i32 %inreg to float
183 store float %cvt, float addrspace(1)* %out, align 4
187 ; GCN-LABEL: {{^}}i8_zext_inreg_hi1_to_f32:
188 define amdgpu_kernel void @i8_zext_inreg_hi1_to_f32(float addrspace(1)* noalias %out, i32 addrspace(1)* noalias %in) nounwind {
189 %tid = call i32 @llvm.amdgcn.workitem.id.x()
190 %gep = getelementptr i32, i32 addrspace(1)* %in, i32 %tid
191 %load = load i32, i32 addrspace(1)* %gep, align 4
192 %inreg = and i32 %load, 65280
193 %shr = lshr i32 %inreg, 8
194 %cvt = uitofp i32 %shr to float
195 store float %cvt, float addrspace(1)* %out, align 4
199 ; We don't get these ones because of the zext, but instcombine removes
200 ; them so it shouldn't really matter.
201 ; GCN-LABEL: {{^}}i8_zext_i32_to_f32:
202 define amdgpu_kernel void @i8_zext_i32_to_f32(float addrspace(1)* noalias %out, i8 addrspace(1)* noalias %in) nounwind {
203 %tid = call i32 @llvm.amdgcn.workitem.id.x()
204 %gep = getelementptr i8, i8 addrspace(1)* %in, i32 %tid
205 %load = load i8, i8 addrspace(1)* %gep, align 1
206 %ext = zext i8 %load to i32
207 %cvt = uitofp i32 %ext to float
208 store float %cvt, float addrspace(1)* %out, align 4
212 ; GCN-LABEL: {{^}}v4i8_zext_v4i32_to_v4f32:
213 define amdgpu_kernel void @v4i8_zext_v4i32_to_v4f32(<4 x float> addrspace(1)* noalias %out, <4 x i8> addrspace(1)* noalias %in) nounwind {
214 %tid = call i32 @llvm.amdgcn.workitem.id.x()
215 %gep = getelementptr <4 x i8>, <4 x i8> addrspace(1)* %in, i32 %tid
216 %load = load <4 x i8>, <4 x i8> addrspace(1)* %gep, align 1
217 %ext = zext <4 x i8> %load to <4 x i32>
218 %cvt = uitofp <4 x i32> %ext to <4 x float>
219 store <4 x float> %cvt, <4 x float> addrspace(1)* %out, align 16
223 ; GCN-LABEL: {{^}}extract_byte0_to_f32:
224 ; GCN: {{buffer|flat}}_load_dword [[VAL:v[0-9]+]]
226 ; GCN: v_cvt_f32_ubyte0_e32 [[CONV:v[0-9]+]], [[VAL]]
227 ; GCN: buffer_store_dword [[CONV]]
228 define amdgpu_kernel void @extract_byte0_to_f32(float addrspace(1)* noalias %out, i32 addrspace(1)* noalias %in) nounwind {
229 %tid = call i32 @llvm.amdgcn.workitem.id.x()
230 %gep = getelementptr i32, i32 addrspace(1)* %in, i32 %tid
231 %val = load i32, i32 addrspace(1)* %gep
232 %and = and i32 %val, 255
233 %cvt = uitofp i32 %and to float
234 store float %cvt, float addrspace(1)* %out
238 ; GCN-LABEL: {{^}}extract_byte1_to_f32:
239 ; GCN: {{buffer|flat}}_load_dword [[VAL:v[0-9]+]]
241 ; GCN: v_cvt_f32_ubyte1_e32 [[CONV:v[0-9]+]], [[VAL]]
242 ; GCN: buffer_store_dword [[CONV]]
243 define amdgpu_kernel void @extract_byte1_to_f32(float addrspace(1)* noalias %out, i32 addrspace(1)* noalias %in) nounwind {
244 %tid = call i32 @llvm.amdgcn.workitem.id.x()
245 %gep = getelementptr i32, i32 addrspace(1)* %in, i32 %tid
246 %val = load i32, i32 addrspace(1)* %gep
247 %srl = lshr i32 %val, 8
248 %and = and i32 %srl, 255
249 %cvt = uitofp i32 %and to float
250 store float %cvt, float addrspace(1)* %out
254 ; GCN-LABEL: {{^}}extract_byte2_to_f32:
255 ; GCN: {{buffer|flat}}_load_dword [[VAL:v[0-9]+]]
257 ; GCN: v_cvt_f32_ubyte2_e32 [[CONV:v[0-9]+]], [[VAL]]
258 ; GCN: buffer_store_dword [[CONV]]
259 define amdgpu_kernel void @extract_byte2_to_f32(float addrspace(1)* noalias %out, i32 addrspace(1)* noalias %in) nounwind {
260 %tid = call i32 @llvm.amdgcn.workitem.id.x()
261 %gep = getelementptr i32, i32 addrspace(1)* %in, i32 %tid
262 %val = load i32, i32 addrspace(1)* %gep
263 %srl = lshr i32 %val, 16
264 %and = and i32 %srl, 255
265 %cvt = uitofp i32 %and to float
266 store float %cvt, float addrspace(1)* %out
270 ; GCN-LABEL: {{^}}extract_byte3_to_f32:
271 ; GCN: {{buffer|flat}}_load_dword [[VAL:v[0-9]+]]
273 ; GCN: v_cvt_f32_ubyte3_e32 [[CONV:v[0-9]+]], [[VAL]]
274 ; GCN: buffer_store_dword [[CONV]]
275 define amdgpu_kernel void @extract_byte3_to_f32(float addrspace(1)* noalias %out, i32 addrspace(1)* noalias %in) nounwind {
276 %tid = call i32 @llvm.amdgcn.workitem.id.x()
277 %gep = getelementptr i32, i32 addrspace(1)* %in, i32 %tid
278 %val = load i32, i32 addrspace(1)* %gep
279 %srl = lshr i32 %val, 24
280 %and = and i32 %srl, 255
281 %cvt = uitofp i32 %and to float
282 store float %cvt, float addrspace(1)* %out
286 ; GCN-LABEL: {{^}}cvt_ubyte0_or_multiuse:
287 ; GCN: {{buffer|flat}}_load_dword [[LOADREG:v[0-9]+]],
288 ; GCN-DAG: v_or_b32_e32 [[OR:v[0-9]+]], 0x80000001, [[LOADREG]]
289 ; GCN-DAG: v_cvt_f32_ubyte0_e32 [[CONV:v[0-9]+]], [[OR]]
290 ; GCN: v_add_f32_e32 [[RES:v[0-9]+]], [[OR]], [[CONV]]
291 ; GCN: buffer_store_dword [[RES]],
292 define amdgpu_kernel void @cvt_ubyte0_or_multiuse(i32 addrspace(1)* %in, float addrspace(1)* %out) {
294 %lid = tail call i32 @llvm.amdgcn.workitem.id.x()
295 %gep = getelementptr inbounds i32, i32 addrspace(1)* %in, i32 %lid
296 %load = load i32, i32 addrspace(1)* %gep
297 %or = or i32 %load, -2147483647
298 %and = and i32 %or, 255
299 %uitofp = uitofp i32 %and to float
300 %cast = bitcast i32 %or to float
301 %add = fadd float %cast, %uitofp
302 store float %add, float addrspace(1)* %out