blob: c22453ba4f57ec0826409099b00fbf5196a73946 [file] [log] [blame]
Sanjay Patel841acbb2017-08-31 20:59:25 +00001; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2; RUN: llc < %s -mtriple=x86_64-unknown -mattr=+ssse3 | FileCheck %s --check-prefix=SSSE3
3; RUN: llc < %s -mtriple=x86_64-unknown -mattr=+avx | FileCheck %s --check-prefix=AVX
4
5; The next 8 tests check for matching the horizontal op and eliminating the shuffle.
6; PR34111 - https://bugs.llvm.org/show_bug.cgi?id=34111
7
8define <4 x float> @hadd_v4f32(<4 x float> %a) {
9; SSSE3-LABEL: hadd_v4f32:
10; SSSE3: # BB#0:
11; SSSE3-NEXT: haddps %xmm0, %xmm0
12; SSSE3-NEXT: movddup {{.*#+}} xmm0 = xmm0[0,0]
13; SSSE3-NEXT: retq
14;
15; AVX-LABEL: hadd_v4f32:
16; AVX: # BB#0:
17; AVX-NEXT: vhaddps %xmm0, %xmm0, %xmm0
18; AVX-NEXT: vmovddup {{.*#+}} xmm0 = xmm0[0,0]
19; AVX-NEXT: retq
20 %a02 = shufflevector <4 x float> %a, <4 x float> undef, <2 x i32> <i32 0, i32 2>
21 %a13 = shufflevector <4 x float> %a, <4 x float> undef, <2 x i32> <i32 1, i32 3>
22 %hop = fadd <2 x float> %a02, %a13
23 %shuf = shufflevector <2 x float> %hop, <2 x float> undef, <4 x i32> <i32 undef, i32 undef, i32 0, i32 1>
24 ret <4 x float> %shuf
25}
26
27define <4 x float> @hsub_v4f32(<4 x float> %a) {
28; SSSE3-LABEL: hsub_v4f32:
29; SSSE3: # BB#0:
30; SSSE3-NEXT: hsubps %xmm0, %xmm0
31; SSSE3-NEXT: movddup {{.*#+}} xmm0 = xmm0[0,0]
32; SSSE3-NEXT: retq
33;
34; AVX-LABEL: hsub_v4f32:
35; AVX: # BB#0:
36; AVX-NEXT: vhsubps %xmm0, %xmm0, %xmm0
37; AVX-NEXT: vmovddup {{.*#+}} xmm0 = xmm0[0,0]
38; AVX-NEXT: retq
39 %a02 = shufflevector <4 x float> %a, <4 x float> undef, <2 x i32> <i32 0, i32 2>
40 %a13 = shufflevector <4 x float> %a, <4 x float> undef, <2 x i32> <i32 1, i32 3>
41 %hop = fsub <2 x float> %a02, %a13
42 %shuf = shufflevector <2 x float> %hop, <2 x float> undef, <4 x i32> <i32 0, i32 1, i32 0, i32 1>
43 ret <4 x float> %shuf
44}
45
46define <2 x double> @hadd_v2f64(<2 x double> %a) {
47; SSSE3-LABEL: hadd_v2f64:
48; SSSE3: # BB#0:
49; SSSE3-NEXT: haddpd %xmm0, %xmm0
50; SSSE3-NEXT: movddup {{.*#+}} xmm0 = xmm0[0,0]
51; SSSE3-NEXT: retq
52;
53; AVX-LABEL: hadd_v2f64:
54; AVX: # BB#0:
55; AVX-NEXT: vhaddpd %xmm0, %xmm0, %xmm0
56; AVX-NEXT: vmovddup {{.*#+}} xmm0 = xmm0[0,0]
57; AVX-NEXT: retq
58 %a0 = shufflevector <2 x double> %a, <2 x double> undef, <2 x i32> <i32 0, i32 undef>
59 %a1 = shufflevector <2 x double> %a, <2 x double> undef, <2 x i32> <i32 1, i32 undef>
60 %hop = fadd <2 x double> %a0, %a1
61 %shuf = shufflevector <2 x double> %hop, <2 x double> undef, <2 x i32> <i32 0, i32 0>
62 ret <2 x double> %shuf
63}
64
65define <2 x double> @hsub_v2f64(<2 x double> %a) {
66; SSSE3-LABEL: hsub_v2f64:
67; SSSE3: # BB#0:
68; SSSE3-NEXT: hsubpd %xmm0, %xmm0
69; SSSE3-NEXT: movddup {{.*#+}} xmm0 = xmm0[0,0]
70; SSSE3-NEXT: retq
71;
72; AVX-LABEL: hsub_v2f64:
73; AVX: # BB#0:
74; AVX-NEXT: vhsubpd %xmm0, %xmm0, %xmm0
75; AVX-NEXT: vmovddup {{.*#+}} xmm0 = xmm0[0,0]
76; AVX-NEXT: retq
77 %a0 = shufflevector <2 x double> %a, <2 x double> undef, <2 x i32> <i32 0, i32 undef>
78 %a1 = shufflevector <2 x double> %a, <2 x double> undef, <2 x i32> <i32 1, i32 undef>
79 %hop = fsub <2 x double> %a0, %a1
80 %shuf = shufflevector <2 x double> %hop, <2 x double> undef, <2 x i32> <i32 undef, i32 0>
81 ret <2 x double> %shuf
82}
83
84define <4 x i32> @hadd_v4i32(<4 x i32> %a) {
85; SSSE3-LABEL: hadd_v4i32:
86; SSSE3: # BB#0:
87; SSSE3-NEXT: phaddd %xmm0, %xmm0
88; SSSE3-NEXT: pshufd {{.*#+}} xmm0 = xmm0[0,1,0,1]
89; SSSE3-NEXT: retq
90;
91; AVX-LABEL: hadd_v4i32:
92; AVX: # BB#0:
93; AVX-NEXT: vphaddd %xmm0, %xmm0, %xmm0
94; AVX-NEXT: vpshufd {{.*#+}} xmm0 = xmm0[0,1,0,1]
95; AVX-NEXT: retq
96 %a02 = shufflevector <4 x i32> %a, <4 x i32> undef, <4 x i32> <i32 0, i32 2, i32 undef, i32 undef>
97 %a13 = shufflevector <4 x i32> %a, <4 x i32> undef, <4 x i32> <i32 1, i32 3, i32 undef, i32 undef>
98 %hop = add <4 x i32> %a02, %a13
99 %shuf = shufflevector <4 x i32> %hop, <4 x i32> undef, <4 x i32> <i32 0, i32 undef, i32 undef, i32 1>
100 ret <4 x i32> %shuf
101}
102
103define <4 x i32> @hsub_v4i32(<4 x i32> %a) {
104; SSSE3-LABEL: hsub_v4i32:
105; SSSE3: # BB#0:
106; SSSE3-NEXT: phsubd %xmm0, %xmm0
107; SSSE3-NEXT: pshufd {{.*#+}} xmm0 = xmm0[0,1,0,1]
108; SSSE3-NEXT: retq
109;
110; AVX-LABEL: hsub_v4i32:
111; AVX: # BB#0:
112; AVX-NEXT: vphsubd %xmm0, %xmm0, %xmm0
113; AVX-NEXT: vpshufd {{.*#+}} xmm0 = xmm0[0,1,0,1]
114; AVX-NEXT: retq
115 %a02 = shufflevector <4 x i32> %a, <4 x i32> undef, <4 x i32> <i32 0, i32 2, i32 undef, i32 undef>
116 %a13 = shufflevector <4 x i32> %a, <4 x i32> undef, <4 x i32> <i32 1, i32 3, i32 undef, i32 undef>
117 %hop = sub <4 x i32> %a02, %a13
118 %shuf = shufflevector <4 x i32> %hop, <4 x i32> undef, <4 x i32> <i32 undef, i32 1, i32 0, i32 undef>
119 ret <4 x i32> %shuf
120}
121
122define <8 x i16> @hadd_v8i16(<8 x i16> %a) {
123; SSSE3-LABEL: hadd_v8i16:
124; SSSE3: # BB#0:
125; SSSE3-NEXT: phaddw %xmm0, %xmm0
126; SSSE3-NEXT: pshufd {{.*#+}} xmm0 = xmm0[0,1,0,1]
127; SSSE3-NEXT: retq
128;
129; AVX-LABEL: hadd_v8i16:
130; AVX: # BB#0:
131; AVX-NEXT: vphaddw %xmm0, %xmm0, %xmm0
132; AVX-NEXT: vpshufd {{.*#+}} xmm0 = xmm0[0,1,0,1]
133; AVX-NEXT: retq
134 %a0246 = shufflevector <8 x i16> %a, <8 x i16> undef, <8 x i32> <i32 0, i32 2, i32 4, i32 6, i32 undef, i32 undef, i32 undef, i32 undef>
135 %a1357 = shufflevector <8 x i16> %a, <8 x i16> undef, <8 x i32> <i32 1, i32 3, i32 5, i32 7, i32 undef, i32 undef, i32 undef, i32 undef>
136 %hop = add <8 x i16> %a0246, %a1357
137 %shuf = shufflevector <8 x i16> %hop, <8 x i16> undef, <8 x i32> <i32 undef, i32 undef, i32 undef, i32 undef, i32 0, i32 1, i32 2, i32 3>
138 ret <8 x i16> %shuf
139}
140
141define <8 x i16> @hsub_v8i16(<8 x i16> %a) {
142; SSSE3-LABEL: hsub_v8i16:
143; SSSE3: # BB#0:
144; SSSE3-NEXT: phsubw %xmm0, %xmm0
145; SSSE3-NEXT: pshufd {{.*#+}} xmm0 = xmm0[0,1,0,1]
146; SSSE3-NEXT: retq
147;
148; AVX-LABEL: hsub_v8i16:
149; AVX: # BB#0:
150; AVX-NEXT: vphsubw %xmm0, %xmm0, %xmm0
151; AVX-NEXT: vpshufd {{.*#+}} xmm0 = xmm0[0,1,0,1]
152; AVX-NEXT: retq
153 %a0246 = shufflevector <8 x i16> %a, <8 x i16> undef, <8 x i32> <i32 0, i32 2, i32 4, i32 6, i32 undef, i32 undef, i32 undef, i32 undef>
154 %a1357 = shufflevector <8 x i16> %a, <8 x i16> undef, <8 x i32> <i32 1, i32 3, i32 5, i32 7, i32 undef, i32 undef, i32 undef, i32 undef>
155 %hop = sub <8 x i16> %a0246, %a1357
156 %shuf = shufflevector <8 x i16> %hop, <8 x i16> undef, <8 x i32> <i32 0, i32 undef, i32 2, i32 undef, i32 undef, i32 1, i32 undef, i32 3>
157 ret <8 x i16> %shuf
158}
159