Add generic expansion of SUB when ADD and XOR

are legal.  Based on a patch by Micah Villmow.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71078 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan Sands 2009-05-06 11:29:50 +00:00
parent cfd0ebea27
commit a9cad0e7e0

View File

@ -3268,8 +3268,7 @@ SDValue SelectionDAGLegalize::LegalizeOp(SDValue Op) {
OpToUse = ISD::UMUL_LOHI; OpToUse = ISD::UMUL_LOHI;
} }
if (OpToUse) { if (OpToUse) {
Result = SDValue(DAG.getNode(OpToUse, dl, VTs, Tmp1, Tmp2).getNode(), Result = DAG.getNode(OpToUse, dl, VTs, Tmp1, Tmp2);
0);
break; break;
} }
} }
@ -3289,16 +3288,21 @@ SDValue SelectionDAGLegalize::LegalizeOp(SDValue Op) {
} }
if (Node->getOpcode() == ISD::SDIV && if (Node->getOpcode() == ISD::SDIV &&
TLI.isOperationLegalOrCustom(ISD::SDIVREM, VT)) { TLI.isOperationLegalOrCustom(ISD::SDIVREM, VT)) {
Result = SDValue(DAG.getNode(ISD::SDIVREM, dl, Result = DAG.getNode(ISD::SDIVREM, dl, VTs, Tmp1, Tmp2);
VTs, Tmp1, Tmp2).getNode(),
0);
break; break;
} }
if (Node->getOpcode() == ISD::UDIV && if (Node->getOpcode() == ISD::UDIV &&
TLI.isOperationLegalOrCustom(ISD::UDIVREM, VT)) { TLI.isOperationLegalOrCustom(ISD::UDIVREM, VT)) {
Result = SDValue(DAG.getNode(ISD::UDIVREM, dl, Result = DAG.getNode(ISD::UDIVREM, dl, VTs, Tmp1, Tmp2);
VTs, Tmp1, Tmp2).getNode(), break;
0); }
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; break;
} }