1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 3
2 ; RUN: llc --mtriple=loongarch64 --mattr=+lsx < %s | FileCheck %s
4 define void @buildvector_v16i8_splat(ptr %dst, i8 %a0) nounwind {
5 ; CHECK-LABEL: buildvector_v16i8_splat:
6 ; CHECK: # %bb.0: # %entry
7 ; CHECK-NEXT: vreplgr2vr.b $vr0, $a1
8 ; CHECK-NEXT: vst $vr0, $a0, 0
11 %insert = insertelement <16 x i8> undef, i8 %a0, i8 0
12 %splat = shufflevector <16 x i8> %insert, <16 x i8> undef, <16 x i32> zeroinitializer
13 store <16 x i8> %splat, ptr %dst
17 define void @buildvector_v8i16_splat(ptr %dst, i16 %a0) nounwind {
18 ; CHECK-LABEL: buildvector_v8i16_splat:
19 ; CHECK: # %bb.0: # %entry
20 ; CHECK-NEXT: vreplgr2vr.h $vr0, $a1
21 ; CHECK-NEXT: vst $vr0, $a0, 0
24 %insert = insertelement <8 x i16> undef, i16 %a0, i8 0
25 %splat = shufflevector <8 x i16> %insert, <8 x i16> undef, <8 x i32> zeroinitializer
26 store <8 x i16> %splat, ptr %dst
30 define void @buildvector_v4i32_splat(ptr %dst, i32 %a0) nounwind {
31 ; CHECK-LABEL: buildvector_v4i32_splat:
32 ; CHECK: # %bb.0: # %entry
33 ; CHECK-NEXT: vreplgr2vr.w $vr0, $a1
34 ; CHECK-NEXT: vst $vr0, $a0, 0
37 %insert = insertelement <4 x i32> undef, i32 %a0, i8 0
38 %splat = shufflevector <4 x i32> %insert, <4 x i32> undef, <4 x i32> zeroinitializer
39 store <4 x i32> %splat, ptr %dst
43 define void @buildvector_v2i64_splat(ptr %dst, i64 %a0) nounwind {
44 ; CHECK-LABEL: buildvector_v2i64_splat:
45 ; CHECK: # %bb.0: # %entry
46 ; CHECK-NEXT: vreplgr2vr.d $vr0, $a1
47 ; CHECK-NEXT: vst $vr0, $a0, 0
50 %insert = insertelement <2 x i64> undef, i64 %a0, i8 0
51 %splat = shufflevector <2 x i64> %insert, <2 x i64> undef, <2 x i32> zeroinitializer
52 store <2 x i64> %splat, ptr %dst
56 define void @buildvector_v4f32_splat(ptr %dst, float %a0) nounwind {
57 ; CHECK-LABEL: buildvector_v4f32_splat:
58 ; CHECK: # %bb.0: # %entry
59 ; CHECK-NEXT: # kill: def $f0 killed $f0 def $vr0
60 ; CHECK-NEXT: vreplvei.w $vr0, $vr0, 0
61 ; CHECK-NEXT: vst $vr0, $a0, 0
64 %insert = insertelement <4 x float> undef, float %a0, i8 0
65 %splat = shufflevector <4 x float> %insert, <4 x float> undef, <4 x i32> zeroinitializer
66 store <4 x float> %splat, ptr %dst
70 define void @buildvector_v2f64_splat(ptr %dst, double %a0) nounwind {
71 ; CHECK-LABEL: buildvector_v2f64_splat:
72 ; CHECK: # %bb.0: # %entry
73 ; CHECK-NEXT: # kill: def $f0_64 killed $f0_64 def $vr0
74 ; CHECK-NEXT: vreplvei.d $vr0, $vr0, 0
75 ; CHECK-NEXT: vst $vr0, $a0, 0
78 %insert = insertelement <2 x double> undef, double %a0, i8 0
79 %splat = shufflevector <2 x double> %insert, <2 x double> undef, <2 x i32> zeroinitializer
80 store <2 x double> %splat, ptr %dst
84 define void @buildvector_v16i8_const_splat(ptr %dst) nounwind {
85 ; CHECK-LABEL: buildvector_v16i8_const_splat:
86 ; CHECK: # %bb.0: # %entry
87 ; CHECK-NEXT: vrepli.b $vr0, 1
88 ; CHECK-NEXT: vst $vr0, $a0, 0
91 store <16 x i8> <i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1>, ptr %dst
95 define void @buildvector_v8i16_const_splat(ptr %dst) nounwind {
96 ; CHECK-LABEL: buildvector_v8i16_const_splat:
97 ; CHECK: # %bb.0: # %entry
98 ; CHECK-NEXT: vrepli.h $vr0, 1
99 ; CHECK-NEXT: vst $vr0, $a0, 0
102 store <8 x i16> <i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1>, ptr %dst
106 define void @buildvector_v4i32_const_splat(ptr %dst) nounwind {
107 ; CHECK-LABEL: buildvector_v4i32_const_splat:
108 ; CHECK: # %bb.0: # %entry
109 ; CHECK-NEXT: vrepli.w $vr0, 1
110 ; CHECK-NEXT: vst $vr0, $a0, 0
113 store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr %dst
117 define void @buildvector_v2i64_const_splat(ptr %dst) nounwind {
118 ; CHECK-LABEL: buildvector_v2i64_const_splat:
119 ; CHECK: # %bb.0: # %entry
120 ; CHECK-NEXT: vrepli.d $vr0, 1
121 ; CHECK-NEXT: vst $vr0, $a0, 0
124 store <2 x i64> <i64 1, i64 1>, ptr %dst
128 define void @buildvector_v2f32_const_splat(ptr %dst) nounwind {
129 ; CHECK-LABEL: buildvector_v2f32_const_splat:
130 ; CHECK: # %bb.0: # %entry
131 ; CHECK-NEXT: lu12i.w $a1, 260096
132 ; CHECK-NEXT: vreplgr2vr.w $vr0, $a1
133 ; CHECK-NEXT: vst $vr0, $a0, 0
136 store <4 x float> <float 1.0, float 1.0, float 1.0, float 1.0>, ptr %dst
140 define void @buildvector_v2f64_const_splat(ptr %dst) nounwind {
141 ; CHECK-LABEL: buildvector_v2f64_const_splat:
142 ; CHECK: # %bb.0: # %entry
143 ; CHECK-NEXT: lu52i.d $a1, $zero, 1023
144 ; CHECK-NEXT: vreplgr2vr.d $vr0, $a1
145 ; CHECK-NEXT: vst $vr0, $a0, 0
148 store <2 x double> <double 1.0, double 1.0>, ptr %dst
152 define void @buildvector_v16i8_const(ptr %dst) nounwind {
153 ; CHECK-LABEL: buildvector_v16i8_const:
154 ; CHECK: # %bb.0: # %entry
155 ; CHECK-NEXT: pcalau12i $a1, %pc_hi20(.LCPI12_0)
156 ; CHECK-NEXT: addi.d $a1, $a1, %pc_lo12(.LCPI12_0)
157 ; CHECK-NEXT: vld $vr0, $a1, 0
158 ; CHECK-NEXT: vst $vr0, $a0, 0
161 store <16 x i8> <i8 0, i8 1, i8 2, i8 3, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15>, ptr %dst
165 define void @buildvector_v8i16_const(ptr %dst) nounwind {
166 ; CHECK-LABEL: buildvector_v8i16_const:
167 ; CHECK: # %bb.0: # %entry
168 ; CHECK-NEXT: pcalau12i $a1, %pc_hi20(.LCPI13_0)
169 ; CHECK-NEXT: addi.d $a1, $a1, %pc_lo12(.LCPI13_0)
170 ; CHECK-NEXT: vld $vr0, $a1, 0
171 ; CHECK-NEXT: vst $vr0, $a0, 0
174 store <8 x i16> <i16 0, i16 1, i16 2, i16 3, i16 4, i16 5, i16 6, i16 7>, ptr %dst
178 define void @buildvector_v4i32_const(ptr %dst) nounwind {
179 ; CHECK-LABEL: buildvector_v4i32_const:
180 ; CHECK: # %bb.0: # %entry
181 ; CHECK-NEXT: pcalau12i $a1, %pc_hi20(.LCPI14_0)
182 ; CHECK-NEXT: addi.d $a1, $a1, %pc_lo12(.LCPI14_0)
183 ; CHECK-NEXT: vld $vr0, $a1, 0
184 ; CHECK-NEXT: vst $vr0, $a0, 0
187 store <4 x i32> <i32 0, i32 1, i32 2, i32 3>, ptr %dst
191 define void @buildvector_v2i64_const(ptr %dst) nounwind {
192 ; CHECK-LABEL: buildvector_v2i64_const:
193 ; CHECK: # %bb.0: # %entry
194 ; CHECK-NEXT: pcalau12i $a1, %pc_hi20(.LCPI15_0)
195 ; CHECK-NEXT: addi.d $a1, $a1, %pc_lo12(.LCPI15_0)
196 ; CHECK-NEXT: vld $vr0, $a1, 0
197 ; CHECK-NEXT: vst $vr0, $a0, 0
200 store <2 x i64> <i64 0, i64 1>, ptr %dst
204 define void @buildvector_v2f32_const(ptr %dst) nounwind {
205 ; CHECK-LABEL: buildvector_v2f32_const:
206 ; CHECK: # %bb.0: # %entry
207 ; CHECK-NEXT: pcalau12i $a1, %pc_hi20(.LCPI16_0)
208 ; CHECK-NEXT: addi.d $a1, $a1, %pc_lo12(.LCPI16_0)
209 ; CHECK-NEXT: vld $vr0, $a1, 0
210 ; CHECK-NEXT: vst $vr0, $a0, 0
213 store <4 x float> <float 0.0, float 1.0, float 2.0, float 3.0>, ptr %dst
217 define void @buildvector_v2f64_const(ptr %dst) nounwind {
218 ; CHECK-LABEL: buildvector_v2f64_const:
219 ; CHECK: # %bb.0: # %entry
220 ; CHECK-NEXT: pcalau12i $a1, %pc_hi20(.LCPI17_0)
221 ; CHECK-NEXT: addi.d $a1, $a1, %pc_lo12(.LCPI17_0)
222 ; CHECK-NEXT: vld $vr0, $a1, 0
223 ; CHECK-NEXT: vst $vr0, $a0, 0
226 store <2 x double> <double 0.0, double 1.0>, ptr %dst
230 define void @buildvector_v16i8(ptr %dst, i8 %a0, i8 %a1, i8 %a2, i8 %a3, i8 %a4, i8 %a5, i8 %a6, i8 %a7, i8 %a8, i8 %a9, i8 %a10, i8 %a11, i8 %a12, i8 %a13, i8 %a14, i8 %a15) nounwind {
231 ; CHECK-LABEL: buildvector_v16i8:
232 ; CHECK: # %bb.0: # %entry
233 ; CHECK-NEXT: ld.b $t0, $sp, 64
234 ; CHECK-NEXT: ld.b $t1, $sp, 56
235 ; CHECK-NEXT: ld.b $t2, $sp, 48
236 ; CHECK-NEXT: ld.b $t3, $sp, 40
237 ; CHECK-NEXT: ld.b $t4, $sp, 32
238 ; CHECK-NEXT: ld.b $t5, $sp, 24
239 ; CHECK-NEXT: ld.b $t6, $sp, 16
240 ; CHECK-NEXT: ld.b $t7, $sp, 8
241 ; CHECK-NEXT: ld.b $t8, $sp, 0
242 ; CHECK-NEXT: vinsgr2vr.b $vr0, $a1, 0
243 ; CHECK-NEXT: vinsgr2vr.b $vr0, $a2, 1
244 ; CHECK-NEXT: vinsgr2vr.b $vr0, $a3, 2
245 ; CHECK-NEXT: vinsgr2vr.b $vr0, $a4, 3
246 ; CHECK-NEXT: vinsgr2vr.b $vr0, $a5, 4
247 ; CHECK-NEXT: vinsgr2vr.b $vr0, $a6, 5
248 ; CHECK-NEXT: vinsgr2vr.b $vr0, $a7, 6
249 ; CHECK-NEXT: vinsgr2vr.b $vr0, $t8, 7
250 ; CHECK-NEXT: vinsgr2vr.b $vr0, $t7, 8
251 ; CHECK-NEXT: vinsgr2vr.b $vr0, $t6, 9
252 ; CHECK-NEXT: vinsgr2vr.b $vr0, $t5, 10
253 ; CHECK-NEXT: vinsgr2vr.b $vr0, $t4, 11
254 ; CHECK-NEXT: vinsgr2vr.b $vr0, $t3, 12
255 ; CHECK-NEXT: vinsgr2vr.b $vr0, $t2, 13
256 ; CHECK-NEXT: vinsgr2vr.b $vr0, $t1, 14
257 ; CHECK-NEXT: vinsgr2vr.b $vr0, $t0, 15
258 ; CHECK-NEXT: vst $vr0, $a0, 0
261 %ins0 = insertelement <16 x i8> undef, i8 %a0, i32 0
262 %ins1 = insertelement <16 x i8> %ins0, i8 %a1, i32 1
263 %ins2 = insertelement <16 x i8> %ins1, i8 %a2, i32 2
264 %ins3 = insertelement <16 x i8> %ins2, i8 %a3, i32 3
265 %ins4 = insertelement <16 x i8> %ins3, i8 %a4, i32 4
266 %ins5 = insertelement <16 x i8> %ins4, i8 %a5, i32 5
267 %ins6 = insertelement <16 x i8> %ins5, i8 %a6, i32 6
268 %ins7 = insertelement <16 x i8> %ins6, i8 %a7, i32 7
269 %ins8 = insertelement <16 x i8> %ins7, i8 %a8, i32 8
270 %ins9 = insertelement <16 x i8> %ins8, i8 %a9, i32 9
271 %ins10 = insertelement <16 x i8> %ins9, i8 %a10, i32 10
272 %ins11 = insertelement <16 x i8> %ins10, i8 %a11, i32 11
273 %ins12 = insertelement <16 x i8> %ins11, i8 %a12, i32 12
274 %ins13 = insertelement <16 x i8> %ins12, i8 %a13, i32 13
275 %ins14 = insertelement <16 x i8> %ins13, i8 %a14, i32 14
276 %ins15 = insertelement <16 x i8> %ins14, i8 %a15, i32 15
277 store <16 x i8> %ins15, ptr %dst
281 define void @buildvector_v8i16(ptr %dst, i16 %a0, i16 %a1, i16 %a2, i16 %a3, i16 %a4, i16 %a5, i16 %a6, i16 %a7) nounwind {
282 ; CHECK-LABEL: buildvector_v8i16:
283 ; CHECK: # %bb.0: # %entry
284 ; CHECK-NEXT: ld.h $t0, $sp, 0
285 ; CHECK-NEXT: vinsgr2vr.h $vr0, $a1, 0
286 ; CHECK-NEXT: vinsgr2vr.h $vr0, $a2, 1
287 ; CHECK-NEXT: vinsgr2vr.h $vr0, $a3, 2
288 ; CHECK-NEXT: vinsgr2vr.h $vr0, $a4, 3
289 ; CHECK-NEXT: vinsgr2vr.h $vr0, $a5, 4
290 ; CHECK-NEXT: vinsgr2vr.h $vr0, $a6, 5
291 ; CHECK-NEXT: vinsgr2vr.h $vr0, $a7, 6
292 ; CHECK-NEXT: vinsgr2vr.h $vr0, $t0, 7
293 ; CHECK-NEXT: vst $vr0, $a0, 0
296 %ins0 = insertelement <8 x i16> undef, i16 %a0, i32 0
297 %ins1 = insertelement <8 x i16> %ins0, i16 %a1, i32 1
298 %ins2 = insertelement <8 x i16> %ins1, i16 %a2, i32 2
299 %ins3 = insertelement <8 x i16> %ins2, i16 %a3, i32 3
300 %ins4 = insertelement <8 x i16> %ins3, i16 %a4, i32 4
301 %ins5 = insertelement <8 x i16> %ins4, i16 %a5, i32 5
302 %ins6 = insertelement <8 x i16> %ins5, i16 %a6, i32 6
303 %ins7 = insertelement <8 x i16> %ins6, i16 %a7, i32 7
304 store <8 x i16> %ins7, ptr %dst
308 define void @buildvector_v4i32(ptr %dst, i32 %a0, i32 %a1, i32 %a2, i32 %a3) nounwind {
309 ; CHECK-LABEL: buildvector_v4i32:
310 ; CHECK: # %bb.0: # %entry
311 ; CHECK-NEXT: vinsgr2vr.w $vr0, $a1, 0
312 ; CHECK-NEXT: vinsgr2vr.w $vr0, $a2, 1
313 ; CHECK-NEXT: vinsgr2vr.w $vr0, $a3, 2
314 ; CHECK-NEXT: vinsgr2vr.w $vr0, $a4, 3
315 ; CHECK-NEXT: vst $vr0, $a0, 0
318 %ins0 = insertelement <4 x i32> undef, i32 %a0, i32 0
319 %ins1 = insertelement <4 x i32> %ins0, i32 %a1, i32 1
320 %ins2 = insertelement <4 x i32> %ins1, i32 %a2, i32 2
321 %ins3 = insertelement <4 x i32> %ins2, i32 %a3, i32 3
322 store <4 x i32> %ins3, ptr %dst
326 define void @buildvector_v2i64(ptr %dst, i64 %a0, i64 %a1) nounwind {
327 ; CHECK-LABEL: buildvector_v2i64:
328 ; CHECK: # %bb.0: # %entry
329 ; CHECK-NEXT: vinsgr2vr.d $vr0, $a1, 0
330 ; CHECK-NEXT: vinsgr2vr.d $vr0, $a2, 1
331 ; CHECK-NEXT: vst $vr0, $a0, 0
334 %ins0 = insertelement <2 x i64> undef, i64 %a0, i32 0
335 %ins1 = insertelement <2 x i64> %ins0, i64 %a1, i32 1
336 store <2 x i64> %ins1, ptr %dst
340 define void @buildvector_v4f32(ptr %dst, float %a0, float %a1, float %a2, float %a3) nounwind {
341 ; CHECK-LABEL: buildvector_v4f32:
342 ; CHECK: # %bb.0: # %entry
343 ; CHECK-NEXT: movfr2gr.s $a1, $fa0
344 ; CHECK-NEXT: vinsgr2vr.w $vr0, $a1, 0
345 ; CHECK-NEXT: movfr2gr.s $a1, $fa1
346 ; CHECK-NEXT: vinsgr2vr.w $vr0, $a1, 1
347 ; CHECK-NEXT: movfr2gr.s $a1, $fa2
348 ; CHECK-NEXT: vinsgr2vr.w $vr0, $a1, 2
349 ; CHECK-NEXT: movfr2gr.s $a1, $fa3
350 ; CHECK-NEXT: vinsgr2vr.w $vr0, $a1, 3
351 ; CHECK-NEXT: vst $vr0, $a0, 0
354 %ins0 = insertelement <4 x float> undef, float %a0, i32 0
355 %ins1 = insertelement <4 x float> %ins0, float %a1, i32 1
356 %ins2 = insertelement <4 x float> %ins1, float %a2, i32 2
357 %ins3 = insertelement <4 x float> %ins2, float %a3, i32 3
358 store <4 x float> %ins3, ptr %dst
362 define void @buildvector_v2f64(ptr %dst, double %a0, double %a1) nounwind {
363 ; CHECK-LABEL: buildvector_v2f64:
364 ; CHECK: # %bb.0: # %entry
365 ; CHECK-NEXT: movfr2gr.d $a1, $fa0
366 ; CHECK-NEXT: vinsgr2vr.d $vr0, $a1, 0
367 ; CHECK-NEXT: movfr2gr.d $a1, $fa1
368 ; CHECK-NEXT: vinsgr2vr.d $vr0, $a1, 1
369 ; CHECK-NEXT: vst $vr0, $a0, 0
372 %ins0 = insertelement <2 x double> undef, double %a0, i32 0
373 %ins1 = insertelement <2 x double> %ins0, double %a1, i32 1
374 store <2 x double> %ins1, ptr %dst
378 ;; BUILD_VECTOR through stack.
379 ;; If `isShuffleMaskLegal` returns true, it will lead to an infinite loop.
380 define void @extract1_i32_zext_insert0_i64_undef(ptr %src, ptr %dst) nounwind {
381 ; CHECK-LABEL: extract1_i32_zext_insert0_i64_undef:
383 ; CHECK-NEXT: addi.d $sp, $sp, -16
384 ; CHECK-NEXT: vld $vr0, $a0, 0
385 ; CHECK-NEXT: vpickve2gr.w $a0, $vr0, 1
386 ; CHECK-NEXT: bstrpick.d $a0, $a0, 31, 0
387 ; CHECK-NEXT: st.d $a0, $sp, 0
388 ; CHECK-NEXT: vld $vr0, $sp, 0
389 ; CHECK-NEXT: vst $vr0, $a1, 0
390 ; CHECK-NEXT: addi.d $sp, $sp, 16
392 %v = load volatile <4 x i32>, ptr %src
393 %e = extractelement <4 x i32> %v, i32 1
394 %z = zext i32 %e to i64
395 %r = insertelement <2 x i64> undef, i64 %z, i32 0
396 store <2 x i64> %r, ptr %dst