llvm.org GIT mirror llvm / ca423f3
[X86][SSE] Generalized unsigned compares to support nonsplat constant vectors (PR39859) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352283 91177308-0d34-0410-b5e6-96231b3b80d8 Simon Pilgrim 1 year, 4 months ago
3 changed file(s) with 14 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
1960319603 TLI.isOperationLegal(ISD::UMIN, VT)) {
1960419604 // If we have a constant operand, increment/decrement it and change the
1960519605 // condition to avoid an invert.
19606 // TODO: This could be extended to handle a non-splat constant by checking
19607 // that each element of the constant is not the max/null value.
19608 APInt C;
19609 if (Cond == ISD::SETUGT && isConstantSplat(Op1, C) && !C.isMaxValue()) {
19606 if (Cond == ISD::SETUGT &&
19607 ISD::matchUnaryPredicate(Op1, [](ConstantSDNode *C) {
19608 return !C->getAPIntValue().isMaxValue();
19609 })) {
1961019610 // X > C --> X >= (C+1) --> X == umax(X, C+1)
19611 Op1 = DAG.getConstant(C + 1, dl, VT);
19611 Op1 = DAG.getNode(ISD::ADD, dl, VT, Op1, DAG.getConstant(1, dl, VT));
1961219612 Cond = ISD::SETUGE;
1961319613 }
19614 if (Cond == ISD::SETULT && isConstantSplat(Op1, C) && !C.isNullValue()) {
19614 if (Cond == ISD::SETULT &&
19615 ISD::matchUnaryPredicate(Op1, [](ConstantSDNode *C) {
19616 return !C->getAPIntValue().isNullValue();
19617 })) {
1961519618 // X < C --> X <= (C-1) --> X == umin(X, C-1)
19616 Op1 = DAG.getConstant(C - 1, dl, VT);
19619 Op1 = DAG.getNode(ISD::SUB, dl, VT, Op1, DAG.getConstant(1, dl, VT));
1961719620 Cond = ISD::SETULE;
1961819621 }
1961919622 bool Invert = false;
550550 ; SSE41: # %bb.0:
551551 ; SSE41-NEXT: movdqa {{.*#+}} xmm1 = [43,44,45,46]
552552 ; SSE41-NEXT: paddd %xmm0, %xmm1
553 ; SSE41-NEXT: movdqa {{.*#+}} xmm2 = [4294967252,4294967251,4294967250,4294967249]
554 ; SSE41-NEXT: pminud %xmm0, %xmm2
553 ; SSE41-NEXT: movdqa {{.*#+}} xmm2 = [4294967253,4294967252,4294967251,4294967250]
554 ; SSE41-NEXT: pmaxud %xmm0, %xmm2
555555 ; SSE41-NEXT: pcmpeqd %xmm2, %xmm0
556 ; SSE41-NEXT: pcmpeqd %xmm2, %xmm2
557 ; SSE41-NEXT: pxor %xmm2, %xmm0
558556 ; SSE41-NEXT: por %xmm1, %xmm0
559557 ; SSE41-NEXT: retq
560558 %a = add <4 x i32> %x,
510510 ;
511511 ; SSE41-LABEL: ugt_v4i32_nonsplat:
512512 ; SSE41: ## %bb.0:
513 ; SSE41-NEXT: movdqa {{.*#+}} xmm1 = [4294967253,4294967254,4294967255,4294967256]
514 ; SSE41-NEXT: pminud %xmm0, %xmm1
513 ; SSE41-NEXT: movdqa {{.*#+}} xmm1 = [4294967254,4294967255,4294967256,4294967257]
514 ; SSE41-NEXT: pmaxud %xmm0, %xmm1
515515 ; SSE41-NEXT: pcmpeqd %xmm1, %xmm0
516 ; SSE41-NEXT: pcmpeqd %xmm1, %xmm1
517 ; SSE41-NEXT: pxor %xmm1, %xmm0
518516 ; SSE41-NEXT: retq
519517 %cmp = icmp ugt <4 x i32> %x,
520518 ret <4 x i1> %cmp