blob: 3b126b7b6dfc03b9bc3e4f823986f886655d1a9c [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:
Francis Visoiu Mistrih25528d62017-12-04 17:18:51 +000010; SSSE3: # %bb.0:
Sanjay Patel841acbb2017-08-31 20:59:25 +000011; SSSE3-NEXT: haddps %xmm0, %xmm0
Sanjay Patel841acbb2017-08-31 20:59:25 +000012; SSSE3-NEXT: retq
13;
14; AVX-LABEL: hadd_v4f32:
Francis Visoiu Mistrih25528d62017-12-04 17:18:51 +000015; AVX: # %bb.0:
Sanjay Patel841acbb2017-08-31 20:59:25 +000016; AVX-NEXT: vhaddps %xmm0, %xmm0, %xmm0
Sanjay Patel841acbb2017-08-31 20:59:25 +000017; AVX-NEXT: retq
18 %a02 = shufflevector <4 x float> %a, <4 x float> undef, <2 x i32> <i32 0, i32 2>
19 %a13 = shufflevector <4 x float> %a, <4 x float> undef, <2 x i32> <i32 1, i32 3>
20 %hop = fadd <2 x float> %a02, %a13
21 %shuf = shufflevector <2 x float> %hop, <2 x float> undef, <4 x i32> <i32 undef, i32 undef, i32 0, i32 1>
22 ret <4 x float> %shuf
23}
24
25define <4 x float> @hsub_v4f32(<4 x float> %a) {
26; SSSE3-LABEL: hsub_v4f32:
Francis Visoiu Mistrih25528d62017-12-04 17:18:51 +000027; SSSE3: # %bb.0:
Sanjay Patel841acbb2017-08-31 20:59:25 +000028; SSSE3-NEXT: hsubps %xmm0, %xmm0
Sanjay Patel841acbb2017-08-31 20:59:25 +000029; SSSE3-NEXT: retq
30;
31; AVX-LABEL: hsub_v4f32:
Francis Visoiu Mistrih25528d62017-12-04 17:18:51 +000032; AVX: # %bb.0:
Sanjay Patel841acbb2017-08-31 20:59:25 +000033; AVX-NEXT: vhsubps %xmm0, %xmm0, %xmm0
Sanjay Patel841acbb2017-08-31 20:59:25 +000034; AVX-NEXT: retq
35 %a02 = shufflevector <4 x float> %a, <4 x float> undef, <2 x i32> <i32 0, i32 2>
36 %a13 = shufflevector <4 x float> %a, <4 x float> undef, <2 x i32> <i32 1, i32 3>
37 %hop = fsub <2 x float> %a02, %a13
38 %shuf = shufflevector <2 x float> %hop, <2 x float> undef, <4 x i32> <i32 0, i32 1, i32 0, i32 1>
39 ret <4 x float> %shuf
40}
41
42define <2 x double> @hadd_v2f64(<2 x double> %a) {
43; SSSE3-LABEL: hadd_v2f64:
Francis Visoiu Mistrih25528d62017-12-04 17:18:51 +000044; SSSE3: # %bb.0:
Sanjay Patel841acbb2017-08-31 20:59:25 +000045; SSSE3-NEXT: haddpd %xmm0, %xmm0
Sanjay Patel841acbb2017-08-31 20:59:25 +000046; SSSE3-NEXT: retq
47;
48; AVX-LABEL: hadd_v2f64:
Francis Visoiu Mistrih25528d62017-12-04 17:18:51 +000049; AVX: # %bb.0:
Sanjay Patel841acbb2017-08-31 20:59:25 +000050; AVX-NEXT: vhaddpd %xmm0, %xmm0, %xmm0
Sanjay Patel841acbb2017-08-31 20:59:25 +000051; AVX-NEXT: retq
52 %a0 = shufflevector <2 x double> %a, <2 x double> undef, <2 x i32> <i32 0, i32 undef>
53 %a1 = shufflevector <2 x double> %a, <2 x double> undef, <2 x i32> <i32 1, i32 undef>
54 %hop = fadd <2 x double> %a0, %a1
55 %shuf = shufflevector <2 x double> %hop, <2 x double> undef, <2 x i32> <i32 0, i32 0>
56 ret <2 x double> %shuf
57}
58
59define <2 x double> @hsub_v2f64(<2 x double> %a) {
60; SSSE3-LABEL: hsub_v2f64:
Francis Visoiu Mistrih25528d62017-12-04 17:18:51 +000061; SSSE3: # %bb.0:
Sanjay Patel841acbb2017-08-31 20:59:25 +000062; SSSE3-NEXT: hsubpd %xmm0, %xmm0
Sanjay Patel841acbb2017-08-31 20:59:25 +000063; SSSE3-NEXT: retq
64;
65; AVX-LABEL: hsub_v2f64:
Francis Visoiu Mistrih25528d62017-12-04 17:18:51 +000066; AVX: # %bb.0:
Sanjay Patel841acbb2017-08-31 20:59:25 +000067; AVX-NEXT: vhsubpd %xmm0, %xmm0, %xmm0
Sanjay Patel841acbb2017-08-31 20:59:25 +000068; AVX-NEXT: retq
69 %a0 = shufflevector <2 x double> %a, <2 x double> undef, <2 x i32> <i32 0, i32 undef>
70 %a1 = shufflevector <2 x double> %a, <2 x double> undef, <2 x i32> <i32 1, i32 undef>
71 %hop = fsub <2 x double> %a0, %a1
72 %shuf = shufflevector <2 x double> %hop, <2 x double> undef, <2 x i32> <i32 undef, i32 0>
73 ret <2 x double> %shuf
74}
75
76define <4 x i32> @hadd_v4i32(<4 x i32> %a) {
77; SSSE3-LABEL: hadd_v4i32:
Francis Visoiu Mistrih25528d62017-12-04 17:18:51 +000078; SSSE3: # %bb.0:
Sanjay Patel841acbb2017-08-31 20:59:25 +000079; SSSE3-NEXT: phaddd %xmm0, %xmm0
Sanjay Patel841acbb2017-08-31 20:59:25 +000080; SSSE3-NEXT: retq
81;
82; AVX-LABEL: hadd_v4i32:
Francis Visoiu Mistrih25528d62017-12-04 17:18:51 +000083; AVX: # %bb.0:
Sanjay Patel841acbb2017-08-31 20:59:25 +000084; AVX-NEXT: vphaddd %xmm0, %xmm0, %xmm0
Sanjay Patel841acbb2017-08-31 20:59:25 +000085; AVX-NEXT: retq
86 %a02 = shufflevector <4 x i32> %a, <4 x i32> undef, <4 x i32> <i32 0, i32 2, i32 undef, i32 undef>
87 %a13 = shufflevector <4 x i32> %a, <4 x i32> undef, <4 x i32> <i32 1, i32 3, i32 undef, i32 undef>
88 %hop = add <4 x i32> %a02, %a13
89 %shuf = shufflevector <4 x i32> %hop, <4 x i32> undef, <4 x i32> <i32 0, i32 undef, i32 undef, i32 1>
90 ret <4 x i32> %shuf
91}
92
93define <4 x i32> @hsub_v4i32(<4 x i32> %a) {
94; SSSE3-LABEL: hsub_v4i32:
Francis Visoiu Mistrih25528d62017-12-04 17:18:51 +000095; SSSE3: # %bb.0:
Sanjay Patel841acbb2017-08-31 20:59:25 +000096; SSSE3-NEXT: phsubd %xmm0, %xmm0
Sanjay Patel841acbb2017-08-31 20:59:25 +000097; SSSE3-NEXT: retq
98;
99; AVX-LABEL: hsub_v4i32:
Francis Visoiu Mistrih25528d62017-12-04 17:18:51 +0000100; AVX: # %bb.0:
Sanjay Patel841acbb2017-08-31 20:59:25 +0000101; AVX-NEXT: vphsubd %xmm0, %xmm0, %xmm0
Sanjay Patel841acbb2017-08-31 20:59:25 +0000102; AVX-NEXT: retq
103 %a02 = shufflevector <4 x i32> %a, <4 x i32> undef, <4 x i32> <i32 0, i32 2, i32 undef, i32 undef>
104 %a13 = shufflevector <4 x i32> %a, <4 x i32> undef, <4 x i32> <i32 1, i32 3, i32 undef, i32 undef>
105 %hop = sub <4 x i32> %a02, %a13
106 %shuf = shufflevector <4 x i32> %hop, <4 x i32> undef, <4 x i32> <i32 undef, i32 1, i32 0, i32 undef>
107 ret <4 x i32> %shuf
108}
109
110define <8 x i16> @hadd_v8i16(<8 x i16> %a) {
111; SSSE3-LABEL: hadd_v8i16:
Francis Visoiu Mistrih25528d62017-12-04 17:18:51 +0000112; SSSE3: # %bb.0:
Sanjay Patel841acbb2017-08-31 20:59:25 +0000113; SSSE3-NEXT: phaddw %xmm0, %xmm0
Sanjay Patel841acbb2017-08-31 20:59:25 +0000114; SSSE3-NEXT: retq
115;
116; AVX-LABEL: hadd_v8i16:
Francis Visoiu Mistrih25528d62017-12-04 17:18:51 +0000117; AVX: # %bb.0:
Sanjay Patel841acbb2017-08-31 20:59:25 +0000118; AVX-NEXT: vphaddw %xmm0, %xmm0, %xmm0
Sanjay Patel841acbb2017-08-31 20:59:25 +0000119; AVX-NEXT: retq
120 %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>
121 %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>
122 %hop = add <8 x i16> %a0246, %a1357
123 %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>
124 ret <8 x i16> %shuf
125}
126
127define <8 x i16> @hsub_v8i16(<8 x i16> %a) {
128; SSSE3-LABEL: hsub_v8i16:
Francis Visoiu Mistrih25528d62017-12-04 17:18:51 +0000129; SSSE3: # %bb.0:
Sanjay Patel841acbb2017-08-31 20:59:25 +0000130; SSSE3-NEXT: phsubw %xmm0, %xmm0
Sanjay Patel841acbb2017-08-31 20:59:25 +0000131; SSSE3-NEXT: retq
132;
133; AVX-LABEL: hsub_v8i16:
Francis Visoiu Mistrih25528d62017-12-04 17:18:51 +0000134; AVX: # %bb.0:
Sanjay Patel841acbb2017-08-31 20:59:25 +0000135; AVX-NEXT: vphsubw %xmm0, %xmm0, %xmm0
Sanjay Patel841acbb2017-08-31 20:59:25 +0000136; AVX-NEXT: retq
137 %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>
138 %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>
139 %hop = sub <8 x i16> %a0246, %a1357
140 %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>
141 ret <8 x i16> %shuf
142}
143