1 ; RUN: llc -O0 -fast-isel -fast-isel-abort=1 -verify-machineinstrs -mtriple=arm64-apple-darwin -mcpu=cyclone < %s | FileCheck %s
3 ;; Test various conversions.
4 define zeroext i32 @trunc_(i8 zeroext %a, i16 zeroext %b, i32 %c, i64 %d) nounwind ssp {
7 ; CHECK: sub sp, sp, #16
8 ; CHECK: strb w0, [sp, #15]
9 ; CHECK: strh w1, [sp, #12]
10 ; CHECK: str w2, [sp, #8]
13 ; CHECK: ; kill: def $w8 killed $w8 killed $x8
14 ; CHECK: str w8, [sp, #8]
15 ; CHECK: ldr w8, [sp, #8]
16 ; CHECK: strh w8, [sp, #12]
17 ; CHECK: ldrh w8, [sp, #12]
18 ; CHECK: strb w8, [sp, #15]
19 ; CHECK: ldrb w0, [sp, #15]
20 ; CHECK: add sp, sp, #16
22 %a.addr = alloca i8, align 1
23 %b.addr = alloca i16, align 2
24 %c.addr = alloca i32, align 4
25 %d.addr = alloca i64, align 8
26 store i8 %a, i8* %a.addr, align 1
27 store i16 %b, i16* %b.addr, align 2
28 store i32 %c, i32* %c.addr, align 4
29 store i64 %d, i64* %d.addr, align 8
30 %tmp = load i64, i64* %d.addr, align 8
31 %conv = trunc i64 %tmp to i32
32 store i32 %conv, i32* %c.addr, align 4
33 %tmp1 = load i32, i32* %c.addr, align 4
34 %conv2 = trunc i32 %tmp1 to i16
35 store i16 %conv2, i16* %b.addr, align 2
36 %tmp3 = load i16, i16* %b.addr, align 2
37 %conv4 = trunc i16 %tmp3 to i8
38 store i8 %conv4, i8* %a.addr, align 1
39 %tmp5 = load i8, i8* %a.addr, align 1
40 %conv6 = zext i8 %tmp5 to i32
44 define i64 @zext_(i8 zeroext %a, i16 zeroext %b, i32 %c, i64 %d) nounwind ssp {
47 ; CHECK: sub sp, sp, #16
48 ; CHECK: strb w0, [sp, #15]
49 ; CHECK: strh w1, [sp, #12]
50 ; CHECK: str w2, [sp, #8]
52 ; CHECK: ldrb w8, [sp, #15]
53 ; CHECK: strh w8, [sp, #12]
54 ; CHECK: ldrh w8, [sp, #12]
55 ; CHECK: str w8, [sp, #8]
56 ; CHECK: ldr w8, [sp, #8]
61 %a.addr = alloca i8, align 1
62 %b.addr = alloca i16, align 2
63 %c.addr = alloca i32, align 4
64 %d.addr = alloca i64, align 8
65 store i8 %a, i8* %a.addr, align 1
66 store i16 %b, i16* %b.addr, align 2
67 store i32 %c, i32* %c.addr, align 4
68 store i64 %d, i64* %d.addr, align 8
69 %tmp = load i8, i8* %a.addr, align 1
70 %conv = zext i8 %tmp to i16
71 store i16 %conv, i16* %b.addr, align 2
72 %tmp1 = load i16, i16* %b.addr, align 2
73 %conv2 = zext i16 %tmp1 to i32
74 store i32 %conv2, i32* %c.addr, align 4
75 %tmp3 = load i32, i32* %c.addr, align 4
76 %conv4 = zext i32 %tmp3 to i64
77 store i64 %conv4, i64* %d.addr, align 8
78 %tmp5 = load i64, i64* %d.addr, align 8
82 define i32 @zext_i1_i32(i1 zeroext %a) nounwind ssp {
84 ; CHECK-LABEL: zext_i1_i32
85 ; CHECK-NOT: and w0, w0, #0x1
87 %conv = zext i1 %a to i32
91 define i64 @zext_i1_i64(i1 zeroext %a) nounwind ssp {
93 ; CHECK-LABEL: zext_i1_i64
94 ; CHECK-NOT: and w0, w0, #0x1
96 %conv = zext i1 %a to i64
100 define i64 @sext_(i8 signext %a, i16 signext %b, i32 %c, i64 %d) nounwind ssp {
103 ; CHECK: sub sp, sp, #16
104 ; CHECK: strb w0, [sp, #15]
105 ; CHECK: strh w1, [sp, #12]
106 ; CHECK: str w2, [sp, #8]
107 ; CHECK: str x3, [sp]
108 ; CHECK: ldrsb w8, [sp, #15]
109 ; CHECK: strh w8, [sp, #12]
110 ; CHECK: ldrsh w8, [sp, #12]
111 ; CHECK: str w8, [sp, #8]
112 ; CHECK: ldrsw x9, [sp, #8]
113 ; CHECK: str x9, [sp]
114 ; CHECK: ldr x0, [sp]
116 %a.addr = alloca i8, align 1
117 %b.addr = alloca i16, align 2
118 %c.addr = alloca i32, align 4
119 %d.addr = alloca i64, align 8
120 store i8 %a, i8* %a.addr, align 1
121 store i16 %b, i16* %b.addr, align 2
122 store i32 %c, i32* %c.addr, align 4
123 store i64 %d, i64* %d.addr, align 8
124 %tmp = load i8, i8* %a.addr, align 1
125 %conv = sext i8 %tmp to i16
126 store i16 %conv, i16* %b.addr, align 2
127 %tmp1 = load i16, i16* %b.addr, align 2
128 %conv2 = sext i16 %tmp1 to i32
129 store i32 %conv2, i32* %c.addr, align 4
130 %tmp3 = load i32, i32* %c.addr, align 4
131 %conv4 = sext i32 %tmp3 to i64
132 store i64 %conv4, i64* %d.addr, align 8
133 %tmp5 = load i64, i64* %d.addr, align 8
137 ; Test sext i8 to i64
139 define zeroext i64 @sext_i8_i64(i8 zeroext %in) {
140 ; CHECK-LABEL: sext_i8_i64:
141 ; CHECK: mov x[[TMP:[0-9]+]], x0
142 ; CHECK: sxtb x0, w[[TMP]]
143 %big = sext i8 %in to i64
147 define zeroext i64 @sext_i16_i64(i16 zeroext %in) {
148 ; CHECK-LABEL: sext_i16_i64:
149 ; CHECK: mov x[[TMP:[0-9]+]], x0
150 ; CHECK: sxth x0, w[[TMP]]
151 %big = sext i16 %in to i64
155 ; Test sext i1 to i32
156 define i32 @sext_i1_i32(i1 signext %a) nounwind ssp {
158 ; CHECK-LABEL: sext_i1_i32
159 ; CHECK-NOT: sbfx w0, w0, #0, #1
161 %conv = sext i1 %a to i32
165 ; Test sext i1 to i16
166 define signext i16 @sext_i1_i16(i1 %a) nounwind ssp {
168 ; CHECK-LABEL: sext_i1_i16
169 ; CHECK: sbfx w8, w0, #0, #1
170 ; CHECK-NEXT: sxth w0, w8
171 %conv = sext i1 %a to i16
176 define signext i8 @sext_i1_i8(i1 %a) nounwind ssp {
178 ; CHECK-LABEL: sext_i1_i8
179 ; CHECK: sbfx w8, w0, #0, #1
180 ; CHECK-NEXT: sxtb w0, w8
181 %conv = sext i1 %a to i8
186 define double @fpext_(float %a) nounwind ssp {
188 ; CHECK-LABEL: fpext_
190 %conv = fpext float %a to double
195 define float @fptrunc_(double %a) nounwind ssp {
197 ; CHECK-LABEL: fptrunc_
199 %conv = fptrunc double %a to float
204 define i32 @fptosi_ws(float %a) nounwind ssp {
206 ; CHECK-LABEL: fptosi_ws
207 ; CHECK: fcvtzs w0, s0
208 %conv = fptosi float %a to i32
213 define i32 @fptosi_wd(double %a) nounwind ssp {
215 ; CHECK-LABEL: fptosi_wd
216 ; CHECK: fcvtzs w0, d0
217 %conv = fptosi double %a to i32
222 define i32 @fptoui_ws(float %a) nounwind ssp {
224 ; CHECK-LABEL: fptoui_ws
225 ; CHECK: fcvtzu w0, s0
226 %conv = fptoui float %a to i32
231 define i32 @fptoui_wd(double %a) nounwind ssp {
233 ; CHECK-LABEL: fptoui_wd
234 ; CHECK: fcvtzu w0, d0
235 %conv = fptoui double %a to i32
240 define float @sitofp_sw_i1(i1 %a) nounwind ssp {
242 ; CHECK-LABEL: sitofp_sw_i1
243 ; CHECK: sbfx w8, w0, #0, #1
244 ; CHECK: scvtf s0, w8
245 %conv = sitofp i1 %a to float
250 define float @sitofp_sw_i8(i8 %a) nounwind ssp {
252 ; CHECK-LABEL: sitofp_sw_i8
254 ; CHECK: scvtf s0, w8
255 %conv = sitofp i8 %a to float
260 define float @sitofp_sw_i16(i16 %a) nounwind ssp {
262 ; CHECK-LABEL: sitofp_sw_i16
263 %conv = sitofp i16 %a to float
268 define float @sitofp_sw(i32 %a) nounwind ssp {
270 ; CHECK-LABEL: sitofp_sw
271 ; CHECK: scvtf s0, w0
272 %conv = sitofp i32 %a to float
277 define float @sitofp_sx(i64 %a) nounwind ssp {
279 ; CHECK-LABEL: sitofp_sx
280 ; CHECK: scvtf s0, x0
281 %conv = sitofp i64 %a to float
286 define double @sitofp_dw(i32 %a) nounwind ssp {
288 ; CHECK-LABEL: sitofp_dw
289 ; CHECK: scvtf d0, w0
290 %conv = sitofp i32 %a to double
295 define double @sitofp_dx(i64 %a) nounwind ssp {
297 ; CHECK-LABEL: sitofp_dx
298 ; CHECK: scvtf d0, x0
299 %conv = sitofp i64 %a to double
304 define float @uitofp_sw_i1(i1 %a) nounwind ssp {
306 ; CHECK-LABEL: uitofp_sw_i1
307 ; CHECK: and w8, w0, #0x1
308 ; CHECK: ucvtf s0, w8
309 %conv = uitofp i1 %a to float
314 define float @uitofp_sw_i8(i8 %a) nounwind ssp {
316 ; CHECK-LABEL: uitofp_sw_i8
317 %conv = uitofp i8 %a to float
322 define float @uitofp_sw_i16(i16 %a) nounwind ssp {
324 ; CHECK-LABEL: uitofp_sw_i16
325 %conv = uitofp i16 %a to float
330 define float @uitofp_sw(i32 %a) nounwind ssp {
332 ; CHECK-LABEL: uitofp_sw
333 ; CHECK: ucvtf s0, w0
334 %conv = uitofp i32 %a to float
339 define float @uitofp_sx(i64 %a) nounwind ssp {
341 ; CHECK-LABEL: uitofp_sx
342 ; CHECK: ucvtf s0, x0
343 %conv = uitofp i64 %a to float
348 define double @uitofp_dw(i32 %a) nounwind ssp {
350 ; CHECK-LABEL: uitofp_dw
351 ; CHECK: ucvtf d0, w0
352 %conv = uitofp i32 %a to double
357 define double @uitofp_dx(i64 %a) nounwind ssp {
359 ; CHECK-LABEL: uitofp_dx
360 ; CHECK: ucvtf d0, x0
361 %conv = uitofp i64 %a to double
365 define i32 @i64_trunc_i32(i64 %a) nounwind ssp {
367 ; CHECK-LABEL: i64_trunc_i32
370 %conv = trunc i64 %a to i32
374 define zeroext i16 @i64_trunc_i16(i64 %a) nounwind ssp {
376 ; CHECK-LABEL: i64_trunc_i16
377 ; CHECK: and [[REG2:w[0-9]+]], w0, #0xffff
378 ; CHECK: uxth w0, [[REG2]]
379 %conv = trunc i64 %a to i16
383 define zeroext i8 @i64_trunc_i8(i64 %a) nounwind ssp {
385 ; CHECK-LABEL: i64_trunc_i8
386 ; CHECK: and [[REG2:w[0-9]+]], w0, #0xff
387 ; CHECK: uxtb w0, [[REG2]]
388 %conv = trunc i64 %a to i8
392 define zeroext i1 @i64_trunc_i1(i64 %a) nounwind ssp {
394 ; CHECK-LABEL: i64_trunc_i1
395 ; CHECK: and [[REG2:w[0-9]+]], w0, #0x1
396 ; CHECK: and w0, [[REG2]], #0x1
397 %conv = trunc i64 %a to i1
402 define void @stack_trunc() nounwind {
403 ; CHECK-LABEL: stack_trunc
404 ; CHECK: sub sp, sp, #16
405 ; CHECK: ldr x[[REG:[0-9]+]], [sp]
406 ; CHECK: and [[REG3:w[0-9]+]], w[[REG]], #0xff
407 ; CHECK: strb [[REG3]], [sp, #15]
408 ; CHECK: add sp, sp, #16
409 %a = alloca i8, align 1
410 %b = alloca i64, align 8
411 %c = load i64, i64* %b, align 8
412 %d = trunc i64 %c to i8
413 store i8 %d, i8* %a, align 1
417 define zeroext i64 @zext_i8_i64(i8 zeroext %in) {
418 ; CHECK-LABEL: zext_i8_i64:
419 ; CHECK-NOT: ubfx x0, {{x[0-9]+}}, #0, #8
421 %big = zext i8 %in to i64
424 define zeroext i64 @zext_i16_i64(i16 zeroext %in) {
425 ; CHECK-LABEL: zext_i16_i64:
426 ; CHECK-NOT: ubfx x0, {{x[0-9]+}}, #0, #16
428 %big = zext i16 %in to i64
432 define float @bitcast_i32_to_float(i32 %a) {
433 %1 = bitcast i32 %a to float
437 define double @bitcast_i64_to_double(i64 %a) {
438 %1 = bitcast i64 %a to double
442 define i32 @bitcast_float_to_i32(float %a) {
443 %1 = bitcast float %a to i32
447 define i64 @bitcast_double_to_i64(double %a) {
448 %1 = bitcast double %a to i64