Improve long vector sext/zext lowering on ARM
[oota-llvm.git] / test / CodeGen / ARM / vcvt.ll
1 ; RUN: llc < %s -march=arm -mattr=+neon,+fp16 | FileCheck %s
2
3 define <2 x i32> @vcvt_f32tos32(<2 x float>* %A) nounwind {
4 ;CHECK: vcvt_f32tos32:
5 ;CHECK: vcvt.s32.f32
6         %tmp1 = load <2 x float>* %A
7         %tmp2 = fptosi <2 x float> %tmp1 to <2 x i32>
8         ret <2 x i32> %tmp2
9 }
10
11 define <2 x i32> @vcvt_f32tou32(<2 x float>* %A) nounwind {
12 ;CHECK: vcvt_f32tou32:
13 ;CHECK: vcvt.u32.f32
14         %tmp1 = load <2 x float>* %A
15         %tmp2 = fptoui <2 x float> %tmp1 to <2 x i32>
16         ret <2 x i32> %tmp2
17 }
18
19 define <2 x float> @vcvt_s32tof32(<2 x i32>* %A) nounwind {
20 ;CHECK: vcvt_s32tof32:
21 ;CHECK: vcvt.f32.s32
22         %tmp1 = load <2 x i32>* %A
23         %tmp2 = sitofp <2 x i32> %tmp1 to <2 x float>
24         ret <2 x float> %tmp2
25 }
26
27 define <2 x float> @vcvt_u32tof32(<2 x i32>* %A) nounwind {
28 ;CHECK: vcvt_u32tof32:
29 ;CHECK: vcvt.f32.u32
30         %tmp1 = load <2 x i32>* %A
31         %tmp2 = uitofp <2 x i32> %tmp1 to <2 x float>
32         ret <2 x float> %tmp2
33 }
34
35 define <4 x i32> @vcvtQ_f32tos32(<4 x float>* %A) nounwind {
36 ;CHECK: vcvtQ_f32tos32:
37 ;CHECK: vcvt.s32.f32
38         %tmp1 = load <4 x float>* %A
39         %tmp2 = fptosi <4 x float> %tmp1 to <4 x i32>
40         ret <4 x i32> %tmp2
41 }
42
43 define <4 x i32> @vcvtQ_f32tou32(<4 x float>* %A) nounwind {
44 ;CHECK: vcvtQ_f32tou32:
45 ;CHECK: vcvt.u32.f32
46         %tmp1 = load <4 x float>* %A
47         %tmp2 = fptoui <4 x float> %tmp1 to <4 x i32>
48         ret <4 x i32> %tmp2
49 }
50
51 define <4 x float> @vcvtQ_s32tof32(<4 x i32>* %A) nounwind {
52 ;CHECK: vcvtQ_s32tof32:
53 ;CHECK: vcvt.f32.s32
54         %tmp1 = load <4 x i32>* %A
55         %tmp2 = sitofp <4 x i32> %tmp1 to <4 x float>
56         ret <4 x float> %tmp2
57 }
58
59 define <4 x float> @vcvtQ_u32tof32(<4 x i32>* %A) nounwind {
60 ;CHECK: vcvtQ_u32tof32:
61 ;CHECK: vcvt.f32.u32
62         %tmp1 = load <4 x i32>* %A
63         %tmp2 = uitofp <4 x i32> %tmp1 to <4 x float>
64         ret <4 x float> %tmp2
65 }
66
67 define <2 x i32> @vcvt_n_f32tos32(<2 x float>* %A) nounwind {
68 ;CHECK: vcvt_n_f32tos32:
69 ;CHECK: vcvt.s32.f32
70         %tmp1 = load <2 x float>* %A
71         %tmp2 = call <2 x i32> @llvm.arm.neon.vcvtfp2fxs.v2i32.v2f32(<2 x float> %tmp1, i32 1)
72         ret <2 x i32> %tmp2
73 }
74
75 define <2 x i32> @vcvt_n_f32tou32(<2 x float>* %A) nounwind {
76 ;CHECK: vcvt_n_f32tou32:
77 ;CHECK: vcvt.u32.f32
78         %tmp1 = load <2 x float>* %A
79         %tmp2 = call <2 x i32> @llvm.arm.neon.vcvtfp2fxu.v2i32.v2f32(<2 x float> %tmp1, i32 1)
80         ret <2 x i32> %tmp2
81 }
82
83 define <2 x float> @vcvt_n_s32tof32(<2 x i32>* %A) nounwind {
84 ;CHECK: vcvt_n_s32tof32:
85 ;CHECK: vcvt.f32.s32
86         %tmp1 = load <2 x i32>* %A
87         %tmp2 = call <2 x float> @llvm.arm.neon.vcvtfxs2fp.v2f32.v2i32(<2 x i32> %tmp1, i32 1)
88         ret <2 x float> %tmp2
89 }
90
91 define <2 x float> @vcvt_n_u32tof32(<2 x i32>* %A) nounwind {
92 ;CHECK: vcvt_n_u32tof32:
93 ;CHECK: vcvt.f32.u32
94         %tmp1 = load <2 x i32>* %A
95         %tmp2 = call <2 x float> @llvm.arm.neon.vcvtfxu2fp.v2f32.v2i32(<2 x i32> %tmp1, i32 1)
96         ret <2 x float> %tmp2
97 }
98
99 declare <2 x i32> @llvm.arm.neon.vcvtfp2fxs.v2i32.v2f32(<2 x float>, i32) nounwind readnone
100 declare <2 x i32> @llvm.arm.neon.vcvtfp2fxu.v2i32.v2f32(<2 x float>, i32) nounwind readnone
101 declare <2 x float> @llvm.arm.neon.vcvtfxs2fp.v2f32.v2i32(<2 x i32>, i32) nounwind readnone
102 declare <2 x float> @llvm.arm.neon.vcvtfxu2fp.v2f32.v2i32(<2 x i32>, i32) nounwind readnone
103
104 define <4 x i32> @vcvtQ_n_f32tos32(<4 x float>* %A) nounwind {
105 ;CHECK: vcvtQ_n_f32tos32:
106 ;CHECK: vcvt.s32.f32
107         %tmp1 = load <4 x float>* %A
108         %tmp2 = call <4 x i32> @llvm.arm.neon.vcvtfp2fxs.v4i32.v4f32(<4 x float> %tmp1, i32 1)
109         ret <4 x i32> %tmp2
110 }
111
112 define <4 x i32> @vcvtQ_n_f32tou32(<4 x float>* %A) nounwind {
113 ;CHECK: vcvtQ_n_f32tou32:
114 ;CHECK: vcvt.u32.f32
115         %tmp1 = load <4 x float>* %A
116         %tmp2 = call <4 x i32> @llvm.arm.neon.vcvtfp2fxu.v4i32.v4f32(<4 x float> %tmp1, i32 1)
117         ret <4 x i32> %tmp2
118 }
119
120 define <4 x float> @vcvtQ_n_s32tof32(<4 x i32>* %A) nounwind {
121 ;CHECK: vcvtQ_n_s32tof32:
122 ;CHECK: vcvt.f32.s32
123         %tmp1 = load <4 x i32>* %A
124         %tmp2 = call <4 x float> @llvm.arm.neon.vcvtfxs2fp.v4f32.v4i32(<4 x i32> %tmp1, i32 1)
125         ret <4 x float> %tmp2
126 }
127
128 define <4 x float> @vcvtQ_n_u32tof32(<4 x i32>* %A) nounwind {
129 ;CHECK: vcvtQ_n_u32tof32:
130 ;CHECK: vcvt.f32.u32
131         %tmp1 = load <4 x i32>* %A
132         %tmp2 = call <4 x float> @llvm.arm.neon.vcvtfxu2fp.v4f32.v4i32(<4 x i32> %tmp1, i32 1)
133         ret <4 x float> %tmp2
134 }
135
136 declare <4 x i32> @llvm.arm.neon.vcvtfp2fxs.v4i32.v4f32(<4 x float>, i32) nounwind readnone
137 declare <4 x i32> @llvm.arm.neon.vcvtfp2fxu.v4i32.v4f32(<4 x float>, i32) nounwind readnone
138 declare <4 x float> @llvm.arm.neon.vcvtfxs2fp.v4f32.v4i32(<4 x i32>, i32) nounwind readnone
139 declare <4 x float> @llvm.arm.neon.vcvtfxu2fp.v4f32.v4i32(<4 x i32>, i32) nounwind readnone
140
141 define <4 x float> @vcvt_f16tof32(<4 x i16>* %A) nounwind {
142 ;CHECK: vcvt_f16tof32:
143 ;CHECK: vcvt.f32.f16
144         %tmp1 = load <4 x i16>* %A
145         %tmp2 = call <4 x float> @llvm.arm.neon.vcvthf2fp(<4 x i16> %tmp1)
146         ret <4 x float> %tmp2
147 }
148
149 define <4 x i16> @vcvt_f32tof16(<4 x float>* %A) nounwind {
150 ;CHECK: vcvt_f32tof16:
151 ;CHECK: vcvt.f16.f32
152         %tmp1 = load <4 x float>* %A
153         %tmp2 = call <4 x i16> @llvm.arm.neon.vcvtfp2hf(<4 x float> %tmp1)
154         ret <4 x i16> %tmp2
155 }
156
157 declare <4 x float> @llvm.arm.neon.vcvthf2fp(<4 x i16>) nounwind readnone
158 declare <4 x i16> @llvm.arm.neon.vcvtfp2hf(<4 x float>) nounwind readnone
159
160 ; We currently estimate the cost of sext/zext/trunc v8(v16)i32 <-> v8(v16)i8
161 ; instructions as expensive. If lowering is improved the cost model needs to
162 ; change.
163 ; RUN: opt < %s  -cost-model -analyze -mtriple=thumbv7-apple-ios6.0.0 -march=arm -mcpu=cortex-a8 | FileCheck %s --check-prefix=COST
164 %T0_5 = type <8 x i8>
165 %T1_5 = type <8 x i32>
166 ; CHECK: func_cvt5:
167 define void @func_cvt5(%T0_5* %loadaddr, %T1_5* %storeaddr) {
168 ; CHECK: vmovl.s8
169 ; CHECK: vmovl.s16
170 ; CHECK: vmovl.s16
171   %v0 = load %T0_5* %loadaddr
172 ; COST: func_cvt5
173 ; COST: cost of 3 {{.*}} sext
174   %r = sext %T0_5 %v0 to %T1_5
175   store %T1_5 %r, %T1_5* %storeaddr
176   ret void
177 }
178 ;; We currently estimate the cost of this instruction as expensive. If lowering
179 ;; is improved the cost needs to change.
180 %TA0_5 = type <8 x i8>
181 %TA1_5 = type <8 x i32>
182 ; CHECK: func_cvt1:
183 define void @func_cvt1(%TA0_5* %loadaddr, %TA1_5* %storeaddr) {
184 ; CHECK: vmovl.u8
185 ; CHECK: vmovl.u16
186 ; CHECK: vmovl.u16
187   %v0 = load %TA0_5* %loadaddr
188 ; COST: func_cvt1
189 ; COST: cost of 3 {{.*}} zext
190   %r = zext %TA0_5 %v0 to %TA1_5
191   store %TA1_5 %r, %TA1_5* %storeaddr
192   ret void
193 }
194 ;; We currently estimate the cost of this instruction as expensive. If lowering
195 ;; is improved the cost needs to change.
196 %T0_51 = type <8 x i32>
197 %T1_51 = type <8 x i8>
198 ; CHECK: func_cvt51:
199 define void @func_cvt51(%T0_51* %loadaddr, %T1_51* %storeaddr) {
200 ; CHECK: strb
201 ; CHECK: strb
202 ; CHECK: strb
203 ; CHECK: strb
204 ; CHECK: strb
205 ; CHECK: strb
206 ; CHECK: strb
207 ; CHECK: strb
208   %v0 = load %T0_51* %loadaddr
209 ; COST: func_cvt51
210 ; COST: cost of 19 {{.*}} trunc
211   %r = trunc %T0_51 %v0 to %T1_51
212   store %T1_51 %r, %T1_51* %storeaddr
213   ret void
214 }
215 ;; We currently estimate the cost of this instruction as expensive. If lowering
216 ;; is improved the cost needs to change.
217 %TT0_5 = type <16 x i8>
218 %TT1_5 = type <16 x i32>
219 ; CHECK: func_cvt52:
220 define void @func_cvt52(%TT0_5* %loadaddr, %TT1_5* %storeaddr) {
221 ; CHECK: vmovl.s16
222 ; CHECK: vmovl.s16
223 ; CHECK: vmovl.s16
224 ; CHECK: vmovl.s16
225   %v0 = load %TT0_5* %loadaddr
226 ; COST: func_cvt52
227 ; COST: cost of 6 {{.*}} sext
228   %r = sext %TT0_5 %v0 to %TT1_5
229   store %TT1_5 %r, %TT1_5* %storeaddr
230   ret void
231 }
232 ;; We currently estimate the cost of this instruction as expensive. If lowering
233 ;; is improved the cost needs to change.
234 %TTA0_5 = type <16 x i8>
235 %TTA1_5 = type <16 x i32>
236 ; CHECK: func_cvt12:
237 define void @func_cvt12(%TTA0_5* %loadaddr, %TTA1_5* %storeaddr) {
238 ; CHECK: vmovl.u16
239 ; CHECK: vmovl.u16
240 ; CHECK: vmovl.u16
241 ; CHECK: vmovl.u16
242   %v0 = load %TTA0_5* %loadaddr
243 ; COST: func_cvt12
244 ; COST: cost of 6 {{.*}} zext
245   %r = zext %TTA0_5 %v0 to %TTA1_5
246   store %TTA1_5 %r, %TTA1_5* %storeaddr
247   ret void
248 }
249 ;; We currently estimate the cost of this instruction as expensive. If lowering
250 ;; is improved the cost needs to change.
251 %TT0_51 = type <16 x i32>
252 %TT1_51 = type <16 x i8>
253 ; CHECK: func_cvt512:
254 define void @func_cvt512(%TT0_51* %loadaddr, %TT1_51* %storeaddr) {
255 ; CHECK: strb
256 ; CHECK: strb
257 ; CHECK: strb
258 ; CHECK: strb
259 ; CHECK: strb
260 ; CHECK: strb
261 ; CHECK: strb
262 ; CHECK: strb
263 ; CHECK: strb
264 ; CHECK: strb
265 ; CHECK: strb
266 ; CHECK: strb
267 ; CHECK: strb
268 ; CHECK: strb
269 ; CHECK: strb
270 ; CHECK: strb
271   %v0 = load %TT0_51* %loadaddr
272 ; COST: func_cvt512
273 ; COST: cost of 38 {{.*}} trunc
274   %r = trunc %TT0_51 %v0 to %TT1_51
275   store %TT1_51 %r, %TT1_51* %storeaddr
276   ret void
277 }
278
279 ; CHECK: sext_v4i16_v4i64:
280 define void @sext_v4i16_v4i64(<4 x i16>* %loadaddr, <4 x i64>* %storeaddr) {
281 ; CHECK: vmovl.s32
282 ; CHECK: vmovl.s32
283   %v0 = load <4 x i16>* %loadaddr
284 ; COST: sext_v4i16_v4i64
285 ; COST: cost of 3 {{.*}} sext
286   %r = sext <4 x i16> %v0 to <4 x i64>
287   store <4 x i64> %r, <4 x i64>* %storeaddr
288   ret void
289 }
290
291 ; CHECK: zext_v4i16_v4i64:
292 define void @zext_v4i16_v4i64(<4 x i16>* %loadaddr, <4 x i64>* %storeaddr) {
293 ; CHECK: vmovl.u32
294 ; CHECK: vmovl.u32
295   %v0 = load <4 x i16>* %loadaddr
296 ; COST: zext_v4i16_v4i64
297 ; COST: cost of 3 {{.*}} zext
298   %r = zext <4 x i16> %v0 to <4 x i64>
299   store <4 x i64> %r, <4 x i64>* %storeaddr
300   ret void
301 }
302
303 ; CHECK: sext_v8i16_v8i64:
304 define void @sext_v8i16_v8i64(<8 x i16>* %loadaddr, <8 x i64>* %storeaddr) {
305 ; CHECK: vmovl.s32
306 ; CHECK: vmovl.s32
307 ; CHECK: vmovl.s32
308 ; CHECK: vmovl.s32
309   %v0 = load <8 x i16>* %loadaddr
310 ; COST: sext_v8i16_v8i64
311 ; COST: cost of 6 {{.*}} sext
312   %r = sext <8 x i16> %v0 to <8 x i64>
313   store <8 x i64> %r, <8 x i64>* %storeaddr
314   ret void
315 }
316
317 ; CHECK: zext_v8i16_v8i64:
318 define void @zext_v8i16_v8i64(<8 x i16>* %loadaddr, <8 x i64>* %storeaddr) {
319 ; CHECK: vmovl.u32
320 ; CHECK: vmovl.u32
321 ; CHECK: vmovl.u32
322 ; CHECK: vmovl.u32
323   %v0 = load <8 x i16>* %loadaddr
324 ; COST: zext_v8i16_v8i64
325 ; COST: cost of 6 {{.*}} zext
326   %r = zext <8 x i16> %v0 to <8 x i64>
327   store <8 x i64> %r, <8 x i64>* %storeaddr
328   ret void
329 }
330