Allow i32 UDIV, SDIV, UREM, SREM to be expanded into libcalls.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30470 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Evan Cheng 2006-09-18 21:49:04 +00:00
parent 025f4c0fad
commit 52cc1ea2a1

View File

@ -2148,6 +2148,19 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) {
if (Tmp1.Val) Result = Tmp1;
break;
case TargetLowering::Expand: {
if (Node->getValueType(0) == MVT::i32) {
switch (Node->getOpcode()) {
default: assert(0 && "Do not know how to expand this integer BinOp!");
case ISD::UDIV:
case ISD::SDIV:
const char *FnName = Node->getOpcode() == ISD::UDIV
? "__udivsi3" : "__divsi3";
SDOperand Dummy;
Result = ExpandLibCall(FnName, Node, Dummy);
};
break;
}
assert(MVT::isVector(Node->getValueType(0)) &&
"Cannot expand this binary operator!");
// Expand the operation into a bunch of nasty scalar code.
@ -2318,13 +2331,24 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) {
}
break;
case TargetLowering::Expand:
unsigned DivOpc= (Node->getOpcode() == ISD::UREM) ? ISD::UDIV : ISD::SREM;
if (MVT::isInteger(Node->getValueType(0))) {
// X % Y -> X-X/Y*Y
MVT::ValueType VT = Node->getValueType(0);
unsigned Opc = Node->getOpcode() == ISD::UREM ? ISD::UDIV : ISD::SDIV;
Result = DAG.getNode(Opc, VT, Tmp1, Tmp2);
Result = DAG.getNode(ISD::MUL, VT, Result, Tmp2);
Result = DAG.getNode(ISD::SUB, VT, Tmp1, Result);
if (TLI.getOperationAction(DivOpc, Node->getValueType(0)) ==
TargetLowering::Legal) {
// X % Y -> X-X/Y*Y
MVT::ValueType VT = Node->getValueType(0);
unsigned Opc = Node->getOpcode() == ISD::UREM ? ISD::UDIV : ISD::SDIV;
Result = DAG.getNode(Opc, VT, Tmp1, Tmp2);
Result = DAG.getNode(ISD::MUL, VT, Result, Tmp2);
Result = DAG.getNode(ISD::SUB, VT, Tmp1, Result);
} else {
assert(Node->getValueType(0) == MVT::i32 &&
"Cannot expand this binary operator!");
const char *FnName = Node->getOpcode() == ISD::UREM
? "__umodsi3" : "__modsi3";
SDOperand Dummy;
Result = ExpandLibCall(FnName, Node, Dummy);
}
} else {
// Floating point mod -> fmod libcall.
const char *FnName = Node->getValueType(0) == MVT::f32 ? "fmodf":"fmod";