Add a triple to switch.ll test.
[oota-llvm.git] / test / CodeGen / X86 / vec_extract-avx.ll
1 target triple = "x86_64-unknown-unknown"
2
3 ; RUN: llc < %s -march=x86-64 -mattr=+avx | FileCheck %s
4
5 ; When extracting multiple consecutive elements from a larger
6 ; vector into a smaller one, do it efficiently. We should use
7 ; an EXTRACT_SUBVECTOR node internally rather than a bunch of
8 ; single element extractions. 
9
10 ; Extracting the low elements only requires using the right kind of store.
11 define void @low_v8f32_to_v4f32(<8 x float> %v, <4 x float>* %ptr) {
12   %ext0 = extractelement <8 x float> %v, i32 0
13   %ext1 = extractelement <8 x float> %v, i32 1
14   %ext2 = extractelement <8 x float> %v, i32 2
15   %ext3 = extractelement <8 x float> %v, i32 3
16   %ins0 = insertelement <4 x float> undef, float %ext0, i32 0
17   %ins1 = insertelement <4 x float> %ins0, float %ext1, i32 1
18   %ins2 = insertelement <4 x float> %ins1, float %ext2, i32 2
19   %ins3 = insertelement <4 x float> %ins2, float %ext3, i32 3
20   store <4 x float> %ins3, <4 x float>* %ptr, align 16
21   ret void
22
23 ; CHECK-LABEL: low_v8f32_to_v4f32
24 ; CHECK: vmovaps
25 ; CHECK-NEXT: vzeroupper
26 ; CHECK-NEXT: retq
27 }
28
29 ; Extracting the high elements requires just one AVX instruction. 
30 define void @high_v8f32_to_v4f32(<8 x float> %v, <4 x float>* %ptr) {
31   %ext0 = extractelement <8 x float> %v, i32 4
32   %ext1 = extractelement <8 x float> %v, i32 5
33   %ext2 = extractelement <8 x float> %v, i32 6
34   %ext3 = extractelement <8 x float> %v, i32 7
35   %ins0 = insertelement <4 x float> undef, float %ext0, i32 0
36   %ins1 = insertelement <4 x float> %ins0, float %ext1, i32 1
37   %ins2 = insertelement <4 x float> %ins1, float %ext2, i32 2
38   %ins3 = insertelement <4 x float> %ins2, float %ext3, i32 3
39   store <4 x float> %ins3, <4 x float>* %ptr, align 16
40   ret void
41
42 ; CHECK-LABEL: high_v8f32_to_v4f32
43 ; CHECK: vextractf128
44 ; CHECK-NEXT: vzeroupper
45 ; CHECK-NEXT: retq
46 }
47
48 ; Make sure element type doesn't alter the codegen. Note that
49 ; if we were actually using the vector in this function and
50 ; have AVX2, we should generate vextracti128 (the int version).
51 define void @high_v8i32_to_v4i32(<8 x i32> %v, <4 x i32>* %ptr) {
52   %ext0 = extractelement <8 x i32> %v, i32 4
53   %ext1 = extractelement <8 x i32> %v, i32 5
54   %ext2 = extractelement <8 x i32> %v, i32 6
55   %ext3 = extractelement <8 x i32> %v, i32 7
56   %ins0 = insertelement <4 x i32> undef, i32 %ext0, i32 0
57   %ins1 = insertelement <4 x i32> %ins0, i32 %ext1, i32 1
58   %ins2 = insertelement <4 x i32> %ins1, i32 %ext2, i32 2
59   %ins3 = insertelement <4 x i32> %ins2, i32 %ext3, i32 3
60   store <4 x i32> %ins3, <4 x i32>* %ptr, align 16
61   ret void
62
63 ; CHECK-LABEL: high_v8i32_to_v4i32
64 ; CHECK: vextractf128
65 ; CHECK-NEXT: vzeroupper
66 ; CHECK-NEXT: retq
67 }
68
69 ; Make sure that element size doesn't alter the codegen.
70 define void @high_v4f64_to_v2f64(<4 x double> %v, <2 x double>* %ptr) {
71   %ext0 = extractelement <4 x double> %v, i32 2
72   %ext1 = extractelement <4 x double> %v, i32 3
73   %ins0 = insertelement <2 x double> undef, double %ext0, i32 0
74   %ins1 = insertelement <2 x double> %ins0, double %ext1, i32 1
75   store <2 x double> %ins1, <2 x double>* %ptr, align 16
76   ret void
77
78 ; CHECK-LABEL: high_v4f64_to_v2f64
79 ; CHECK: vextractf128
80 ; CHECK-NEXT: vzeroupper
81 ; CHECK-NEXT: retq
82 }