From c71d6d157f06619d3091d396da71cc2007579b99 Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Fri, 8 Mar 2019 11:30:33 +0000 Subject: [PATCH] [DAGCombine] Merge visitSADDO+visitUADDO into visitADDO. NFCI. llvm-svn: 355689 --- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 72 +++++++++------------------ 1 file changed, 24 insertions(+), 48 deletions(-) diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 9371161..2a01a17 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -295,8 +295,7 @@ namespace { SDValue visitADDSAT(SDNode *N); SDValue visitSUBSAT(SDNode *N); SDValue visitADDC(SDNode *N); - SDValue visitSADDO(SDNode *N); - SDValue visitUADDO(SDNode *N); + SDValue visitADDO(SDNode *N); SDValue visitUADDOLike(SDValue N0, SDValue N1, SDNode *N); SDValue visitSUBC(SDNode *N); SDValue visitSUBO(SDNode *N); @@ -1493,8 +1492,8 @@ SDValue DAGCombiner::visit(SDNode *N) { case ISD::SSUBSAT: case ISD::USUBSAT: return visitSUBSAT(N); case ISD::ADDC: return visitADDC(N); - case ISD::SADDO: return visitSADDO(N); - case ISD::UADDO: return visitUADDO(N); + case ISD::SADDO: + case ISD::UADDO: return visitADDO(N); case ISD::SUBC: return visitSUBC(N); case ISD::SSUBO: case ISD::USUBO: return visitSUBO(N); @@ -2416,35 +2415,11 @@ static bool isBooleanFlip(SDValue V, EVT VT, const TargetLowering &TLI) { llvm_unreachable("Unsupported boolean content"); } -// TODO: merge this with DAGCombiner::visitUADDO -SDValue DAGCombiner::visitSADDO(SDNode *N) { - SDValue N0 = N->getOperand(0); - SDValue N1 = N->getOperand(1); - EVT VT = N0.getValueType(); - EVT CarryVT = N->getValueType(1); - SDLoc DL(N); - - // If the flag result is dead, turn this into an ADD. - if (!N->hasAnyUseOfValue(1)) - return CombineTo(N, DAG.getNode(ISD::ADD, DL, VT, N0, N1), - DAG.getUNDEF(CarryVT)); - - // canonicalize constant to RHS. - if (DAG.isConstantIntBuildVectorOrConstantInt(N0) && - !DAG.isConstantIntBuildVectorOrConstantInt(N1)) - return DAG.getNode(ISD::SADDO, DL, N->getVTList(), N1, N0); - - // fold (saddo x, 0) -> x + no carry out - if (isNullOrNullSplat(N1)) - return CombineTo(N, N0, DAG.getConstant(0, DL, CarryVT)); - - return SDValue(); -} - -SDValue DAGCombiner::visitUADDO(SDNode *N) { +SDValue DAGCombiner::visitADDO(SDNode *N) { SDValue N0 = N->getOperand(0); SDValue N1 = N->getOperand(1); EVT VT = N0.getValueType(); + bool IsSigned = (ISD::SADDO == N->getOpcode()); EVT CarryVT = N->getValueType(1); SDLoc DL(N); @@ -2457,31 +2432,32 @@ SDValue DAGCombiner::visitUADDO(SDNode *N) { // canonicalize constant to RHS. if (DAG.isConstantIntBuildVectorOrConstantInt(N0) && !DAG.isConstantIntBuildVectorOrConstantInt(N1)) - return DAG.getNode(ISD::UADDO, DL, N->getVTList(), N1, N0); + return DAG.getNode(N->getOpcode(), DL, N->getVTList(), N1, N0); - // fold (uaddo x, 0) -> x + no carry out + // fold (addo x, 0) -> x + no carry out if (isNullOrNullSplat(N1)) return CombineTo(N, N0, DAG.getConstant(0, DL, CarryVT)); - // If it cannot overflow, transform into an add. - if (DAG.computeOverflowKind(N0, N1) == SelectionDAG::OFK_Never) - return CombineTo(N, DAG.getNode(ISD::ADD, DL, VT, N0, N1), - DAG.getConstant(0, DL, CarryVT)); + if (!IsSigned) { + // If it cannot overflow, transform into an add. + if (DAG.computeOverflowKind(N0, N1) == SelectionDAG::OFK_Never) + return CombineTo(N, DAG.getNode(ISD::ADD, DL, VT, N0, N1), + DAG.getConstant(0, DL, CarryVT)); - // fold (uaddo (xor a, -1), 1) -> (usub 0, a) and flip carry. - if (isBitwiseNot(N0) && isOneOrOneSplat(N1)) { - SDValue Sub = DAG.getNode(ISD::USUBO, DL, N->getVTList(), - DAG.getConstant(0, DL, VT), - N0.getOperand(0)); - return CombineTo(N, Sub, - flipBoolean(Sub.getValue(1), DL, CarryVT, DAG, TLI)); - } + // fold (uaddo (xor a, -1), 1) -> (usub 0, a) and flip carry. + if (isBitwiseNot(N0) && isOneOrOneSplat(N1)) { + SDValue Sub = DAG.getNode(ISD::USUBO, DL, N->getVTList(), + DAG.getConstant(0, DL, VT), N0.getOperand(0)); + return CombineTo(N, Sub, + flipBoolean(Sub.getValue(1), DL, CarryVT, DAG, TLI)); + } - if (SDValue Combined = visitUADDOLike(N0, N1, N)) - return Combined; + if (SDValue Combined = visitUADDOLike(N0, N1, N)) + return Combined; - if (SDValue Combined = visitUADDOLike(N1, N0, N)) - return Combined; + if (SDValue Combined = visitUADDOLike(N1, N0, N)) + return Combined; + } return SDValue(); } -- 2.7.4