1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+avx | FileCheck %s
4 ; These are actually tests of ValueTracking, and so may have test coverage in InstCombine or other
5 ; IR opt passes, but ValueTracking also affects the backend via SelectionDAGBuilder::visitSelect().
7 define <4 x i32> @smin_vec1(<4 x i32> %x) {
8 ; CHECK-LABEL: smin_vec1:
10 ; CHECK-NEXT: vpcmpeqd %xmm1, %xmm1, %xmm1
11 ; CHECK-NEXT: vpxor %xmm1, %xmm0, %xmm0
12 ; CHECK-NEXT: vpminsd %xmm1, %xmm0, %xmm0
14 %not_x = xor <4 x i32> %x, <i32 -1, i32 -1, i32 -1, i32 -1>
15 %cmp = icmp sgt <4 x i32> %x, zeroinitializer
16 %sel = select <4 x i1> %cmp, <4 x i32> %not_x, <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>
20 define <4 x i32> @smin_vec2(<4 x i32> %x) {
21 ; CHECK-LABEL: smin_vec2:
23 ; CHECK-NEXT: vpcmpeqd %xmm1, %xmm1, %xmm1
24 ; CHECK-NEXT: vpxor %xmm1, %xmm0, %xmm0
25 ; CHECK-NEXT: vpminsd %xmm1, %xmm0, %xmm0
27 %not_x = xor <4 x i32> %x, <i32 -1, i32 -1, i32 -1, i32 -1>
28 %cmp = icmp slt <4 x i32> %x, zeroinitializer
29 %sel = select <4 x i1> %cmp, <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, <4 x i32> %not_x
34 ; (X >s Y) ? 0 : Z ==> (Z >s 0) ? 0 : Z ==> SMIN(Z, 0)
35 define <4 x i32> @smin_vec3(<4 x i32> %x, <4 x i32> %y) {
36 ; CHECK-LABEL: smin_vec3:
38 ; CHECK-NEXT: vpsubd %xmm1, %xmm0, %xmm0
39 ; CHECK-NEXT: vpxor %xmm1, %xmm1, %xmm1
40 ; CHECK-NEXT: vpminsd %xmm1, %xmm0, %xmm0
42 %sub = sub nsw <4 x i32> %x, %y
43 %cmp = icmp sgt <4 x i32> %x, %y
44 %sel = select <4 x i1> %cmp, <4 x i32> zeroinitializer, <4 x i32> %sub
49 ; (X <s Y) ? Z : 0 ==> (Z <s 0) ? Z : 0 ==> SMIN(Z, 0)
50 define <4 x i32> @smin_vec4(<4 x i32> %x, <4 x i32> %y) {
51 ; CHECK-LABEL: smin_vec4:
53 ; CHECK-NEXT: vpsubd %xmm1, %xmm0, %xmm0
54 ; CHECK-NEXT: vpxor %xmm1, %xmm1, %xmm1
55 ; CHECK-NEXT: vpminsd %xmm1, %xmm0, %xmm0
57 %sub = sub nsw <4 x i32> %x, %y
58 %cmp = icmp slt <4 x i32> %x, %y
59 %sel = select <4 x i1> %cmp, <4 x i32> %sub, <4 x i32> zeroinitializer
63 define <4 x i32> @smax_vec1(<4 x i32> %x) {
64 ; CHECK-LABEL: smax_vec1:
66 ; CHECK-NEXT: vpcmpeqd %xmm1, %xmm1, %xmm1
67 ; CHECK-NEXT: vpxor %xmm1, %xmm0, %xmm0
68 ; CHECK-NEXT: vpmaxsd %xmm1, %xmm0, %xmm0
70 %not_x = xor <4 x i32> %x, <i32 -1, i32 -1, i32 -1, i32 -1>
71 %cmp = icmp slt <4 x i32> %x, zeroinitializer
72 %sel = select <4 x i1> %cmp, <4 x i32> %not_x, <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>
76 define <4 x i32> @smax_vec2(<4 x i32> %x) {
77 ; CHECK-LABEL: smax_vec2:
79 ; CHECK-NEXT: vpcmpeqd %xmm1, %xmm1, %xmm1
80 ; CHECK-NEXT: vpxor %xmm1, %xmm0, %xmm0
81 ; CHECK-NEXT: vpmaxsd %xmm1, %xmm0, %xmm0
83 %not_x = xor <4 x i32> %x, <i32 -1, i32 -1, i32 -1, i32 -1>
84 %cmp = icmp sgt <4 x i32> %x, zeroinitializer
85 %sel = select <4 x i1> %cmp, <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, <4 x i32> %not_x
90 ; (X <s Y) ? 0 : Z ==> (Z <s 0) ? 0 : Z ==> SMAX(Z, 0)
91 define <4 x i32> @smax_vec3(<4 x i32> %x, <4 x i32> %y) {
92 ; CHECK-LABEL: smax_vec3:
94 ; CHECK-NEXT: vpsubd %xmm1, %xmm0, %xmm0
95 ; CHECK-NEXT: vpxor %xmm1, %xmm1, %xmm1
96 ; CHECK-NEXT: vpmaxsd %xmm1, %xmm0, %xmm0
98 %sub = sub nsw <4 x i32> %x, %y
99 %cmp = icmp slt <4 x i32> %x, %y
100 %sel = select <4 x i1> %cmp, <4 x i32> zeroinitializer, <4 x i32> %sub
105 ; (X >s Y) ? Z : 0 ==> (Z >s 0) ? Z : 0 ==> SMAX(Z, 0)
106 define <4 x i32> @smax_vec4(<4 x i32> %x, <4 x i32> %y) {
107 ; CHECK-LABEL: smax_vec4:
109 ; CHECK-NEXT: vpsubd %xmm1, %xmm0, %xmm0
110 ; CHECK-NEXT: vpxor %xmm1, %xmm1, %xmm1
111 ; CHECK-NEXT: vpmaxsd %xmm1, %xmm0, %xmm0
113 %sub = sub nsw <4 x i32> %x, %y
114 %cmp = icmp sgt <4 x i32> %x, %y
115 %sel = select <4 x i1> %cmp, <4 x i32> %sub, <4 x i32> zeroinitializer
119 define <4 x i32> @umax_vec1(<4 x i32> %x) {
120 ; CHECK-LABEL: umax_vec1:
122 ; CHECK-NEXT: vpmaxud {{.*}}(%rip), %xmm0, %xmm0
124 %cmp = icmp slt <4 x i32> %x, zeroinitializer
125 %sel = select <4 x i1> %cmp, <4 x i32> %x, <4 x i32> <i32 2147483647, i32 2147483647, i32 2147483647, i32 2147483647>
129 define <4 x i32> @umax_vec2(<4 x i32> %x) {
130 ; CHECK-LABEL: umax_vec2:
132 ; CHECK-NEXT: vpmaxud {{.*}}(%rip), %xmm0, %xmm0
134 %cmp = icmp sgt <4 x i32> %x, <i32 -1, i32 -1, i32 -1, i32 -1>
135 %sel = select <4 x i1> %cmp, <4 x i32> <i32 2147483648, i32 2147483648, i32 2147483648, i32 2147483648>, <4 x i32> %x
139 define <4 x i32> @umin_vec1(<4 x i32> %x) {
140 ; CHECK-LABEL: umin_vec1:
142 ; CHECK-NEXT: vpminud {{.*}}(%rip), %xmm0, %xmm0
144 %cmp = icmp slt <4 x i32> %x, zeroinitializer
145 %sel = select <4 x i1> %cmp, <4 x i32> <i32 2147483647, i32 2147483647, i32 2147483647, i32 2147483647>, <4 x i32> %x
149 define <4 x i32> @umin_vec2(<4 x i32> %x) {
150 ; CHECK-LABEL: umin_vec2:
152 ; CHECK-NEXT: vpminud {{.*}}(%rip), %xmm0, %xmm0
154 %cmp = icmp sgt <4 x i32> %x, <i32 -1, i32 -1, i32 -1, i32 -1>
155 %sel = select <4 x i1> %cmp, <4 x i32> %x, <4 x i32> <i32 2147483648, i32 2147483648, i32 2147483648, i32 2147483648>
159 ; The next 4 tests are value clamping with constants:
160 ; https://llvm.org/bugs/show_bug.cgi?id=31693
162 ; (X <s C1) ? C1 : SMIN(X, C2) ==> SMAX(SMIN(X, C2), C1)
164 define <4 x i32> @clamp_signed1(<4 x i32> %x) {
165 ; CHECK-LABEL: clamp_signed1:
167 ; CHECK-NEXT: vpminsd {{.*}}(%rip), %xmm0, %xmm0
168 ; CHECK-NEXT: vpmaxsd {{.*}}(%rip), %xmm0, %xmm0
170 %cmp2 = icmp slt <4 x i32> %x, <i32 255, i32 255, i32 255, i32 255>
171 %min = select <4 x i1> %cmp2, <4 x i32> %x, <4 x i32><i32 255, i32 255, i32 255, i32 255>
172 %cmp1 = icmp slt <4 x i32> %x, <i32 15, i32 15, i32 15, i32 15>
173 %r = select <4 x i1> %cmp1, <4 x i32><i32 15, i32 15, i32 15, i32 15>, <4 x i32> %min
177 ; (X >s C1) ? C1 : SMAX(X, C2) ==> SMIN(SMAX(X, C2), C1)
179 define <4 x i32> @clamp_signed2(<4 x i32> %x) {
180 ; CHECK-LABEL: clamp_signed2:
182 ; CHECK-NEXT: vpmaxsd {{.*}}(%rip), %xmm0, %xmm0
183 ; CHECK-NEXT: vpminsd {{.*}}(%rip), %xmm0, %xmm0
185 %cmp2 = icmp sgt <4 x i32> %x, <i32 15, i32 15, i32 15, i32 15>
186 %max = select <4 x i1> %cmp2, <4 x i32> %x, <4 x i32><i32 15, i32 15, i32 15, i32 15>
187 %cmp1 = icmp sgt <4 x i32> %x, <i32 255, i32 255, i32 255, i32 255>
188 %r = select <4 x i1> %cmp1, <4 x i32><i32 255, i32 255, i32 255, i32 255>, <4 x i32> %max
192 ; (X <u C1) ? C1 : UMIN(X, C2) ==> UMAX(UMIN(X, C2), C1)
194 define <4 x i32> @clamp_unsigned1(<4 x i32> %x) {
195 ; CHECK-LABEL: clamp_unsigned1:
197 ; CHECK-NEXT: vpminud {{.*}}(%rip), %xmm0, %xmm0
198 ; CHECK-NEXT: vpmaxud {{.*}}(%rip), %xmm0, %xmm0
200 %cmp2 = icmp ult <4 x i32> %x, <i32 255, i32 255, i32 255, i32 255>
201 %min = select <4 x i1> %cmp2, <4 x i32> %x, <4 x i32><i32 255, i32 255, i32 255, i32 255>
202 %cmp1 = icmp ult <4 x i32> %x, <i32 15, i32 15, i32 15, i32 15>
203 %r = select <4 x i1> %cmp1, <4 x i32><i32 15, i32 15, i32 15, i32 15>, <4 x i32> %min
207 ; (X >u C1) ? C1 : UMAX(X, C2) ==> UMIN(UMAX(X, C2), C1)
209 define <4 x i32> @clamp_unsigned2(<4 x i32> %x) {
210 ; CHECK-LABEL: clamp_unsigned2:
212 ; CHECK-NEXT: vpmaxud {{.*}}(%rip), %xmm0, %xmm0
213 ; CHECK-NEXT: vpminud {{.*}}(%rip), %xmm0, %xmm0
215 %cmp2 = icmp ugt <4 x i32> %x, <i32 15, i32 15, i32 15, i32 15>
216 %max = select <4 x i1> %cmp2, <4 x i32> %x, <4 x i32><i32 15, i32 15, i32 15, i32 15>
217 %cmp1 = icmp ugt <4 x i32> %x, <i32 255, i32 255, i32 255, i32 255>
218 %r = select <4 x i1> %cmp1, <4 x i32><i32 255, i32 255, i32 255, i32 255>, <4 x i32> %max
222 define <4 x i32> @wrong_pred_for_smin_with_not(<4 x i32> %x) {
223 ; CHECK-LABEL: wrong_pred_for_smin_with_not:
225 ; CHECK-NEXT: vpcmpeqd %xmm1, %xmm1, %xmm1
226 ; CHECK-NEXT: vpxor %xmm1, %xmm0, %xmm1
227 ; CHECK-NEXT: vpmaxud {{.*}}(%rip), %xmm0, %xmm2
228 ; CHECK-NEXT: vpcmpeqd %xmm2, %xmm0, %xmm0
229 ; CHECK-NEXT: vmovaps {{.*#+}} xmm2 = [4294967291,4294967291,4294967291,4294967291]
230 ; CHECK-NEXT: vblendvps %xmm0, %xmm1, %xmm2, %xmm0
232 %not_x = xor <4 x i32> %x, <i32 -1, i32 -1, i32 -1, i32 -1>
233 %cmp = icmp ugt <4 x i32> %x, <i32 4, i32 4, i32 4, i32 4>
234 %sel = select <4 x i1> %cmp, <4 x i32> %not_x, <4 x i32> <i32 -5, i32 -5, i32 -5, i32 -5>
238 define <4 x i32> @wrong_pred_for_smin_with_subnsw(<4 x i32> %x, <4 x i32> %y) {
239 ; CHECK-LABEL: wrong_pred_for_smin_with_subnsw:
241 ; CHECK-NEXT: vpsubd %xmm1, %xmm0, %xmm2
242 ; CHECK-NEXT: vpminud %xmm1, %xmm0, %xmm1
243 ; CHECK-NEXT: vpcmpeqd %xmm1, %xmm0, %xmm0
244 ; CHECK-NEXT: vpand %xmm2, %xmm0, %xmm0
246 %sub = sub nsw <4 x i32> %x, %y
247 %cmp = icmp ugt <4 x i32> %x, %y
248 %sel = select <4 x i1> %cmp, <4 x i32> zeroinitializer, <4 x i32> %sub