1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+sse4.1 | FileCheck %s --check-prefix=SSE
3 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+avx2 | FileCheck %s --check-prefix=AVX
6 define <4 x i32> @combine_vec_sub_zero(<4 x i32> %a) {
7 ; SSE-LABEL: combine_vec_sub_zero:
11 ; AVX-LABEL: combine_vec_sub_zero:
14 %1 = sub <4 x i32> %a, zeroinitializer
18 ; fold (sub x, x) -> 0
19 define <4 x i32> @combine_vec_sub_self(<4 x i32> %a) {
20 ; SSE-LABEL: combine_vec_sub_self:
22 ; SSE-NEXT: xorps %xmm0, %xmm0
25 ; AVX-LABEL: combine_vec_sub_self:
27 ; AVX-NEXT: vxorps %xmm0, %xmm0, %xmm0
29 %1 = sub <4 x i32> %a, %a
33 ; fold (sub x, c) -> (add x, -c)
34 define <4 x i32> @combine_vec_sub_constant(<4 x i32> %x) {
35 ; SSE-LABEL: combine_vec_sub_constant:
37 ; SSE-NEXT: psubd {{.*}}(%rip), %xmm0
40 ; AVX-LABEL: combine_vec_sub_constant:
42 ; AVX-NEXT: vpsubd {{.*}}(%rip), %xmm0, %xmm0
44 %1 = sub <4 x i32> %x, <i32 0, i32 1, i32 2, i32 3>
48 ; Canonicalize (sub -1, x) -> ~x, i.e. (xor x, -1)
49 define <4 x i32> @combine_vec_sub_negone(<4 x i32> %x) {
50 ; SSE-LABEL: combine_vec_sub_negone:
52 ; SSE-NEXT: pcmpeqd %xmm1, %xmm1
53 ; SSE-NEXT: pxor %xmm1, %xmm0
56 ; AVX-LABEL: combine_vec_sub_negone:
58 ; AVX-NEXT: vpcmpeqd %xmm1, %xmm1, %xmm1
59 ; AVX-NEXT: vpxor %xmm1, %xmm0, %xmm0
61 %1 = sub <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, %x
66 define <4 x i32> @combine_vec_sub_sub(<4 x i32> %a, <4 x i32> %b) {
67 ; SSE-LABEL: combine_vec_sub_sub:
69 ; SSE-NEXT: movaps %xmm1, %xmm0
72 ; AVX-LABEL: combine_vec_sub_sub:
74 ; AVX-NEXT: vmovaps %xmm1, %xmm0
76 %1 = sub <4 x i32> %a, %b
77 %2 = sub <4 x i32> %a, %1
82 define <4 x i32> @combine_vec_sub_add0(<4 x i32> %a, <4 x i32> %b) {
83 ; SSE-LABEL: combine_vec_sub_add0:
85 ; SSE-NEXT: movaps %xmm1, %xmm0
88 ; AVX-LABEL: combine_vec_sub_add0:
90 ; AVX-NEXT: vmovaps %xmm1, %xmm0
92 %1 = add <4 x i32> %a, %b
93 %2 = sub <4 x i32> %1, %a
98 define <4 x i32> @combine_vec_sub_add1(<4 x i32> %a, <4 x i32> %b) {
99 ; SSE-LABEL: combine_vec_sub_add1:
103 ; AVX-LABEL: combine_vec_sub_add1:
106 %1 = add <4 x i32> %a, %b
107 %2 = sub <4 x i32> %1, %b
111 ; fold C2-(A+C1) -> (C2-C1)-A
112 define <4 x i32> @combine_vec_sub_constant_add(<4 x i32> %a) {
113 ; SSE-LABEL: combine_vec_sub_constant_add:
115 ; SSE-NEXT: movdqa {{.*#+}} xmm1 = [3,1,4294967295,4294967293]
116 ; SSE-NEXT: psubd %xmm0, %xmm1
117 ; SSE-NEXT: movdqa %xmm1, %xmm0
120 ; AVX-LABEL: combine_vec_sub_constant_add:
122 ; AVX-NEXT: vmovdqa {{.*#+}} xmm1 = [3,1,4294967295,4294967293]
123 ; AVX-NEXT: vpsubd %xmm0, %xmm1, %xmm0
125 %1 = add <4 x i32> %a, <i32 0, i32 1, i32 2, i32 3>
126 %2 = sub <4 x i32> <i32 3, i32 2, i32 1, i32 0>, %1
130 ; fold ((A+(B+C))-B) -> A+C
131 define <4 x i32> @combine_vec_sub_add_add(<4 x i32> %a, <4 x i32> %b, <4 x i32> %c) {
132 ; SSE-LABEL: combine_vec_sub_add_add:
134 ; SSE-NEXT: paddd %xmm2, %xmm0
137 ; AVX-LABEL: combine_vec_sub_add_add:
139 ; AVX-NEXT: vpaddd %xmm2, %xmm0, %xmm0
141 %1 = add <4 x i32> %b, %c
142 %2 = add <4 x i32> %a, %1
143 %3 = sub <4 x i32> %2, %b
147 ; fold ((A+(B-C))-B) -> A-C
148 define <4 x i32> @combine_vec_sub_add_sub(<4 x i32> %a, <4 x i32> %b, <4 x i32> %c) {
149 ; SSE-LABEL: combine_vec_sub_add_sub:
151 ; SSE-NEXT: psubd %xmm2, %xmm0
154 ; AVX-LABEL: combine_vec_sub_add_sub:
156 ; AVX-NEXT: vpsubd %xmm2, %xmm0, %xmm0
158 %1 = sub <4 x i32> %b, %c
159 %2 = add <4 x i32> %a, %1
160 %3 = sub <4 x i32> %2, %b
164 ; fold ((A-(B-C))-C) -> A-B
165 define <4 x i32> @combine_vec_sub_sub_sub(<4 x i32> %a, <4 x i32> %b, <4 x i32> %c) {
166 ; SSE-LABEL: combine_vec_sub_sub_sub:
168 ; SSE-NEXT: psubd %xmm1, %xmm0
171 ; AVX-LABEL: combine_vec_sub_sub_sub:
173 ; AVX-NEXT: vpsubd %xmm1, %xmm0, %xmm0
175 %1 = sub <4 x i32> %b, %c
176 %2 = sub <4 x i32> %a, %1
177 %3 = sub <4 x i32> %2, %c
181 ; fold undef-A -> undef
182 define <4 x i32> @combine_vec_sub_undef0(<4 x i32> %a) {
183 ; SSE-LABEL: combine_vec_sub_undef0:
187 ; AVX-LABEL: combine_vec_sub_undef0:
190 %1 = sub <4 x i32> undef, %a
194 ; fold A-undef -> undef
195 define <4 x i32> @combine_vec_sub_undef1(<4 x i32> %a) {
196 ; SSE-LABEL: combine_vec_sub_undef1:
200 ; AVX-LABEL: combine_vec_sub_undef1:
203 %1 = sub <4 x i32> %a, undef
207 ; sub X, (sext Y i1) -> add X, (and Y 1)
208 define <4 x i32> @combine_vec_add_sext(<4 x i32> %x, <4 x i1> %y) {
209 ; SSE-LABEL: combine_vec_add_sext:
211 ; SSE-NEXT: pslld $31, %xmm1
212 ; SSE-NEXT: psrad $31, %xmm1
213 ; SSE-NEXT: psubd %xmm1, %xmm0
216 ; AVX-LABEL: combine_vec_add_sext:
218 ; AVX-NEXT: vpslld $31, %xmm1, %xmm1
219 ; AVX-NEXT: vpsrad $31, %xmm1, %xmm1
220 ; AVX-NEXT: vpsubd %xmm1, %xmm0, %xmm0
222 %1 = sext <4 x i1> %y to <4 x i32>
223 %2 = sub <4 x i32> %x, %1
227 ; sub X, (sextinreg Y i1) -> add X, (and Y 1)
228 define <4 x i32> @combine_vec_sub_sextinreg(<4 x i32> %x, <4 x i32> %y) {
229 ; SSE-LABEL: combine_vec_sub_sextinreg:
231 ; SSE-NEXT: pslld $31, %xmm1
232 ; SSE-NEXT: psrad $31, %xmm1
233 ; SSE-NEXT: psubd %xmm1, %xmm0
236 ; AVX-LABEL: combine_vec_sub_sextinreg:
238 ; AVX-NEXT: vpslld $31, %xmm1, %xmm1
239 ; AVX-NEXT: vpsrad $31, %xmm1, %xmm1
240 ; AVX-NEXT: vpsubd %xmm1, %xmm0, %xmm0
242 %1 = shl <4 x i32> %y, <i32 31, i32 31, i32 31, i32 31>
243 %2 = ashr <4 x i32> %1, <i32 31, i32 31, i32 31, i32 31>
244 %3 = sub <4 x i32> %x, %2