llvm.org GIT mirror llvm / c5a680a
[SelectionDAG] Support some SimplifySetCC cases for comparing against vector splats of constants. This supports things like (setcc ugt X, 0) -> (setcc ne X, 0) I've restricted to only make changes to vectors before legalize ops because I doubt all targets have accurate condition code legality information for vectors given how little we did before. Differential Revision: https://reviews.llvm.org/D42948 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@326495 91177308-0d34-0410-b5e6-96231b3b80d8 Craig Topper 2 years ago
3 changed file(s) with 37 addition(s) and 54 deletion(s). Raw diff Collapse all Expand all
22202220 if (C1 == MinVal)
22212221 return DAG.getBoolConstant(false, dl, VT, OpVT); // X < MIN --> false
22222222
2223 if (!VT.isVector()) { // TODO: Support this for vectors.
2223 // TODO: Support this for vectors after legalize ops.
2224 if (!VT.isVector() || DCI.isBeforeLegalizeOps()) {
22242225 // Canonicalize setlt X, Max --> setne X, Max
22252226 if (C1 == MaxVal)
22262227 return DAG.getSetCC(dl, VT, N0, N1, ISD::SETNE);
22372238 if (C1 == MaxVal)
22382239 return DAG.getBoolConstant(false, dl, VT, OpVT); // X > MAX --> false
22392240
2240 if (!VT.isVector()) { // TODO: Support this for vectors.
2241 // TODO: Support this for vectors after legalize ops.
2242 if (!VT.isVector() || DCI.isBeforeLegalizeOps()) {
22412243 // Canonicalize setgt X, Min --> setne X, Min
22422244 if (C1 == MinVal)
22432245 return DAG.getSetCC(dl, VT, N0, N1, ISD::SETNE);
22522254
22532255 // If we have "setcc X, C0", check to see if we can shrink the immediate
22542256 // by changing cc.
2255 if (!VT.isVector()) { // TODO: Support this for vectors.
2257 // TODO: Support this for vectors after legalize ops.
2258 if (!VT.isVector() || DCI.isBeforeLegalizeOps()) {
22562259 // SETUGT X, SINTMAX -> SETLT X, 0
22572260 if (Cond == ISD::SETUGT &&
22582261 C1 == APInt::getSignedMaxValue(OperandBitSize))
17061706 ; KNL-NEXT: subq $64, %rsp
17071707 ; KNL-NEXT: ## kill: def $esi killed $esi def $rsi
17081708 ; KNL-NEXT: vpxor %xmm1, %xmm1, %xmm1
1709 ; KNL-NEXT: vpminub %ymm1, %ymm0, %ymm1
17101709 ; KNL-NEXT: vpcmpeqb %ymm1, %ymm0, %ymm0
17111710 ; KNL-NEXT: vpternlogq $15, %zmm0, %zmm0, %zmm0
17121711 ; KNL-NEXT: andl $31, %esi
17381737 ; SKX-NEXT: andq $-32, %rsp
17391738 ; SKX-NEXT: subq $64, %rsp
17401739 ; SKX-NEXT: ## kill: def $esi killed $esi def $rsi
1741 ; SKX-NEXT: vpxor %xmm1, %xmm1, %xmm1
1742 ; SKX-NEXT: vpcmpnleub %ymm1, %ymm0, %k0
1740 ; SKX-NEXT: vptestmb %ymm0, %ymm0, %k0
17431741 ; SKX-NEXT: andl $31, %esi
17441742 ; SKX-NEXT: testb %dil, %dil
17451743 ; SKX-NEXT: vpmovm2b %k0, %ymm0
17711769 ; KNL-NEXT: subq $128, %rsp
17721770 ; KNL-NEXT: ## kill: def $esi killed $esi def $rsi
17731771 ; KNL-NEXT: vpxor %xmm2, %xmm2, %xmm2
1774 ; KNL-NEXT: vpminub %ymm2, %ymm0, %ymm3
1775 ; KNL-NEXT: vpcmpeqb %ymm3, %ymm0, %ymm0
1772 ; KNL-NEXT: vpcmpeqb %ymm2, %ymm0, %ymm0
17761773 ; KNL-NEXT: vpternlogq $15, %zmm0, %zmm0, %zmm0
1777 ; KNL-NEXT: vpminub %ymm2, %ymm1, %ymm2
17781774 ; KNL-NEXT: vpcmpeqb %ymm2, %ymm1, %ymm1
17791775 ; KNL-NEXT: vpternlogq $15, %zmm1, %zmm1, %zmm1
17801776 ; KNL-NEXT: andl $63, %esi
18231819 ; SKX-NEXT: andq $-64, %rsp
18241820 ; SKX-NEXT: subq $128, %rsp
18251821 ; SKX-NEXT: ## kill: def $esi killed $esi def $rsi
1826 ; SKX-NEXT: vpxor %xmm1, %xmm1, %xmm1
1827 ; SKX-NEXT: vpcmpnleub %zmm1, %zmm0, %k0
1822 ; SKX-NEXT: vptestmb %zmm0, %zmm0, %k0
18281823 ; SKX-NEXT: andl $63, %esi
18291824 ; SKX-NEXT: testb %dil, %dil
18301825 ; SKX-NEXT: vpmovm2b %k0, %zmm0
19541949 ; KNL-NEXT: vpinsrb $15, 216(%rbp), %xmm3, %xmm3
19551950 ; KNL-NEXT: vinserti128 $1, %xmm3, %ymm2, %ymm2
19561951 ; KNL-NEXT: vpxor %xmm3, %xmm3, %xmm3
1957 ; KNL-NEXT: vpminub %ymm3, %ymm2, %ymm4
1958 ; KNL-NEXT: vpcmpeqb %ymm4, %ymm2, %ymm2
1952 ; KNL-NEXT: vpcmpeqb %ymm3, %ymm2, %ymm2
19591953 ; KNL-NEXT: vpternlogq $15, %zmm2, %zmm2, %zmm2
1960 ; KNL-NEXT: vpminub %ymm3, %ymm1, %ymm4
1961 ; KNL-NEXT: vpcmpeqb %ymm4, %ymm1, %ymm1
1954 ; KNL-NEXT: vpcmpeqb %ymm3, %ymm1, %ymm1
19621955 ; KNL-NEXT: vpternlogq $15, %zmm1, %zmm1, %zmm1
1963 ; KNL-NEXT: vpminub %ymm3, %ymm0, %ymm4
1964 ; KNL-NEXT: vpcmpeqb %ymm4, %ymm0, %ymm0
1956 ; KNL-NEXT: vpcmpeqb %ymm3, %ymm0, %ymm0
19651957 ; KNL-NEXT: vpternlogq $15, %zmm0, %zmm0, %zmm0
19661958 ; KNL-NEXT: movl 744(%rbp), %eax
19671959 ; KNL-NEXT: andl $127, %eax
21372129 ; SKX-NEXT: vpinsrb $14, 720(%rbp), %xmm2, %xmm2
21382130 ; SKX-NEXT: vpinsrb $15, 728(%rbp), %xmm2, %xmm2
21392131 ; SKX-NEXT: vinserti128 $1, %xmm2, %ymm1, %ymm1
2140 ; SKX-NEXT: vpxor %xmm2, %xmm2, %xmm2
2141 ; SKX-NEXT: vpcmpnleub %zmm2, %zmm0, %k0
2142 ; SKX-NEXT: vpcmpnleub %zmm2, %zmm1, %k1
2132 ; SKX-NEXT: vptestmb %zmm0, %zmm0, %k0
2133 ; SKX-NEXT: vptestmb %zmm1, %zmm1, %k1
21432134 ; SKX-NEXT: movl 744(%rbp), %eax
21442135 ; SKX-NEXT: andl $127, %eax
21452136 ; SKX-NEXT: cmpb $0, 736(%rbp)
21772168 ; KNL-NEXT: subq $256, %rsp ## imm = 0x100
21782169 ; KNL-NEXT: ## kill: def $esi killed $esi def $rsi
21792170 ; KNL-NEXT: vpxor %xmm4, %xmm4, %xmm4
2180 ; KNL-NEXT: vpminub %ymm4, %ymm0, %ymm5
2181 ; KNL-NEXT: vpcmpeqb %ymm5, %ymm0, %ymm0
2171 ; KNL-NEXT: vpcmpeqb %ymm4, %ymm0, %ymm0
21822172 ; KNL-NEXT: vpternlogq $15, %zmm0, %zmm0, %zmm0
2183 ; KNL-NEXT: vpminub %ymm4, %ymm1, %ymm5
2184 ; KNL-NEXT: vpcmpeqb %ymm5, %ymm1, %ymm1
2173 ; KNL-NEXT: vpcmpeqb %ymm4, %ymm1, %ymm1
21852174 ; KNL-NEXT: vpternlogq $15, %zmm1, %zmm1, %zmm1
2186 ; KNL-NEXT: vpminub %ymm4, %ymm2, %ymm5
2187 ; KNL-NEXT: vpcmpeqb %ymm5, %ymm2, %ymm2
2175 ; KNL-NEXT: vpcmpeqb %ymm4, %ymm2, %ymm2
21882176 ; KNL-NEXT: vpternlogq $15, %zmm2, %zmm2, %zmm2
2189 ; KNL-NEXT: vpminub %ymm4, %ymm3, %ymm4
21902177 ; KNL-NEXT: vpcmpeqb %ymm4, %ymm3, %ymm3
21912178 ; KNL-NEXT: vpternlogq $15, %zmm3, %zmm3, %zmm3
21922179 ; KNL-NEXT: andl $127, %esi
22632250 ; SKX-NEXT: andq $-128, %rsp
22642251 ; SKX-NEXT: subq $256, %rsp ## imm = 0x100
22652252 ; SKX-NEXT: ## kill: def $esi killed $esi def $rsi
2266 ; SKX-NEXT: vpxor %xmm2, %xmm2, %xmm2
2267 ; SKX-NEXT: vpcmpnleub %zmm2, %zmm0, %k0
2268 ; SKX-NEXT: vpcmpnleub %zmm2, %zmm1, %k1
2253 ; SKX-NEXT: vptestmb %zmm0, %zmm0, %k0
2254 ; SKX-NEXT: vptestmb %zmm1, %zmm1, %k1
22692255 ; SKX-NEXT: andl $127, %esi
22702256 ; SKX-NEXT: testb %dil, %dil
22712257 ; SKX-NEXT: vpmovm2b %k1, %zmm0
112112 define <4 x i32> @ugt_min(<4 x i32> %x) {
113113 ; CHECK-LABEL: ugt_min:
114114 ; CHECK: # %bb.0:
115 ; CHECK-NEXT: movdqa {{.*#+}} xmm1 = [2147483648,2147483648,2147483648,2147483648]
116 ; CHECK-NEXT: pxor %xmm1, %xmm0
117 ; CHECK-NEXT: pcmpgtd %xmm1, %xmm0
115 ; CHECK-NEXT: pxor %xmm1, %xmm1
116 ; CHECK-NEXT: pcmpeqd %xmm1, %xmm0
117 ; CHECK-NEXT: pcmpeqd %xmm1, %xmm1
118 ; CHECK-NEXT: pxor %xmm1, %xmm0
118119 ; CHECK-NEXT: retq
119120 %cmp = icmp ugt <4 x i32> %x, zeroinitializer
120121 %r = sext <4 x i1> %cmp to <4 x i32>
158159 define <4 x i32> @ult_max(<4 x i32> %x) {
159160 ; CHECK-LABEL: ult_max:
160161 ; CHECK: # %bb.0:
161 ; CHECK-NEXT: pxor {{.*}}(%rip), %xmm0
162 ; CHECK-NEXT: movdqa {{.*#+}} xmm1 = [2147483647,2147483647,2147483647,2147483647]
163 ; CHECK-NEXT: pcmpgtd %xmm0, %xmm1
164 ; CHECK-NEXT: movdqa %xmm1, %xmm0
162 ; CHECK-NEXT: pcmpeqd %xmm1, %xmm1
163 ; CHECK-NEXT: pcmpeqd %xmm1, %xmm0
164 ; CHECK-NEXT: pxor %xmm1, %xmm0
165165 ; CHECK-NEXT: retq
166166 %cmp = icmp ult <4 x i32> %x,
167167 %r = sext <4 x i1> %cmp to <4 x i32>
186186 define <4 x i32> @slt_min_plus1(<4 x i32> %x) {
187187 ; CHECK-LABEL: slt_min_plus1:
188188 ; CHECK: # %bb.0:
189 ; CHECK-NEXT: movdqa {{.*#+}} xmm1 = [2147483649,2147483649,2147483649,2147483649]
190 ; CHECK-NEXT: pcmpgtd %xmm0, %xmm1
191 ; CHECK-NEXT: movdqa %xmm1, %xmm0
189 ; CHECK-NEXT: pcmpeqd {{.*}}(%rip), %xmm0
192190 ; CHECK-NEXT: retq
193191 %cmp = icmp slt <4 x i32> %x,
194192 %r = sext <4 x i1> %cmp to <4 x i32>
211209 define <4 x i32> @sgt_max_minus1(<4 x i32> %x) {
212210 ; CHECK-LABEL: sgt_max_minus1:
213211 ; CHECK: # %bb.0:
214 ; CHECK-NEXT: pcmpgtd {{.*}}(%rip), %xmm0
212 ; CHECK-NEXT: pcmpeqd {{.*}}(%rip), %xmm0
215213 ; CHECK-NEXT: retq
216214 %cmp = icmp sgt <4 x i32> %x,
217215 %r = sext <4 x i1> %cmp to <4 x i32>
233231 define <4 x i32> @ult_one(<4 x i32> %x) {
234232 ; CHECK-LABEL: ult_one:
235233 ; CHECK: # %bb.0:
236 ; CHECK-NEXT: pxor {{.*}}(%rip), %xmm0
237 ; CHECK-NEXT: movdqa {{.*#+}} xmm1 = [2147483649,2147483649,2147483649,2147483649]
238 ; CHECK-NEXT: pcmpgtd %xmm0, %xmm1
239 ; CHECK-NEXT: movdqa %xmm1, %xmm0
234 ; CHECK-NEXT: pxor %xmm1, %xmm1
235 ; CHECK-NEXT: pcmpeqd %xmm1, %xmm0
240236 ; CHECK-NEXT: retq
241237 %cmp = icmp ult <4 x i32> %x,
242238 %r = sext <4 x i1> %cmp to <4 x i32>
260256 define <4 x i32> @ugt_max_minus1(<4 x i32> %x) {
261257 ; CHECK-LABEL: ugt_max_minus1:
262258 ; CHECK: # %bb.0:
263 ; CHECK-NEXT: pxor {{.*}}(%rip), %xmm0
264 ; CHECK-NEXT: pcmpgtd {{.*}}(%rip), %xmm0
259 ; CHECK-NEXT: pcmpeqd %xmm1, %xmm1
260 ; CHECK-NEXT: pcmpeqd %xmm1, %xmm0
265261 ; CHECK-NEXT: retq
266262 %cmp = icmp ugt <4 x i32> %x,
267263 %r = sext <4 x i1> %cmp to <4 x i32>
284280 define <4 x i32> @ugt_smax(<4 x i32> %x) {
285281 ; CHECK-LABEL: ugt_smax:
286282 ; CHECK: # %bb.0:
287 ; CHECK-NEXT: pxor {{.*}}(%rip), %xmm0
288 ; CHECK-NEXT: pcmpeqd %xmm1, %xmm1
289 ; CHECK-NEXT: pcmpgtd %xmm1, %xmm0
283 ; CHECK-NEXT: pxor %xmm1, %xmm1
284 ; CHECK-NEXT: pcmpgtd %xmm0, %xmm1
285 ; CHECK-NEXT: movdqa %xmm1, %xmm0
290286 ; CHECK-NEXT: retq
291287 %cmp = icmp ugt <4 x i32> %x,
292288 %r = sext <4 x i1> %cmp to <4 x i32>
309305 define <4 x i32> @ult_smin(<4 x i32> %x) {
310306 ; CHECK-LABEL: ult_smin:
311307 ; CHECK: # %bb.0:
312 ; CHECK-NEXT: pxor {{.*}}(%rip), %xmm0
313 ; CHECK-NEXT: pxor %xmm1, %xmm1
314 ; CHECK-NEXT: pcmpgtd %xmm0, %xmm1
315 ; CHECK-NEXT: movdqa %xmm1, %xmm0
308 ; CHECK-NEXT: pcmpeqd %xmm1, %xmm1
309 ; CHECK-NEXT: pcmpgtd %xmm1, %xmm0
316310 ; CHECK-NEXT: retq
317311 %cmp = icmp ult <4 x i32> %x,
318312 %r = sext <4 x i1> %cmp to <4 x i32>