forked from OSchip/llvm-project
[DAG] LowerMINMAX - move default expansion to generic TargetLowering::expandIntMINMAX
This is part of the discussion on D91876 about trying to reduce custom lowering of MIN/MAX ops on older SSE targets - if we can improve generic vector expansion we should be able to relax the limitations in SelectionDAGBuilder when it will let MIN/MAX ops be generated, and avoid having to flag so many ops as 'custom'.
This commit is contained in:
parent
82c22f1248
commit
791040cd8b
|
@ -4418,6 +4418,10 @@ public:
|
||||||
SDValue getVectorElementPointer(SelectionDAG &DAG, SDValue VecPtr, EVT VecVT,
|
SDValue getVectorElementPointer(SelectionDAG &DAG, SDValue VecPtr, EVT VecVT,
|
||||||
SDValue Index) const;
|
SDValue Index) const;
|
||||||
|
|
||||||
|
/// Method for building the DAG expansion of ISD::[US][MIN|MAX]. This
|
||||||
|
/// method accepts integers as its arguments.
|
||||||
|
SDValue expandIntMINMAX(SDNode *Node, SelectionDAG &DAG) const;
|
||||||
|
|
||||||
/// Method for building the DAG expansion of ISD::[US][ADD|SUB]SAT. This
|
/// Method for building the DAG expansion of ISD::[US][ADD|SUB]SAT. This
|
||||||
/// method accepts integers as its arguments.
|
/// method accepts integers as its arguments.
|
||||||
SDValue expandAddSubSat(SDNode *Node, SelectionDAG &DAG) const;
|
SDValue expandAddSubSat(SDNode *Node, SelectionDAG &DAG) const;
|
||||||
|
|
|
@ -812,6 +812,15 @@ void VectorLegalizer::Expand(SDNode *Node, SmallVectorImpl<SDValue> &Results) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case ISD::SMIN:
|
||||||
|
case ISD::SMAX:
|
||||||
|
case ISD::UMIN:
|
||||||
|
case ISD::UMAX:
|
||||||
|
if (SDValue Expanded = TLI.expandIntMINMAX(Node, DAG)) {
|
||||||
|
Results.push_back(Expanded);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case ISD::UADDO:
|
case ISD::UADDO:
|
||||||
case ISD::USUBO:
|
case ISD::USUBO:
|
||||||
ExpandUADDSUBO(Node, Results);
|
ExpandUADDSUBO(Node, Results);
|
||||||
|
|
|
@ -7458,6 +7458,31 @@ TargetLowering::getCanonicalIndexType(ISD::MemIndexType IndexType, EVT MemVT,
|
||||||
return IndexType;
|
return IndexType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SDValue TargetLowering::expandIntMINMAX(SDNode *Node, SelectionDAG &DAG) const {
|
||||||
|
SDValue Op0 = Node->getOperand(0);
|
||||||
|
SDValue Op1 = Node->getOperand(1);
|
||||||
|
EVT VT = Op0.getValueType();
|
||||||
|
|
||||||
|
// Expand Y = MAX(A, B) -> Y = (A > B) ? A : B
|
||||||
|
ISD::CondCode CC;
|
||||||
|
switch (Node->getOpcode()) {
|
||||||
|
default: llvm_unreachable("How did we get here?");
|
||||||
|
case ISD::SMAX: CC = ISD::SETGT; break;
|
||||||
|
case ISD::SMIN: CC = ISD::SETLT; break;
|
||||||
|
case ISD::UMAX: CC = ISD::SETUGT; break;
|
||||||
|
case ISD::UMIN: CC = ISD::SETULT; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: Should really try to split the vector in case it's legal on a
|
||||||
|
// subvector.
|
||||||
|
if (VT.isVector() && !isOperationLegalOrCustom(ISD::VSELECT, VT))
|
||||||
|
return DAG.UnrollVectorOp(Node);
|
||||||
|
|
||||||
|
SDLoc DL(Node);
|
||||||
|
SDValue Cond = DAG.getSetCC(DL, VT, Op0, Op1, CC);
|
||||||
|
return DAG.getSelect(DL, VT, Cond, Op0, Op1);
|
||||||
|
}
|
||||||
|
|
||||||
SDValue TargetLowering::expandAddSubSat(SDNode *Node, SelectionDAG &DAG) const {
|
SDValue TargetLowering::expandAddSubSat(SDNode *Node, SelectionDAG &DAG) const {
|
||||||
unsigned Opcode = Node->getOpcode();
|
unsigned Opcode = Node->getOpcode();
|
||||||
SDValue LHS = Node->getOperand(0);
|
SDValue LHS = Node->getOperand(0);
|
||||||
|
|
|
@ -26975,18 +26975,8 @@ static SDValue LowerMINMAX(SDValue Op, SelectionDAG &DAG) {
|
||||||
DAG.getNode(ISD::USUBSAT, DL, VT, N1, N0), N0);
|
DAG.getNode(ISD::USUBSAT, DL, VT, N1, N0), N0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Else, expand to a compare/select.
|
// Default to expand.
|
||||||
ISD::CondCode CC;
|
return SDValue();
|
||||||
switch (Opcode) {
|
|
||||||
case ISD::SMIN: CC = ISD::CondCode::SETLT; break;
|
|
||||||
case ISD::SMAX: CC = ISD::CondCode::SETGT; break;
|
|
||||||
case ISD::UMIN: CC = ISD::CondCode::SETULT; break;
|
|
||||||
case ISD::UMAX: CC = ISD::CondCode::SETUGT; break;
|
|
||||||
default: llvm_unreachable("Unknown MINMAX opcode");
|
|
||||||
}
|
|
||||||
|
|
||||||
SDValue Cond = DAG.getSetCC(DL, VT, N0, N1, CC);
|
|
||||||
return DAG.getSelect(DL, VT, Cond, N0, N1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static SDValue LowerMUL(SDValue Op, const X86Subtarget &Subtarget,
|
static SDValue LowerMUL(SDValue Op, const X86Subtarget &Subtarget,
|
||||||
|
|
Loading…
Reference in New Issue