1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -O0 -mtriple=mipsel-linux-gnu -global-isel -verify-machineinstrs %s -o -| FileCheck %s -check-prefixes=MIPS32,FP32
3 ; RUN: llc -O0 -mtriple=mipsel-linux-gnu -mattr=+fp64,+mips32r2 -global-isel -verify-machineinstrs %s -o -| FileCheck %s -check-prefixes=MIPS32,FP64
5 define i64 @f32toi64(float %a) {
6 ; MIPS32-LABEL: f32toi64:
7 ; MIPS32: # %bb.0: # %entry
8 ; MIPS32-NEXT: addiu $sp, $sp, -24
9 ; MIPS32-NEXT: .cfi_def_cfa_offset 24
10 ; MIPS32-NEXT: sw $ra, 20($sp) # 4-byte Folded Spill
11 ; MIPS32-NEXT: .cfi_offset 31, -4
12 ; MIPS32-NEXT: jal __fixsfdi
14 ; MIPS32-NEXT: lw $ra, 20($sp) # 4-byte Folded Reload
15 ; MIPS32-NEXT: addiu $sp, $sp, 24
19 %conv = fptosi float %a to i64
23 define i32 @f32toi32(float %a) {
24 ; MIPS32-LABEL: f32toi32:
25 ; MIPS32: # %bb.0: # %entry
26 ; MIPS32-NEXT: trunc.w.s $f0, $f12
27 ; MIPS32-NEXT: mfc1 $2, $f0
31 %conv = fptosi float %a to i32
35 define signext i16 @f32toi16(float %a) {
36 ; MIPS32-LABEL: f32toi16:
37 ; MIPS32: # %bb.0: # %entry
38 ; MIPS32-NEXT: trunc.w.s $f0, $f12
39 ; MIPS32-NEXT: mfc1 $1, $f0
40 ; MIPS32-NEXT: sll $1, $1, 16
41 ; MIPS32-NEXT: sra $2, $1, 16
45 %conv = fptosi float %a to i16
49 define signext i8 @f32toi8(float %a) {
50 ; MIPS32-LABEL: f32toi8:
51 ; MIPS32: # %bb.0: # %entry
52 ; MIPS32-NEXT: trunc.w.s $f0, $f12
53 ; MIPS32-NEXT: mfc1 $1, $f0
54 ; MIPS32-NEXT: sll $1, $1, 24
55 ; MIPS32-NEXT: sra $2, $1, 24
59 %conv = fptosi float %a to i8
63 define i64 @f64toi64(double %a) {
64 ; MIPS32-LABEL: f64toi64:
65 ; MIPS32: # %bb.0: # %entry
66 ; MIPS32-NEXT: addiu $sp, $sp, -24
67 ; MIPS32-NEXT: .cfi_def_cfa_offset 24
68 ; MIPS32-NEXT: sw $ra, 20($sp) # 4-byte Folded Spill
69 ; MIPS32-NEXT: .cfi_offset 31, -4
70 ; MIPS32-NEXT: jal __fixdfdi
72 ; MIPS32-NEXT: lw $ra, 20($sp) # 4-byte Folded Reload
73 ; MIPS32-NEXT: addiu $sp, $sp, 24
77 %conv = fptosi double %a to i64
81 define i32 @f64toi32(double %a) {
82 ; MIPS32-LABEL: f64toi32:
83 ; MIPS32: # %bb.0: # %entry
84 ; MIPS32-NEXT: trunc.w.d $f0, $f12
85 ; MIPS32-NEXT: mfc1 $2, $f0
89 %conv = fptosi double %a to i32
93 define signext i16 @f64toi16(double %a) {
94 ; MIPS32-LABEL: f64toi16:
95 ; MIPS32: # %bb.0: # %entry
96 ; MIPS32-NEXT: trunc.w.d $f0, $f12
97 ; MIPS32-NEXT: mfc1 $1, $f0
98 ; MIPS32-NEXT: sll $1, $1, 16
99 ; MIPS32-NEXT: sra $2, $1, 16
100 ; MIPS32-NEXT: jr $ra
103 %conv = fptosi double %a to i16
107 define signext i8 @f64toi8(double %a) {
108 ; MIPS32-LABEL: f64toi8:
109 ; MIPS32: # %bb.0: # %entry
110 ; MIPS32-NEXT: trunc.w.d $f0, $f12
111 ; MIPS32-NEXT: mfc1 $1, $f0
112 ; MIPS32-NEXT: sll $1, $1, 24
113 ; MIPS32-NEXT: sra $2, $1, 24
114 ; MIPS32-NEXT: jr $ra
117 %conv = fptosi double %a to i8
121 define i64 @f32tou64(float %a) {
122 ; MIPS32-LABEL: f32tou64:
123 ; MIPS32: # %bb.0: # %entry
124 ; MIPS32-NEXT: addiu $sp, $sp, -24
125 ; MIPS32-NEXT: .cfi_def_cfa_offset 24
126 ; MIPS32-NEXT: sw $ra, 20($sp) # 4-byte Folded Spill
127 ; MIPS32-NEXT: .cfi_offset 31, -4
128 ; MIPS32-NEXT: jal __fixunssfdi
130 ; MIPS32-NEXT: lw $ra, 20($sp) # 4-byte Folded Reload
131 ; MIPS32-NEXT: addiu $sp, $sp, 24
132 ; MIPS32-NEXT: jr $ra
135 %conv = fptoui float %a to i64
139 define i32 @f32tou32(float %a) {
140 ; MIPS32-LABEL: f32tou32:
141 ; MIPS32: # %bb.0: # %entry
142 ; MIPS32-NEXT: trunc.w.s $f0, $f12
143 ; MIPS32-NEXT: mfc1 $1, $f0
144 ; MIPS32-NEXT: lui $2, 20224
145 ; MIPS32-NEXT: mtc1 $2, $f0
146 ; MIPS32-NEXT: sub.s $f1, $f12, $f0
147 ; MIPS32-NEXT: trunc.w.s $f1, $f1
148 ; MIPS32-NEXT: mfc1 $2, $f1
149 ; MIPS32-NEXT: lui $3, 32768
150 ; MIPS32-NEXT: xor $2, $2, $3
151 ; MIPS32-NEXT: addiu $3, $zero, 1
152 ; MIPS32-NEXT: c.ult.s $f12, $f0
153 ; MIPS32-NEXT: movf $3, $zero, $fcc0
154 ; MIPS32-NEXT: movn $2, $1, $3
155 ; MIPS32-NEXT: jr $ra
158 %conv = fptoui float %a to i32
162 define zeroext i16 @f32tou16(float %a) {
163 ; MIPS32-LABEL: f32tou16:
164 ; MIPS32: # %bb.0: # %entry
165 ; MIPS32-NEXT: trunc.w.s $f0, $f12
166 ; MIPS32-NEXT: mfc1 $1, $f0
167 ; MIPS32-NEXT: lui $2, 20224
168 ; MIPS32-NEXT: mtc1 $2, $f0
169 ; MIPS32-NEXT: sub.s $f1, $f12, $f0
170 ; MIPS32-NEXT: trunc.w.s $f1, $f1
171 ; MIPS32-NEXT: mfc1 $2, $f1
172 ; MIPS32-NEXT: lui $3, 32768
173 ; MIPS32-NEXT: xor $2, $2, $3
174 ; MIPS32-NEXT: addiu $3, $zero, 1
175 ; MIPS32-NEXT: c.ult.s $f12, $f0
176 ; MIPS32-NEXT: movf $3, $zero, $fcc0
177 ; MIPS32-NEXT: movn $2, $1, $3
178 ; MIPS32-NEXT: ori $1, $zero, 65535
179 ; MIPS32-NEXT: and $2, $2, $1
180 ; MIPS32-NEXT: jr $ra
183 %conv = fptoui float %a to i16
187 define zeroext i8 @f32tou8(float %a) {
188 ; MIPS32-LABEL: f32tou8:
189 ; MIPS32: # %bb.0: # %entry
190 ; MIPS32-NEXT: trunc.w.s $f0, $f12
191 ; MIPS32-NEXT: mfc1 $1, $f0
192 ; MIPS32-NEXT: lui $2, 20224
193 ; MIPS32-NEXT: mtc1 $2, $f0
194 ; MIPS32-NEXT: sub.s $f1, $f12, $f0
195 ; MIPS32-NEXT: trunc.w.s $f1, $f1
196 ; MIPS32-NEXT: mfc1 $2, $f1
197 ; MIPS32-NEXT: lui $3, 32768
198 ; MIPS32-NEXT: xor $2, $2, $3
199 ; MIPS32-NEXT: addiu $3, $zero, 1
200 ; MIPS32-NEXT: c.ult.s $f12, $f0
201 ; MIPS32-NEXT: movf $3, $zero, $fcc0
202 ; MIPS32-NEXT: movn $2, $1, $3
203 ; MIPS32-NEXT: ori $1, $zero, 255
204 ; MIPS32-NEXT: and $2, $2, $1
205 ; MIPS32-NEXT: jr $ra
208 %conv = fptoui float %a to i8
212 define i64 @f64tou64(double %a) {
213 ; MIPS32-LABEL: f64tou64:
214 ; MIPS32: # %bb.0: # %entry
215 ; MIPS32-NEXT: addiu $sp, $sp, -24
216 ; MIPS32-NEXT: .cfi_def_cfa_offset 24
217 ; MIPS32-NEXT: sw $ra, 20($sp) # 4-byte Folded Spill
218 ; MIPS32-NEXT: .cfi_offset 31, -4
219 ; MIPS32-NEXT: jal __fixunsdfdi
221 ; MIPS32-NEXT: lw $ra, 20($sp) # 4-byte Folded Reload
222 ; MIPS32-NEXT: addiu $sp, $sp, 24
223 ; MIPS32-NEXT: jr $ra
226 %conv = fptoui double %a to i64
230 define i32 @f64tou32(double %a) {
231 ; FP32-LABEL: f64tou32:
232 ; FP32: # %bb.0: # %entry
233 ; FP32-NEXT: trunc.w.d $f0, $f12
234 ; FP32-NEXT: mfc1 $1, $f0
235 ; FP32-NEXT: lui $2, 16864
236 ; FP32-NEXT: ori $3, $zero, 0
237 ; FP32-NEXT: mtc1 $3, $f2
238 ; FP32-NEXT: mtc1 $2, $f3
239 ; FP32-NEXT: sub.d $f4, $f12, $f2
240 ; FP32-NEXT: trunc.w.d $f0, $f4
241 ; FP32-NEXT: mfc1 $2, $f0
242 ; FP32-NEXT: lui $3, 32768
243 ; FP32-NEXT: xor $2, $2, $3
244 ; FP32-NEXT: addiu $3, $zero, 1
245 ; FP32-NEXT: c.ult.d $f12, $f2
246 ; FP32-NEXT: movf $3, $zero, $fcc0
247 ; FP32-NEXT: movn $2, $1, $3
251 ; FP64-LABEL: f64tou32:
252 ; FP64: # %bb.0: # %entry
253 ; FP64-NEXT: trunc.w.d $f0, $f12
254 ; FP64-NEXT: mfc1 $1, $f0
255 ; FP64-NEXT: lui $2, 16864
256 ; FP64-NEXT: ori $3, $zero, 0
257 ; FP64-NEXT: mtc1 $3, $f1
258 ; FP64-NEXT: mthc1 $2, $f1
259 ; FP64-NEXT: sub.d $f2, $f12, $f1
260 ; FP64-NEXT: trunc.w.d $f0, $f2
261 ; FP64-NEXT: mfc1 $2, $f0
262 ; FP64-NEXT: lui $3, 32768
263 ; FP64-NEXT: xor $2, $2, $3
264 ; FP64-NEXT: addiu $3, $zero, 1
265 ; FP64-NEXT: c.ult.d $f12, $f1
266 ; FP64-NEXT: movf $3, $zero, $fcc0
267 ; FP64-NEXT: movn $2, $1, $3
271 %conv = fptoui double %a to i32
275 define zeroext i16 @f64tou16(double %a) {
276 ; FP32-LABEL: f64tou16:
277 ; FP32: # %bb.0: # %entry
278 ; FP32-NEXT: trunc.w.d $f0, $f12
279 ; FP32-NEXT: mfc1 $1, $f0
280 ; FP32-NEXT: lui $2, 16864
281 ; FP32-NEXT: ori $3, $zero, 0
282 ; FP32-NEXT: mtc1 $3, $f2
283 ; FP32-NEXT: mtc1 $2, $f3
284 ; FP32-NEXT: sub.d $f4, $f12, $f2
285 ; FP32-NEXT: trunc.w.d $f0, $f4
286 ; FP32-NEXT: mfc1 $2, $f0
287 ; FP32-NEXT: lui $3, 32768
288 ; FP32-NEXT: xor $2, $2, $3
289 ; FP32-NEXT: addiu $3, $zero, 1
290 ; FP32-NEXT: c.ult.d $f12, $f2
291 ; FP32-NEXT: movf $3, $zero, $fcc0
292 ; FP32-NEXT: movn $2, $1, $3
293 ; FP32-NEXT: ori $1, $zero, 65535
294 ; FP32-NEXT: and $2, $2, $1
298 ; FP64-LABEL: f64tou16:
299 ; FP64: # %bb.0: # %entry
300 ; FP64-NEXT: trunc.w.d $f0, $f12
301 ; FP64-NEXT: mfc1 $1, $f0
302 ; FP64-NEXT: lui $2, 16864
303 ; FP64-NEXT: ori $3, $zero, 0
304 ; FP64-NEXT: mtc1 $3, $f1
305 ; FP64-NEXT: mthc1 $2, $f1
306 ; FP64-NEXT: sub.d $f2, $f12, $f1
307 ; FP64-NEXT: trunc.w.d $f0, $f2
308 ; FP64-NEXT: mfc1 $2, $f0
309 ; FP64-NEXT: lui $3, 32768
310 ; FP64-NEXT: xor $2, $2, $3
311 ; FP64-NEXT: addiu $3, $zero, 1
312 ; FP64-NEXT: c.ult.d $f12, $f1
313 ; FP64-NEXT: movf $3, $zero, $fcc0
314 ; FP64-NEXT: movn $2, $1, $3
315 ; FP64-NEXT: ori $1, $zero, 65535
316 ; FP64-NEXT: and $2, $2, $1
320 %conv = fptoui double %a to i16
324 define zeroext i8 @f64tou8(double %a) {
325 ; FP32-LABEL: f64tou8:
326 ; FP32: # %bb.0: # %entry
327 ; FP32-NEXT: trunc.w.d $f0, $f12
328 ; FP32-NEXT: mfc1 $1, $f0
329 ; FP32-NEXT: lui $2, 16864
330 ; FP32-NEXT: ori $3, $zero, 0
331 ; FP32-NEXT: mtc1 $3, $f2
332 ; FP32-NEXT: mtc1 $2, $f3
333 ; FP32-NEXT: sub.d $f4, $f12, $f2
334 ; FP32-NEXT: trunc.w.d $f0, $f4
335 ; FP32-NEXT: mfc1 $2, $f0
336 ; FP32-NEXT: lui $3, 32768
337 ; FP32-NEXT: xor $2, $2, $3
338 ; FP32-NEXT: addiu $3, $zero, 1
339 ; FP32-NEXT: c.ult.d $f12, $f2
340 ; FP32-NEXT: movf $3, $zero, $fcc0
341 ; FP32-NEXT: movn $2, $1, $3
342 ; FP32-NEXT: ori $1, $zero, 255
343 ; FP32-NEXT: and $2, $2, $1
347 ; FP64-LABEL: f64tou8:
348 ; FP64: # %bb.0: # %entry
349 ; FP64-NEXT: trunc.w.d $f0, $f12
350 ; FP64-NEXT: mfc1 $1, $f0
351 ; FP64-NEXT: lui $2, 16864
352 ; FP64-NEXT: ori $3, $zero, 0
353 ; FP64-NEXT: mtc1 $3, $f1
354 ; FP64-NEXT: mthc1 $2, $f1
355 ; FP64-NEXT: sub.d $f2, $f12, $f1
356 ; FP64-NEXT: trunc.w.d $f0, $f2
357 ; FP64-NEXT: mfc1 $2, $f0
358 ; FP64-NEXT: lui $3, 32768
359 ; FP64-NEXT: xor $2, $2, $3
360 ; FP64-NEXT: addiu $3, $zero, 1
361 ; FP64-NEXT: c.ult.d $f12, $f1
362 ; FP64-NEXT: movf $3, $zero, $fcc0
363 ; FP64-NEXT: movn $2, $1, $3
364 ; FP64-NEXT: ori $1, $zero, 255
365 ; FP64-NEXT: and $2, $2, $1
369 %conv = fptoui double %a to i8