1 ; RUN: llc -march=amdgcn -mcpu=tahiti -verify-machineinstrs < %s | FileCheck -check-prefix=GCN -check-prefix=SI %s
2 ; RUN: llc -march=amdgcn -mcpu=tonga -mattr=-flat-for-global -verify-machineinstrs < %s | FileCheck -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{{[0-9]+}}, [[VAL]]
40 ; GCN-DAG: v_cvt_f32_ubyte1_e32 v[[HIRESULT:[0-9]+]], [[VAL]]
41 ; GCN-DAG: v_cvt_f32_ubyte0_e32 v[[LORESULT:[0-9]+]], [[VAL]]
42 ; GCN: buffer_store_dwordx2 v{{\[}}[[LORESULT]]:[[HIRESULT]]{{\]}},
43 define amdgpu_kernel void @load_v3i8_to_v3f32(<3 x float> addrspace(1)* noalias %out, <3 x i8> addrspace(1)* noalias %in) nounwind {
44 %tid = call i32 @llvm.amdgcn.workitem.id.x()
45 %gep = getelementptr <3 x i8>, <3 x i8> addrspace(1)* %in, i32 %tid
46 %load = load <3 x i8>, <3 x i8> addrspace(1)* %gep, align 4
47 %cvt = uitofp <3 x i8> %load to <3 x float>
48 store <3 x float> %cvt, <3 x float> addrspace(1)* %out, align 16
52 ; GCN-LABEL: {{^}}load_v4i8_to_v4f32:
53 ; GCN: {{buffer|flat}}_load_dword [[LOADREG:v[0-9]+]]
56 ; GCN-DAG: v_cvt_f32_ubyte3_e32 v[[HIRESULT:[0-9]+]], [[LOADREG]]
57 ; GCN-DAG: v_cvt_f32_ubyte2_e32 v{{[0-9]+}}, [[LOADREG]]
58 ; GCN-DAG: v_cvt_f32_ubyte1_e32 v{{[0-9]+}}, [[LOADREG]]
59 ; GCN-DAG: v_cvt_f32_ubyte0_e32 v[[LORESULT:[0-9]+]], [[LOADREG]]
60 ; GCN: buffer_store_dwordx4 v{{\[}}[[LORESULT]]:[[HIRESULT]]{{\]}},
61 define amdgpu_kernel void @load_v4i8_to_v4f32(<4 x float> addrspace(1)* noalias %out, <4 x i8> addrspace(1)* noalias %in) nounwind {
62 %tid = call i32 @llvm.amdgcn.workitem.id.x()
63 %gep = getelementptr <4 x i8>, <4 x i8> addrspace(1)* %in, i32 %tid
64 %load = load <4 x i8>, <4 x i8> addrspace(1)* %gep, align 4
65 %cvt = uitofp <4 x i8> %load to <4 x float>
66 store <4 x float> %cvt, <4 x float> addrspace(1)* %out, align 16
70 ; This should not be adding instructions to shift into the correct
71 ; position in the word for the component.
73 ; FIXME: Packing bytes
74 ; GCN-LABEL: {{^}}load_v4i8_to_v4f32_unaligned:
75 ; GCN: {{buffer|flat}}_load_ubyte [[LOADREG3:v[0-9]+]]
76 ; GCN: {{buffer|flat}}_load_ubyte [[LOADREG2:v[0-9]+]]
77 ; GCN: {{buffer|flat}}_load_ubyte [[LOADREG1:v[0-9]+]]
78 ; GCN: {{buffer|flat}}_load_ubyte [[LOADREG0:v[0-9]+]]
79 ; GCN-DAG: v_lshlrev_b32
81 ; GCN-DAG: v_cvt_f32_ubyte0_e32 v[[LORESULT:[0-9]+]],
82 ; GCN-DAG: v_cvt_f32_ubyte0_e32 v{{[0-9]+}},
83 ; GCN-DAG: v_cvt_f32_ubyte0_e32 v{{[0-9]+}},
84 ; GCN-DAG: v_cvt_f32_ubyte0_e32 v[[HIRESULT:[0-9]+]]
86 ; GCN: buffer_store_dwordx4
87 define amdgpu_kernel void @load_v4i8_to_v4f32_unaligned(<4 x float> addrspace(1)* noalias %out, <4 x i8> addrspace(1)* noalias %in) nounwind {
88 %tid = call i32 @llvm.amdgcn.workitem.id.x()
89 %gep = getelementptr <4 x i8>, <4 x i8> addrspace(1)* %in, i32 %tid
90 %load = load <4 x i8>, <4 x i8> addrspace(1)* %gep, align 1
91 %cvt = uitofp <4 x i8> %load to <4 x float>
92 store <4 x float> %cvt, <4 x float> addrspace(1)* %out, align 16
96 ; FIXME: Need to handle non-uniform case for function below (load without gep).
97 ; Instructions still emitted to repack bytes for add use.
99 ; GCN-LABEL: {{^}}load_v4i8_to_v4f32_2_uses:
100 ; GCN: {{buffer|flat}}_load_dword
101 ; GCN-DAG: v_cvt_f32_ubyte0_e32
102 ; GCN-DAG: v_cvt_f32_ubyte1_e32
103 ; GCN-DAG: v_cvt_f32_ubyte2_e32
104 ; GCN-DAG: v_cvt_f32_ubyte3_e32
106 ; GCN-DAG: v_lshrrev_b32_e32 v{{[0-9]+}}, 24
108 ; SI-DAG: v_lshlrev_b32_e32 v{{[0-9]+}}, 16
109 ; SI-DAG: v_lshlrev_b32_e32 v{{[0-9]+}}, 8
110 ; SI-DAG: v_and_b32_e32 v{{[0-9]+}}, 0xffff,
111 ; SI-DAG: v_and_b32_e32 v{{[0-9]+}}, 0xff00,
114 ; VI-DAG: v_and_b32_e32 v{{[0-9]+}}, 0xffffff00,
115 ; VI-DAG: v_add_u16_e32
116 ; VI-DAG: v_add_u16_e32
118 ; GCN: {{buffer|flat}}_store_dwordx4
119 ; GCN: {{buffer|flat}}_store_dword
122 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 {
123 %tid.x = call i32 @llvm.amdgcn.workitem.id.x()
124 %in.ptr = getelementptr <4 x i8>, <4 x i8> addrspace(1)* %in, i32 %tid.x
125 %load = load <4 x i8>, <4 x i8> addrspace(1)* %in.ptr, align 4
126 %cvt = uitofp <4 x i8> %load to <4 x float>
127 store <4 x float> %cvt, <4 x float> addrspace(1)* %out, align 16
128 %add = add <4 x i8> %load, <i8 9, i8 9, i8 9, i8 9> ; Second use of %load
129 store <4 x i8> %add, <4 x i8> addrspace(1)* %out2, align 4
133 ; Make sure this doesn't crash.
134 ; GCN-LABEL: {{^}}load_v7i8_to_v7f32:
136 define amdgpu_kernel void @load_v7i8_to_v7f32(<7 x float> addrspace(1)* noalias %out, <7 x i8> addrspace(1)* noalias %in) nounwind {
137 %tid = call i32 @llvm.amdgcn.workitem.id.x()
138 %gep = getelementptr <7 x i8>, <7 x i8> addrspace(1)* %in, i32 %tid
139 %load = load <7 x i8>, <7 x i8> addrspace(1)* %gep, align 1
140 %cvt = uitofp <7 x i8> %load to <7 x float>
141 store <7 x float> %cvt, <7 x float> addrspace(1)* %out, align 16
145 ; GCN-LABEL: {{^}}load_v8i8_to_v8f32:
146 ; GCN: {{buffer|flat}}_load_dwordx2 v{{\[}}[[LOLOAD:[0-9]+]]:[[HILOAD:[0-9]+]]{{\]}},
149 ; GCN-DAG: v_cvt_f32_ubyte3_e32 v{{[0-9]+}}, v[[LOLOAD]]
150 ; GCN-DAG: v_cvt_f32_ubyte2_e32 v{{[0-9]+}}, v[[LOLOAD]]
151 ; GCN-DAG: v_cvt_f32_ubyte1_e32 v{{[0-9]+}}, v[[LOLOAD]]
152 ; GCN-DAG: v_cvt_f32_ubyte0_e32 v{{[0-9]+}}, v[[LOLOAD]]
153 ; GCN-DAG: v_cvt_f32_ubyte3_e32 v{{[0-9]+}}, v[[HILOAD]]
154 ; GCN-DAG: v_cvt_f32_ubyte2_e32 v{{[0-9]+}}, v[[HILOAD]]
155 ; GCN-DAG: v_cvt_f32_ubyte1_e32 v{{[0-9]+}}, v[[HILOAD]]
156 ; GCN-DAG: v_cvt_f32_ubyte0_e32 v{{[0-9]+}}, v[[HILOAD]]
159 ; GCN: buffer_store_dwordx4
160 ; GCN: buffer_store_dwordx4
161 define amdgpu_kernel void @load_v8i8_to_v8f32(<8 x float> addrspace(1)* noalias %out, <8 x i8> addrspace(1)* noalias %in) nounwind {
162 %tid = call i32 @llvm.amdgcn.workitem.id.x()
163 %gep = getelementptr <8 x i8>, <8 x i8> addrspace(1)* %in, i32 %tid
164 %load = load <8 x i8>, <8 x i8> addrspace(1)* %gep, align 8
165 %cvt = uitofp <8 x i8> %load to <8 x float>
166 store <8 x float> %cvt, <8 x float> addrspace(1)* %out, align 16
170 ; GCN-LABEL: {{^}}i8_zext_inreg_i32_to_f32:
171 ; GCN: {{buffer|flat}}_load_dword [[LOADREG:v[0-9]+]],
172 ; GCN: v_add_i32_e32 [[ADD:v[0-9]+]], vcc, 2, [[LOADREG]]
173 ; GCN-NEXT: v_cvt_f32_ubyte0_e32 [[CONV:v[0-9]+]], [[ADD]]
174 ; GCN: buffer_store_dword [[CONV]],
175 define amdgpu_kernel void @i8_zext_inreg_i32_to_f32(float addrspace(1)* noalias %out, i32 addrspace(1)* noalias %in) nounwind {
176 %tid = call i32 @llvm.amdgcn.workitem.id.x()
177 %gep = getelementptr i32, i32 addrspace(1)* %in, i32 %tid
178 %load = load i32, i32 addrspace(1)* %gep, align 4
179 %add = add i32 %load, 2
180 %inreg = and i32 %add, 255
181 %cvt = uitofp i32 %inreg to float
182 store float %cvt, float addrspace(1)* %out, align 4
186 ; GCN-LABEL: {{^}}i8_zext_inreg_hi1_to_f32:
187 define amdgpu_kernel void @i8_zext_inreg_hi1_to_f32(float addrspace(1)* noalias %out, i32 addrspace(1)* noalias %in) nounwind {
188 %tid = call i32 @llvm.amdgcn.workitem.id.x()
189 %gep = getelementptr i32, i32 addrspace(1)* %in, i32 %tid
190 %load = load i32, i32 addrspace(1)* %gep, align 4
191 %inreg = and i32 %load, 65280
192 %shr = lshr i32 %inreg, 8
193 %cvt = uitofp i32 %shr to float
194 store float %cvt, float addrspace(1)* %out, align 4
198 ; We don't get these ones because of the zext, but instcombine removes
199 ; them so it shouldn't really matter.
200 ; GCN-LABEL: {{^}}i8_zext_i32_to_f32:
201 define amdgpu_kernel void @i8_zext_i32_to_f32(float addrspace(1)* noalias %out, i8 addrspace(1)* noalias %in) nounwind {
202 %tid = call i32 @llvm.amdgcn.workitem.id.x()
203 %gep = getelementptr i8, i8 addrspace(1)* %in, i32 %tid
204 %load = load i8, i8 addrspace(1)* %gep, align 1
205 %ext = zext i8 %load to i32
206 %cvt = uitofp i32 %ext to float
207 store float %cvt, float addrspace(1)* %out, align 4
211 ; GCN-LABEL: {{^}}v4i8_zext_v4i32_to_v4f32:
212 define amdgpu_kernel void @v4i8_zext_v4i32_to_v4f32(<4 x float> addrspace(1)* noalias %out, <4 x i8> addrspace(1)* noalias %in) nounwind {
213 %tid = call i32 @llvm.amdgcn.workitem.id.x()
214 %gep = getelementptr <4 x i8>, <4 x i8> addrspace(1)* %in, i32 %tid
215 %load = load <4 x i8>, <4 x i8> addrspace(1)* %gep, align 1
216 %ext = zext <4 x i8> %load to <4 x i32>
217 %cvt = uitofp <4 x i32> %ext to <4 x float>
218 store <4 x float> %cvt, <4 x float> addrspace(1)* %out, align 16
222 ; GCN-LABEL: {{^}}extract_byte0_to_f32:
223 ; GCN: {{buffer|flat}}_load_dword [[VAL:v[0-9]+]]
225 ; GCN: v_cvt_f32_ubyte0_e32 [[CONV:v[0-9]+]], [[VAL]]
226 ; GCN: buffer_store_dword [[CONV]]
227 define amdgpu_kernel void @extract_byte0_to_f32(float addrspace(1)* noalias %out, i32 addrspace(1)* noalias %in) nounwind {
228 %tid = call i32 @llvm.amdgcn.workitem.id.x()
229 %gep = getelementptr i32, i32 addrspace(1)* %in, i32 %tid
230 %val = load i32, i32 addrspace(1)* %gep
231 %and = and i32 %val, 255
232 %cvt = uitofp i32 %and to float
233 store float %cvt, float addrspace(1)* %out
237 ; GCN-LABEL: {{^}}extract_byte1_to_f32:
238 ; GCN: {{buffer|flat}}_load_dword [[VAL:v[0-9]+]]
240 ; GCN: v_cvt_f32_ubyte1_e32 [[CONV:v[0-9]+]], [[VAL]]
241 ; GCN: buffer_store_dword [[CONV]]
242 define amdgpu_kernel void @extract_byte1_to_f32(float addrspace(1)* noalias %out, i32 addrspace(1)* noalias %in) nounwind {
243 %tid = call i32 @llvm.amdgcn.workitem.id.x()
244 %gep = getelementptr i32, i32 addrspace(1)* %in, i32 %tid
245 %val = load i32, i32 addrspace(1)* %gep
246 %srl = lshr i32 %val, 8
247 %and = and i32 %srl, 255
248 %cvt = uitofp i32 %and to float
249 store float %cvt, float addrspace(1)* %out
253 ; GCN-LABEL: {{^}}extract_byte2_to_f32:
254 ; GCN: {{buffer|flat}}_load_dword [[VAL:v[0-9]+]]
256 ; GCN: v_cvt_f32_ubyte2_e32 [[CONV:v[0-9]+]], [[VAL]]
257 ; GCN: buffer_store_dword [[CONV]]
258 define amdgpu_kernel void @extract_byte2_to_f32(float addrspace(1)* noalias %out, i32 addrspace(1)* noalias %in) nounwind {
259 %tid = call i32 @llvm.amdgcn.workitem.id.x()
260 %gep = getelementptr i32, i32 addrspace(1)* %in, i32 %tid
261 %val = load i32, i32 addrspace(1)* %gep
262 %srl = lshr i32 %val, 16
263 %and = and i32 %srl, 255
264 %cvt = uitofp i32 %and to float
265 store float %cvt, float addrspace(1)* %out
269 ; GCN-LABEL: {{^}}extract_byte3_to_f32:
270 ; GCN: {{buffer|flat}}_load_dword [[VAL:v[0-9]+]]
272 ; GCN: v_cvt_f32_ubyte3_e32 [[CONV:v[0-9]+]], [[VAL]]
273 ; GCN: buffer_store_dword [[CONV]]
274 define amdgpu_kernel void @extract_byte3_to_f32(float addrspace(1)* noalias %out, i32 addrspace(1)* noalias %in) nounwind {
275 %tid = call i32 @llvm.amdgcn.workitem.id.x()
276 %gep = getelementptr i32, i32 addrspace(1)* %in, i32 %tid
277 %val = load i32, i32 addrspace(1)* %gep
278 %srl = lshr i32 %val, 24
279 %and = and i32 %srl, 255
280 %cvt = uitofp i32 %and to float
281 store float %cvt, float addrspace(1)* %out