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
5 declare {i32, i1} @llvm.ssub.with.overflow.i32(i32, i32) nounwind readnone
6 declare {i32, i1} @llvm.usub.with.overflow.i32(i32, i32) nounwind readnone
8 declare {<4 x i32>, <4 x i1>} @llvm.ssub.with.overflow.v4i32(<4 x i32>, <4 x i32>) nounwind readnone
9 declare {<4 x i32>, <4 x i1>} @llvm.usub.with.overflow.v4i32(<4 x i32>, <4 x i32>) nounwind readnone
11 ; fold (ssub x, 0) -> x
12 define i32 @combine_ssub_zero(i32 %a0, i32 %a1) {
13 ; SSE-LABEL: combine_ssub_zero:
15 ; SSE-NEXT: movl %edi, %eax
18 ; AVX-LABEL: combine_ssub_zero:
20 ; AVX-NEXT: movl %edi, %eax
22 %1 = call {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a0, i32 zeroinitializer)
23 %2 = extractvalue {i32, i1} %1, 0
24 %3 = extractvalue {i32, i1} %1, 1
25 %4 = select i1 %3, i32 %a1, i32 %2
29 define <4 x i32> @combine_vec_ssub_zero(<4 x i32> %a0, <4 x i32> %a1) {
30 ; SSE-LABEL: combine_vec_ssub_zero:
34 ; AVX-LABEL: combine_vec_ssub_zero:
37 %1 = call {<4 x i32>, <4 x i1>} @llvm.ssub.with.overflow.v4i32(<4 x i32> %a0, <4 x i32> zeroinitializer)
38 %2 = extractvalue {<4 x i32>, <4 x i1>} %1, 0
39 %3 = extractvalue {<4 x i32>, <4 x i1>} %1, 1
40 %4 = select <4 x i1> %3, <4 x i32> %a1, <4 x i32> %2
44 ; fold (usub x, 0) -> x
45 define i32 @combine_usub_zero(i32 %a0, i32 %a1) {
46 ; SSE-LABEL: combine_usub_zero:
48 ; SSE-NEXT: movl %edi, %eax
51 ; AVX-LABEL: combine_usub_zero:
53 ; AVX-NEXT: movl %edi, %eax
55 %1 = call {i32, i1} @llvm.usub.with.overflow.i32(i32 %a0, i32 zeroinitializer)
56 %2 = extractvalue {i32, i1} %1, 0
57 %3 = extractvalue {i32, i1} %1, 1
58 %4 = select i1 %3, i32 %a1, i32 %2
62 define <4 x i32> @combine_vec_usub_zero(<4 x i32> %a0, <4 x i32> %a1) {
63 ; SSE-LABEL: combine_vec_usub_zero:
67 ; AVX-LABEL: combine_vec_usub_zero:
70 %1 = call {<4 x i32>, <4 x i1>} @llvm.usub.with.overflow.v4i32(<4 x i32> %a0, <4 x i32> zeroinitializer)
71 %2 = extractvalue {<4 x i32>, <4 x i1>} %1, 0
72 %3 = extractvalue {<4 x i32>, <4 x i1>} %1, 1
73 %4 = select <4 x i1> %3, <4 x i32> %a1, <4 x i32> %2
77 ; fold (ssub x, x) -> 0
78 define i32 @combine_ssub_self(i32 %a0, i32 %a1) {
79 ; SSE-LABEL: combine_ssub_self:
81 ; SSE-NEXT: xorl %eax, %eax
84 ; AVX-LABEL: combine_ssub_self:
86 ; AVX-NEXT: xorl %eax, %eax
88 %1 = call {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a0, i32 %a0)
89 %2 = extractvalue {i32, i1} %1, 0
90 %3 = extractvalue {i32, i1} %1, 1
91 %4 = select i1 %3, i32 %a1, i32 %2
95 define <4 x i32> @combine_vec_ssub_self(<4 x i32> %a0, <4 x i32> %a1) {
96 ; SSE-LABEL: combine_vec_ssub_self:
98 ; SSE-NEXT: xorps %xmm0, %xmm0
101 ; AVX-LABEL: combine_vec_ssub_self:
103 ; AVX-NEXT: vxorps %xmm0, %xmm0, %xmm0
105 %1 = call {<4 x i32>, <4 x i1>} @llvm.ssub.with.overflow.v4i32(<4 x i32> %a0, <4 x i32> %a0)
106 %2 = extractvalue {<4 x i32>, <4 x i1>} %1, 0
107 %3 = extractvalue {<4 x i32>, <4 x i1>} %1, 1
108 %4 = select <4 x i1> %3, <4 x i32> %a1, <4 x i32> %2
112 ; fold (usub x, x) -> x
113 define i32 @combine_usub_self(i32 %a0, i32 %a1) {
114 ; SSE-LABEL: combine_usub_self:
116 ; SSE-NEXT: xorl %eax, %eax
119 ; AVX-LABEL: combine_usub_self:
121 ; AVX-NEXT: xorl %eax, %eax
123 %1 = call {i32, i1} @llvm.usub.with.overflow.i32(i32 %a0, i32 %a0)
124 %2 = extractvalue {i32, i1} %1, 0
125 %3 = extractvalue {i32, i1} %1, 1
126 %4 = select i1 %3, i32 %a1, i32 %2
130 define <4 x i32> @combine_vec_usub_self(<4 x i32> %a0, <4 x i32> %a1) {
131 ; SSE-LABEL: combine_vec_usub_self:
133 ; SSE-NEXT: xorps %xmm0, %xmm0
136 ; AVX-LABEL: combine_vec_usub_self:
138 ; AVX-NEXT: vxorps %xmm0, %xmm0, %xmm0
140 %1 = call {<4 x i32>, <4 x i1>} @llvm.usub.with.overflow.v4i32(<4 x i32> %a0, <4 x i32> %a0)
141 %2 = extractvalue {<4 x i32>, <4 x i1>} %1, 0
142 %3 = extractvalue {<4 x i32>, <4 x i1>} %1, 1
143 %4 = select <4 x i1> %3, <4 x i32> %a1, <4 x i32> %2
147 ; fold (usub -1, x) -> (xor x, -1) + no borrow
148 define i32 @combine_usub_negone(i32 %a0, i32 %a1) {
149 ; SSE-LABEL: combine_usub_negone:
151 ; SSE-NEXT: movl %edi, %eax
152 ; SSE-NEXT: notl %eax
155 ; AVX-LABEL: combine_usub_negone:
157 ; AVX-NEXT: movl %edi, %eax
158 ; AVX-NEXT: notl %eax
160 %1 = call {i32, i1} @llvm.usub.with.overflow.i32(i32 -1, i32 %a0)
161 %2 = extractvalue {i32, i1} %1, 0
162 %3 = extractvalue {i32, i1} %1, 1
163 %4 = select i1 %3, i32 %a1, i32 %2
167 define <4 x i32> @combine_vec_usub_negone(<4 x i32> %a0, <4 x i32> %a1) {
168 ; SSE-LABEL: combine_vec_usub_negone:
170 ; SSE-NEXT: pcmpeqd %xmm1, %xmm1
171 ; SSE-NEXT: pxor %xmm1, %xmm0
174 ; AVX-LABEL: combine_vec_usub_negone:
176 ; AVX-NEXT: vpcmpeqd %xmm1, %xmm1, %xmm1
177 ; AVX-NEXT: vpxor %xmm1, %xmm0, %xmm0
179 %1 = call {<4 x i32>, <4 x i1>} @llvm.usub.with.overflow.v4i32(<4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, <4 x i32> %a0)
180 %2 = extractvalue {<4 x i32>, <4 x i1>} %1, 0
181 %3 = extractvalue {<4 x i32>, <4 x i1>} %1, 1
182 %4 = select <4 x i1> %3, <4 x i32> %a1, <4 x i32> %2