From 4c64dd7977bc676399df0d5d2bf8016a3242780e Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 3 Aug 2005 20:31:37 +0000 Subject: [PATCH] Fix PR611, codegen'ing SREM of FP operands to fmod or fmodf instead of the sequence used for integer ops git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22629 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/SelectionDAG/LegalizeDAG.cpp | 18 ++++++++++++------ .../SelectionDAG/SelectionDAGPrinter.cpp | 2 ++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp index 9e9f4fa4879..69cd725cafb 100644 --- a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp +++ b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp @@ -1306,12 +1306,18 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) { case TargetLowering::Promote: case TargetLowering::Custom: assert(0 && "Cannot promote/custom handle this yet!"); - case TargetLowering::Expand: { - 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); + case TargetLowering::Expand: + if (MVT::isInteger(Node->getValueType(0))) { + 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 { + // Floating point mod -> fmod libcall. + const char *FnName = Node->getValueType(0) == MVT::f32 ? "fmodf":"fmod"; + SDOperand Dummy; + Result = ExpandLibCall(FnName, Node, Dummy); } break; } diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp index a554b625f28..3b4cb287f83 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp @@ -124,6 +124,7 @@ void SelectionDAG::viewGraph() { if (system((LLVM_PATH_GRAPHVIZ " " + Filename).c_str())) { std::cerr << "Error viewing graph: 'Graphviz' not in path?\n"; } else { + system(("rm " + Filename).c_str()); return; } #endif @@ -143,4 +144,5 @@ void SelectionDAG::viewGraph() { #endif std::cerr << "SelectionDAG::viewGraph is only available in debug builds on " << "systems with Graphviz or gv!\n"; + system(("rm " + Filename).c_str()); }