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 ; This and the next test were intended to become smin,
35 ; but that is not correct in general.
37 define <4 x i32> @smin_vec3(<4 x i32> %x, <4 x i32> %y) {
38 ; CHECK-LABEL: smin_vec3:
40 ; CHECK-NEXT: vpsubd %xmm1, %xmm0, %xmm2
41 ; CHECK-NEXT: vpcmpgtd %xmm1, %xmm0, %xmm0
42 ; CHECK-NEXT: vpandn %xmm2, %xmm0, %xmm0
44 %sub = sub nsw <4 x i32> %x, %y
45 %cmp = icmp sgt <4 x i32> %x, %y
46 %sel = select <4 x i1> %cmp, <4 x i32> zeroinitializer, <4 x i32> %sub
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, %xmm2
54 ; CHECK-NEXT: vpcmpgtd %xmm0, %xmm1, %xmm0
55 ; CHECK-NEXT: vpand %xmm2, %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 ; This and the next test were intended to become smax,
91 ; but that is not correct in general.
93 define <4 x i32> @smax_vec3(<4 x i32> %x, <4 x i32> %y) {
94 ; CHECK-LABEL: smax_vec3:
96 ; CHECK-NEXT: vpsubd %xmm1, %xmm0, %xmm2
97 ; CHECK-NEXT: vpcmpgtd %xmm0, %xmm1, %xmm0
98 ; CHECK-NEXT: vpandn %xmm2, %xmm0, %xmm0
100 %sub = sub nsw <4 x i32> %x, %y
101 %cmp = icmp slt <4 x i32> %x, %y
102 %sel = select <4 x i1> %cmp, <4 x i32> zeroinitializer, <4 x i32> %sub
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, %xmm2
110 ; CHECK-NEXT: vpcmpgtd %xmm1, %xmm0, %xmm0
111 ; CHECK-NEXT: vpand %xmm2, %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 {{\.?LCPI[0-9]+_[0-9]+}}(%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 {{\.?LCPI[0-9]+_[0-9]+}}(%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 {{\.?LCPI[0-9]+_[0-9]+}}(%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 {{\.?LCPI[0-9]+_[0-9]+}}(%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 {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0, %xmm0
168 ; CHECK-NEXT: vpmaxsd {{\.?LCPI[0-9]+_[0-9]+}}(%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 {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0, %xmm0
183 ; CHECK-NEXT: vpminsd {{\.?LCPI[0-9]+_[0-9]+}}(%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 {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0, %xmm0
198 ; CHECK-NEXT: vpmaxud {{\.?LCPI[0-9]+_[0-9]+}}(%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 {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0, %xmm0
213 ; CHECK-NEXT: vpminud {{\.?LCPI[0-9]+_[0-9]+}}(%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> @umin_not_ops(<4 x i32> %x) {
223 ; CHECK-LABEL: umin_not_ops:
225 ; CHECK-NEXT: vpcmpeqd %xmm1, %xmm1, %xmm1
226 ; CHECK-NEXT: vpxor %xmm1, %xmm0, %xmm0
227 ; CHECK-NEXT: vpminud {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0, %xmm0
229 %not_x = xor <4 x i32> %x, <i32 -1, i32 -1, i32 -1, i32 -1>
230 %cmp = icmp ugt <4 x i32> %x, <i32 4, i32 4, i32 4, i32 4>
231 %sel = select <4 x i1> %cmp, <4 x i32> %not_x, <4 x i32> <i32 -5, i32 -5, i32 -5, i32 -5>
235 define <4 x i32> @wrong_pred_for_smin_with_subnsw(<4 x i32> %x, <4 x i32> %y) {
236 ; CHECK-LABEL: wrong_pred_for_smin_with_subnsw:
238 ; CHECK-NEXT: vpsubd %xmm1, %xmm0, %xmm2
239 ; CHECK-NEXT: vpminud %xmm1, %xmm0, %xmm1
240 ; CHECK-NEXT: vpcmpeqd %xmm1, %xmm0, %xmm0
241 ; CHECK-NEXT: vpand %xmm2, %xmm0, %xmm0
243 %sub = sub nsw <4 x i32> %x, %y
244 %cmp = icmp ugt <4 x i32> %x, %y
245 %sel = select <4 x i1> %cmp, <4 x i32> zeroinitializer, <4 x i32> %sub