From 2c2e76a9e24a9f90808dfa159af05712bf9236e7 Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Fri, 8 Mar 2019 11:16:55 +0000 Subject: [PATCH] [DAGCombine] Merge visitSSUBO+visitUSUBO into visitSUBO. NFCI. llvm-svn: 355688 --- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 41 ++++++--------------------- 1 file changed, 8 insertions(+), 33 deletions(-) diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 770c15c..9371161 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -299,8 +299,7 @@ namespace { SDValue visitUADDO(SDNode *N); SDValue visitUADDOLike(SDValue N0, SDValue N1, SDNode *N); SDValue visitSUBC(SDNode *N); - SDValue visitSSUBO(SDNode *N); - SDValue visitUSUBO(SDNode *N); + SDValue visitSUBO(SDNode *N); SDValue visitADDE(SDNode *N); SDValue visitADDCARRY(SDNode *N); SDValue visitADDCARRYLike(SDValue N0, SDValue N1, SDValue CarryIn, SDNode *N); @@ -1497,8 +1496,8 @@ SDValue DAGCombiner::visit(SDNode *N) { case ISD::SADDO: return visitSADDO(N); case ISD::UADDO: return visitUADDO(N); case ISD::SUBC: return visitSUBC(N); - case ISD::SSUBO: return visitSSUBO(N); - case ISD::USUBO: return visitUSUBO(N); + case ISD::SSUBO: + case ISD::USUBO: return visitSUBO(N); case ISD::ADDE: return visitADDE(N); case ISD::ADDCARRY: return visitADDCARRY(N); case ISD::SUBE: return visitSUBE(N); @@ -2925,35 +2924,11 @@ SDValue DAGCombiner::visitSUBC(SDNode *N) { return SDValue(); } -// TODO: merge this with DAGCombiner::visitUSUBO -SDValue DAGCombiner::visitSSUBO(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 SUB. - if (!N->hasAnyUseOfValue(1)) - return CombineTo(N, DAG.getNode(ISD::SUB, DL, VT, N0, N1), - DAG.getUNDEF(CarryVT)); - - // fold (ssubo x, x) -> 0 + no borrow - if (N0 == N1) - return CombineTo(N, DAG.getConstant(0, DL, VT), - DAG.getConstant(0, DL, CarryVT)); - - // fold (ssubo x, 0) -> x + no borrow - if (isNullOrNullSplat(N1)) - return CombineTo(N, N0, DAG.getConstant(0, DL, CarryVT)); - - return SDValue(); -} - -SDValue DAGCombiner::visitUSUBO(SDNode *N) { +SDValue DAGCombiner::visitSUBO(SDNode *N) { SDValue N0 = N->getOperand(0); SDValue N1 = N->getOperand(1); EVT VT = N0.getValueType(); + bool IsSigned = (ISD::SSUBO == N->getOpcode()); EVT CarryVT = N->getValueType(1); SDLoc DL(N); @@ -2963,17 +2938,17 @@ SDValue DAGCombiner::visitUSUBO(SDNode *N) { return CombineTo(N, DAG.getNode(ISD::SUB, DL, VT, N0, N1), DAG.getUNDEF(CarryVT)); - // fold (usubo x, x) -> 0 + no borrow + // fold (subo x, x) -> 0 + no borrow if (N0 == N1) return CombineTo(N, DAG.getConstant(0, DL, VT), DAG.getConstant(0, DL, CarryVT)); - // fold (usubo x, 0) -> x + no borrow + // fold (subo x, 0) -> x + no borrow if (isNullOrNullSplat(N1)) return CombineTo(N, N0, DAG.getConstant(0, DL, CarryVT)); // Canonicalize (usubo -1, x) -> ~x, i.e. (xor x, -1) + no borrow - if (isAllOnesOrAllOnesSplat(N0)) + if (!IsSigned && isAllOnesOrAllOnesSplat(N0)) return CombineTo(N, DAG.getNode(ISD::XOR, DL, VT, N1, N0), DAG.getConstant(0, DL, CarryVT)); -- 2.7.4