From 2338f6c57e3ceb848c99d34fd22eef05b779a1ff Mon Sep 17 00:00:00 2001 From: Duncan Sands Date: Wed, 6 May 2009 11:29:50 +0000 Subject: [PATCH] Add generic expansion of SUB when ADD and XOR are legal. Based on a patch by Micah Villmow. llvm-svn: 71078 --- llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp index bdcad0a3b5ea..ca5f962a869f 100644 --- a/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp @@ -3268,8 +3268,7 @@ SDValue SelectionDAGLegalize::LegalizeOp(SDValue Op) { OpToUse = ISD::UMUL_LOHI; } if (OpToUse) { - Result = SDValue(DAG.getNode(OpToUse, dl, VTs, Tmp1, Tmp2).getNode(), - 0); + Result = DAG.getNode(OpToUse, dl, VTs, Tmp1, Tmp2); break; } } @@ -3289,16 +3288,21 @@ SDValue SelectionDAGLegalize::LegalizeOp(SDValue Op) { } if (Node->getOpcode() == ISD::SDIV && TLI.isOperationLegalOrCustom(ISD::SDIVREM, VT)) { - Result = SDValue(DAG.getNode(ISD::SDIVREM, dl, - VTs, Tmp1, Tmp2).getNode(), - 0); + Result = DAG.getNode(ISD::SDIVREM, dl, VTs, Tmp1, Tmp2); break; } if (Node->getOpcode() == ISD::UDIV && TLI.isOperationLegalOrCustom(ISD::UDIVREM, VT)) { - Result = SDValue(DAG.getNode(ISD::UDIVREM, dl, - VTs, Tmp1, Tmp2).getNode(), - 0); + Result = DAG.getNode(ISD::UDIVREM, dl, VTs, Tmp1, Tmp2); + break; + } + if (Node->getOpcode() == ISD::SUB && + TLI.isOperationLegalOrCustom(ISD::ADD, VT) && + TLI.isOperationLegalOrCustom(ISD::XOR, VT)) { + Tmp2 = DAG.getNode(ISD::XOR, dl, VT, Tmp2, + DAG.getConstant(APInt::getAllOnesValue(VT.getSizeInBits()), VT)); + Tmp2 = DAG.getNode(ISD::ADD, dl, VT, Tmp2, DAG.getConstant(1, VT)); + Result = DAG.getNode(ISD::ADD, dl, VT, Tmp1, Tmp2); break; }