forked from OSchip/llvm-project
[TargetLowering] Simplify the interface of expandABS. NFC
Instead of returning a bool to indicate success and a separate SDValue, return the SDValue and have the callers check if it is null. Reviewed By: RKSimon Differential Revision: https://reviews.llvm.org/D112331
This commit is contained in:
parent
0f12cf7eba
commit
04c184bba7
|
@ -4465,10 +4465,9 @@ public:
|
|||
/// vector nodes can only succeed if all operations are legal/custom.
|
||||
/// (ABS x) -> (XOR (ADD x, (SRA x, type_size)), (SRA x, type_size))
|
||||
/// \param N Node to expand
|
||||
/// \param Result output after conversion
|
||||
/// \param IsNegative indicate negated abs
|
||||
/// \returns True, if the expansion was successful, false otherwise
|
||||
bool expandABS(SDNode *N, SDValue &Result, SelectionDAG &DAG,
|
||||
/// \returns The expansion result or SDValue() if it fails.
|
||||
SDValue expandABS(SDNode *N, SelectionDAG &DAG,
|
||||
bool IsNegative = false) const;
|
||||
|
||||
/// Expand BSWAP nodes. Expands scalar/vector BSWAP nodes with i16/i32/i64
|
||||
|
|
|
@ -3319,10 +3319,9 @@ SDValue DAGCombiner::visitSUB(SDNode *N) {
|
|||
}
|
||||
|
||||
// Convert 0 - abs(x).
|
||||
SDValue Result;
|
||||
if (N1->getOpcode() == ISD::ABS &&
|
||||
!TLI.isOperationLegalOrCustom(ISD::ABS, VT) &&
|
||||
TLI.expandABS(N1.getNode(), Result, DAG, true))
|
||||
!TLI.isOperationLegalOrCustom(ISD::ABS, VT))
|
||||
if (SDValue Result = TLI.expandABS(N1.getNode(), DAG, true))
|
||||
return Result;
|
||||
|
||||
// Fold neg(splat(neg(x)) -> splat(x)
|
||||
|
|
|
@ -2684,7 +2684,7 @@ bool SelectionDAGLegalize::ExpandNode(SDNode *Node) {
|
|||
bool NeedInvert;
|
||||
switch (Node->getOpcode()) {
|
||||
case ISD::ABS:
|
||||
if (TLI.expandABS(Node, Tmp1, DAG))
|
||||
if ((Tmp1 = TLI.expandABS(Node, DAG)))
|
||||
Results.push_back(Tmp1);
|
||||
break;
|
||||
case ISD::CTPOP:
|
||||
|
|
|
@ -774,8 +774,8 @@ void VectorLegalizer::Expand(SDNode *Node, SmallVectorImpl<SDValue> &Results) {
|
|||
ExpandSETCC(Node, Results);
|
||||
return;
|
||||
case ISD::ABS:
|
||||
if (TLI.expandABS(Node, Tmp, DAG)) {
|
||||
Results.push_back(Tmp);
|
||||
if (SDValue Expanded = TLI.expandABS(Node, DAG)) {
|
||||
Results.push_back(Expanded);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -7145,8 +7145,8 @@ SDValue TargetLowering::expandCTTZ(SDNode *Node, SelectionDAG &DAG) const {
|
|||
return DAG.getNode(ISD::CTPOP, dl, VT, Tmp);
|
||||
}
|
||||
|
||||
bool TargetLowering::expandABS(SDNode *N, SDValue &Result,
|
||||
SelectionDAG &DAG, bool IsNegative) const {
|
||||
SDValue TargetLowering::expandABS(SDNode *N, SelectionDAG &DAG,
|
||||
bool IsNegative) const {
|
||||
SDLoc dl(N);
|
||||
EVT VT = N->getValueType(0);
|
||||
EVT ShVT = getShiftAmountTy(VT, DAG.getDataLayout());
|
||||
|
@ -7156,27 +7156,24 @@ bool TargetLowering::expandABS(SDNode *N, SDValue &Result,
|
|||
if (!IsNegative && isOperationLegal(ISD::SUB, VT) &&
|
||||
isOperationLegal(ISD::SMAX, VT)) {
|
||||
SDValue Zero = DAG.getConstant(0, dl, VT);
|
||||
Result = DAG.getNode(ISD::SMAX, dl, VT, Op,
|
||||
return DAG.getNode(ISD::SMAX, dl, VT, Op,
|
||||
DAG.getNode(ISD::SUB, dl, VT, Zero, Op));
|
||||
return true;
|
||||
}
|
||||
|
||||
// abs(x) -> umin(x,sub(0,x))
|
||||
if (!IsNegative && isOperationLegal(ISD::SUB, VT) &&
|
||||
isOperationLegal(ISD::UMIN, VT)) {
|
||||
SDValue Zero = DAG.getConstant(0, dl, VT);
|
||||
Result = DAG.getNode(ISD::UMIN, dl, VT, Op,
|
||||
return DAG.getNode(ISD::UMIN, dl, VT, Op,
|
||||
DAG.getNode(ISD::SUB, dl, VT, Zero, Op));
|
||||
return true;
|
||||
}
|
||||
|
||||
// 0 - abs(x) -> smin(x, sub(0,x))
|
||||
if (IsNegative && isOperationLegal(ISD::SUB, VT) &&
|
||||
isOperationLegal(ISD::SMIN, VT)) {
|
||||
SDValue Zero = DAG.getConstant(0, dl, VT);
|
||||
Result = DAG.getNode(ISD::SMIN, dl, VT, Op,
|
||||
return DAG.getNode(ISD::SMIN, dl, VT, Op,
|
||||
DAG.getNode(ISD::SUB, dl, VT, Zero, Op));
|
||||
return true;
|
||||
}
|
||||
|
||||
// Only expand vector types if we have the appropriate vector operations.
|
||||
|
@ -7185,20 +7182,19 @@ bool TargetLowering::expandABS(SDNode *N, SDValue &Result,
|
|||
(!IsNegative && !isOperationLegalOrCustom(ISD::ADD, VT)) ||
|
||||
(IsNegative && !isOperationLegalOrCustom(ISD::SUB, VT)) ||
|
||||
!isOperationLegalOrCustomOrPromote(ISD::XOR, VT)))
|
||||
return false;
|
||||
return SDValue();
|
||||
|
||||
SDValue Shift =
|
||||
DAG.getNode(ISD::SRA, dl, VT, Op,
|
||||
DAG.getConstant(VT.getScalarSizeInBits() - 1, dl, ShVT));
|
||||
if (!IsNegative) {
|
||||
SDValue Add = DAG.getNode(ISD::ADD, dl, VT, Op, Shift);
|
||||
Result = DAG.getNode(ISD::XOR, dl, VT, Add, Shift);
|
||||
} else {
|
||||
return DAG.getNode(ISD::XOR, dl, VT, Add, Shift);
|
||||
}
|
||||
|
||||
// 0 - abs(x) -> Y = sra (X, size(X)-1); sub (Y, xor (X, Y))
|
||||
SDValue Xor = DAG.getNode(ISD::XOR, dl, VT, Op, Shift);
|
||||
Result = DAG.getNode(ISD::SUB, dl, VT, Shift, Xor);
|
||||
}
|
||||
return true;
|
||||
return DAG.getNode(ISD::SUB, dl, VT, Shift, Xor);
|
||||
}
|
||||
|
||||
SDValue TargetLowering::expandBSWAP(SDNode *N, SelectionDAG &DAG) const {
|
||||
|
|
|
@ -13094,17 +13094,13 @@ static SDValue PerformVSELECTCombine(SDNode *N,
|
|||
static SDValue PerformABSCombine(SDNode *N,
|
||||
TargetLowering::DAGCombinerInfo &DCI,
|
||||
const ARMSubtarget *Subtarget) {
|
||||
SDValue res;
|
||||
SelectionDAG &DAG = DCI.DAG;
|
||||
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
|
||||
|
||||
if (TLI.isOperationLegal(N->getOpcode(), N->getValueType(0)))
|
||||
return SDValue();
|
||||
|
||||
if (!TLI.expandABS(N, res, DAG))
|
||||
return SDValue();
|
||||
|
||||
return res;
|
||||
return TLI.expandABS(N, DAG);
|
||||
}
|
||||
|
||||
/// PerformADDECombine - Target-specific dag combine transform from
|
||||
|
|
Loading…
Reference in New Issue