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,11 +4465,10 @@ public:
|
||||||
/// vector nodes can only succeed if all operations are legal/custom.
|
/// vector nodes can only succeed if all operations are legal/custom.
|
||||||
/// (ABS x) -> (XOR (ADD x, (SRA x, type_size)), (SRA x, type_size))
|
/// (ABS x) -> (XOR (ADD x, (SRA x, type_size)), (SRA x, type_size))
|
||||||
/// \param N Node to expand
|
/// \param N Node to expand
|
||||||
/// \param Result output after conversion
|
|
||||||
/// \param IsNegative indicate negated abs
|
/// \param IsNegative indicate negated abs
|
||||||
/// \returns True, if the expansion was successful, false otherwise
|
/// \returns The expansion result or SDValue() if it fails.
|
||||||
bool expandABS(SDNode *N, SDValue &Result, SelectionDAG &DAG,
|
SDValue expandABS(SDNode *N, SelectionDAG &DAG,
|
||||||
bool IsNegative = false) const;
|
bool IsNegative = false) const;
|
||||||
|
|
||||||
/// Expand BSWAP nodes. Expands scalar/vector BSWAP nodes with i16/i32/i64
|
/// Expand BSWAP nodes. Expands scalar/vector BSWAP nodes with i16/i32/i64
|
||||||
/// scalar types. Returns SDValue() if expand fails.
|
/// scalar types. Returns SDValue() if expand fails.
|
||||||
|
|
|
@ -3319,11 +3319,10 @@ SDValue DAGCombiner::visitSUB(SDNode *N) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert 0 - abs(x).
|
// Convert 0 - abs(x).
|
||||||
SDValue Result;
|
|
||||||
if (N1->getOpcode() == ISD::ABS &&
|
if (N1->getOpcode() == ISD::ABS &&
|
||||||
!TLI.isOperationLegalOrCustom(ISD::ABS, VT) &&
|
!TLI.isOperationLegalOrCustom(ISD::ABS, VT))
|
||||||
TLI.expandABS(N1.getNode(), Result, DAG, true))
|
if (SDValue Result = TLI.expandABS(N1.getNode(), DAG, true))
|
||||||
return Result;
|
return Result;
|
||||||
|
|
||||||
// Fold neg(splat(neg(x)) -> splat(x)
|
// Fold neg(splat(neg(x)) -> splat(x)
|
||||||
if (VT.isVector()) {
|
if (VT.isVector()) {
|
||||||
|
|
|
@ -2684,7 +2684,7 @@ bool SelectionDAGLegalize::ExpandNode(SDNode *Node) {
|
||||||
bool NeedInvert;
|
bool NeedInvert;
|
||||||
switch (Node->getOpcode()) {
|
switch (Node->getOpcode()) {
|
||||||
case ISD::ABS:
|
case ISD::ABS:
|
||||||
if (TLI.expandABS(Node, Tmp1, DAG))
|
if ((Tmp1 = TLI.expandABS(Node, DAG)))
|
||||||
Results.push_back(Tmp1);
|
Results.push_back(Tmp1);
|
||||||
break;
|
break;
|
||||||
case ISD::CTPOP:
|
case ISD::CTPOP:
|
||||||
|
|
|
@ -774,8 +774,8 @@ void VectorLegalizer::Expand(SDNode *Node, SmallVectorImpl<SDValue> &Results) {
|
||||||
ExpandSETCC(Node, Results);
|
ExpandSETCC(Node, Results);
|
||||||
return;
|
return;
|
||||||
case ISD::ABS:
|
case ISD::ABS:
|
||||||
if (TLI.expandABS(Node, Tmp, DAG)) {
|
if (SDValue Expanded = TLI.expandABS(Node, DAG)) {
|
||||||
Results.push_back(Tmp);
|
Results.push_back(Expanded);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -7145,8 +7145,8 @@ SDValue TargetLowering::expandCTTZ(SDNode *Node, SelectionDAG &DAG) const {
|
||||||
return DAG.getNode(ISD::CTPOP, dl, VT, Tmp);
|
return DAG.getNode(ISD::CTPOP, dl, VT, Tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TargetLowering::expandABS(SDNode *N, SDValue &Result,
|
SDValue TargetLowering::expandABS(SDNode *N, SelectionDAG &DAG,
|
||||||
SelectionDAG &DAG, bool IsNegative) const {
|
bool IsNegative) const {
|
||||||
SDLoc dl(N);
|
SDLoc dl(N);
|
||||||
EVT VT = N->getValueType(0);
|
EVT VT = N->getValueType(0);
|
||||||
EVT ShVT = getShiftAmountTy(VT, DAG.getDataLayout());
|
EVT ShVT = getShiftAmountTy(VT, DAG.getDataLayout());
|
||||||
|
@ -7156,27 +7156,24 @@ bool TargetLowering::expandABS(SDNode *N, SDValue &Result,
|
||||||
if (!IsNegative && isOperationLegal(ISD::SUB, VT) &&
|
if (!IsNegative && isOperationLegal(ISD::SUB, VT) &&
|
||||||
isOperationLegal(ISD::SMAX, VT)) {
|
isOperationLegal(ISD::SMAX, VT)) {
|
||||||
SDValue Zero = DAG.getConstant(0, dl, 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));
|
DAG.getNode(ISD::SUB, dl, VT, Zero, Op));
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// abs(x) -> umin(x,sub(0,x))
|
// abs(x) -> umin(x,sub(0,x))
|
||||||
if (!IsNegative && isOperationLegal(ISD::SUB, VT) &&
|
if (!IsNegative && isOperationLegal(ISD::SUB, VT) &&
|
||||||
isOperationLegal(ISD::UMIN, VT)) {
|
isOperationLegal(ISD::UMIN, VT)) {
|
||||||
SDValue Zero = DAG.getConstant(0, dl, 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));
|
DAG.getNode(ISD::SUB, dl, VT, Zero, Op));
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 0 - abs(x) -> smin(x, sub(0,x))
|
// 0 - abs(x) -> smin(x, sub(0,x))
|
||||||
if (IsNegative && isOperationLegal(ISD::SUB, VT) &&
|
if (IsNegative && isOperationLegal(ISD::SUB, VT) &&
|
||||||
isOperationLegal(ISD::SMIN, VT)) {
|
isOperationLegal(ISD::SMIN, VT)) {
|
||||||
SDValue Zero = DAG.getConstant(0, dl, 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));
|
DAG.getNode(ISD::SUB, dl, VT, Zero, Op));
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only expand vector types if we have the appropriate vector operations.
|
// 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::ADD, VT)) ||
|
||||||
(IsNegative && !isOperationLegalOrCustom(ISD::SUB, VT)) ||
|
(IsNegative && !isOperationLegalOrCustom(ISD::SUB, VT)) ||
|
||||||
!isOperationLegalOrCustomOrPromote(ISD::XOR, VT)))
|
!isOperationLegalOrCustomOrPromote(ISD::XOR, VT)))
|
||||||
return false;
|
return SDValue();
|
||||||
|
|
||||||
SDValue Shift =
|
SDValue Shift =
|
||||||
DAG.getNode(ISD::SRA, dl, VT, Op,
|
DAG.getNode(ISD::SRA, dl, VT, Op,
|
||||||
DAG.getConstant(VT.getScalarSizeInBits() - 1, dl, ShVT));
|
DAG.getConstant(VT.getScalarSizeInBits() - 1, dl, ShVT));
|
||||||
if (!IsNegative) {
|
if (!IsNegative) {
|
||||||
SDValue Add = DAG.getNode(ISD::ADD, dl, VT, Op, Shift);
|
SDValue Add = DAG.getNode(ISD::ADD, dl, VT, Op, Shift);
|
||||||
Result = DAG.getNode(ISD::XOR, dl, VT, Add, Shift);
|
return DAG.getNode(ISD::XOR, dl, VT, Add, Shift);
|
||||||
} else {
|
|
||||||
// 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;
|
|
||||||
|
// 0 - abs(x) -> Y = sra (X, size(X)-1); sub (Y, xor (X, Y))
|
||||||
|
SDValue Xor = DAG.getNode(ISD::XOR, dl, VT, Op, Shift);
|
||||||
|
return DAG.getNode(ISD::SUB, dl, VT, Shift, Xor);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDValue TargetLowering::expandBSWAP(SDNode *N, SelectionDAG &DAG) const {
|
SDValue TargetLowering::expandBSWAP(SDNode *N, SelectionDAG &DAG) const {
|
||||||
|
|
|
@ -13092,19 +13092,15 @@ static SDValue PerformVSELECTCombine(SDNode *N,
|
||||||
}
|
}
|
||||||
|
|
||||||
static SDValue PerformABSCombine(SDNode *N,
|
static SDValue PerformABSCombine(SDNode *N,
|
||||||
TargetLowering::DAGCombinerInfo &DCI,
|
TargetLowering::DAGCombinerInfo &DCI,
|
||||||
const ARMSubtarget *Subtarget) {
|
const ARMSubtarget *Subtarget) {
|
||||||
SDValue res;
|
|
||||||
SelectionDAG &DAG = DCI.DAG;
|
SelectionDAG &DAG = DCI.DAG;
|
||||||
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
|
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
|
||||||
|
|
||||||
if (TLI.isOperationLegal(N->getOpcode(), N->getValueType(0)))
|
if (TLI.isOperationLegal(N->getOpcode(), N->getValueType(0)))
|
||||||
return SDValue();
|
return SDValue();
|
||||||
|
|
||||||
if (!TLI.expandABS(N, res, DAG))
|
return TLI.expandABS(N, DAG);
|
||||||
return SDValue();
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// PerformADDECombine - Target-specific dag combine transform from
|
/// PerformADDECombine - Target-specific dag combine transform from
|
||||||
|
|
Loading…
Reference in New Issue