1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00

[X86] Use incDecVectorConstant to simplify the min/max code in LowerVSETCC.

incDecVectorConstant is used for a similar reason in LowerVSETCCWithSUBUS
so we might as well share the code.

llvm-svn: 371861
This commit is contained in:
Craig Topper 2019-09-13 14:59:08 +00:00
parent fe26bc2586
commit 9a1d55880e

View File

@ -20514,7 +20514,7 @@ static SDValue LowerVSETCCWithSUBUS(SDValue Op0, SDValue Op1, MVT VT,
// Only do this pre-AVX since vpcmp* is no longer destructive. // Only do this pre-AVX since vpcmp* is no longer destructive.
if (Subtarget.hasAVX()) if (Subtarget.hasAVX())
return SDValue(); return SDValue();
SDValue ULEOp1 = incDecVectorConstant(Op1, DAG, false); SDValue ULEOp1 = incDecVectorConstant(Op1, DAG, /*IsInc*/false);
if (!ULEOp1) if (!ULEOp1)
return SDValue(); return SDValue();
Op1 = ULEOp1; Op1 = ULEOp1;
@ -20525,7 +20525,7 @@ static SDValue LowerVSETCCWithSUBUS(SDValue Op0, SDValue Op1, MVT VT,
// This is beneficial because materializing a constant 0 for the PCMPEQ is // This is beneficial because materializing a constant 0 for the PCMPEQ is
// probably cheaper than XOR+PCMPGT using 2 different vector constants: // probably cheaper than XOR+PCMPGT using 2 different vector constants:
// cmpgt (xor X, SignMaskC) CmpC --> cmpeq (usubsat (CmpC+1), X), 0 // cmpgt (xor X, SignMaskC) CmpC --> cmpeq (usubsat (CmpC+1), X), 0
SDValue UGEOp1 = incDecVectorConstant(Op1, DAG, true); SDValue UGEOp1 = incDecVectorConstant(Op1, DAG, /*IsInc*/true);
if (!UGEOp1) if (!UGEOp1)
return SDValue(); return SDValue();
Op1 = Op0; Op1 = Op0;
@ -20732,22 +20732,20 @@ static SDValue LowerVSETCC(SDValue Op, const X86Subtarget &Subtarget,
TLI.isOperationLegal(ISD::UMIN, VT)) { TLI.isOperationLegal(ISD::UMIN, VT)) {
// If we have a constant operand, increment/decrement it and change the // If we have a constant operand, increment/decrement it and change the
// condition to avoid an invert. // condition to avoid an invert.
if (Cond == ISD::SETUGT && if (Cond == ISD::SETUGT) {
ISD::matchUnaryPredicate(Op1, [](ConstantSDNode *C) {
return !C->getAPIntValue().isMaxValue();
})) {
// X > C --> X >= (C+1) --> X == umax(X, C+1) // X > C --> X >= (C+1) --> X == umax(X, C+1)
Op1 = DAG.getNode(ISD::ADD, dl, VT, Op1, DAG.getConstant(1, dl, VT)); if (SDValue UGTOp1 = incDecVectorConstant(Op1, DAG, /*IsInc*/true)) {
Op1 = UGTOp1;
Cond = ISD::SETUGE; Cond = ISD::SETUGE;
} }
if (Cond == ISD::SETULT && }
ISD::matchUnaryPredicate(Op1, [](ConstantSDNode *C) { if (Cond == ISD::SETULT) {
return !C->getAPIntValue().isNullValue();
})) {
// X < C --> X <= (C-1) --> X == umin(X, C-1) // X < C --> X <= (C-1) --> X == umin(X, C-1)
Op1 = DAG.getNode(ISD::SUB, dl, VT, Op1, DAG.getConstant(1, dl, VT)); if (SDValue ULTOp1 = incDecVectorConstant(Op1, DAG, /*IsInc*/false)) {
Op1 = ULTOp1;
Cond = ISD::SETULE; Cond = ISD::SETULE;
} }
}
bool Invert = false; bool Invert = false;
unsigned Opc; unsigned Opc;
switch (Cond) { switch (Cond) {