From 57da25231aaa5f9bbc981cd8bb8722ff129bf8a0 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 23 Aug 2005 20:22:50 +0000 Subject: [PATCH] Fix PR618 and Regression/CodeGen/CBackend/2005-08-23-Fmod.ll by not emitting x%y for 'rem' on fp values. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22984 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/CBackend/CBackend.cpp | 14 ++++++++++++++ lib/Target/CBackend/Writer.cpp | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp index fc87afd2062..df06c7ca24d 100644 --- a/lib/Target/CBackend/CBackend.cpp +++ b/lib/Target/CBackend/CBackend.cpp @@ -871,6 +871,9 @@ bool CWriter::doInitialization(Module &M) { } // Function declarations + Out << "double fmod(double, double);\n"; // Support for FP rem + Out << "float fmodf(float, float);\n"; + if (!M.empty()) { Out << "\n/* Function Declarations */\n"; for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) { @@ -1349,6 +1352,17 @@ void CWriter::visitBinaryOperator(Instruction &I) { Out << "-("; writeOperand(BinaryOperator::getNegArgument(cast(&I))); Out << ")"; + } else if (I.getOpcode() == Instruction::Rem && + I.getType()->isFloatingPoint()) { + // Output a call to fmod/fmodf instead of emitting a%b + if (I.getType() == Type::FloatTy) + Out << "fmodf("; + else + Out << "fmod("; + writeOperand(I.getOperand(0)); + Out << ", "; + writeOperand(I.getOperand(1)); + Out << ")"; } else { writeOperand(I.getOperand(0)); diff --git a/lib/Target/CBackend/Writer.cpp b/lib/Target/CBackend/Writer.cpp index fc87afd2062..df06c7ca24d 100644 --- a/lib/Target/CBackend/Writer.cpp +++ b/lib/Target/CBackend/Writer.cpp @@ -871,6 +871,9 @@ bool CWriter::doInitialization(Module &M) { } // Function declarations + Out << "double fmod(double, double);\n"; // Support for FP rem + Out << "float fmodf(float, float);\n"; + if (!M.empty()) { Out << "\n/* Function Declarations */\n"; for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) { @@ -1349,6 +1352,17 @@ void CWriter::visitBinaryOperator(Instruction &I) { Out << "-("; writeOperand(BinaryOperator::getNegArgument(cast(&I))); Out << ")"; + } else if (I.getOpcode() == Instruction::Rem && + I.getType()->isFloatingPoint()) { + // Output a call to fmod/fmodf instead of emitting a%b + if (I.getType() == Type::FloatTy) + Out << "fmodf("; + else + Out << "fmod("; + writeOperand(I.getOperand(0)); + Out << ", "; + writeOperand(I.getOperand(1)); + Out << ")"; } else { writeOperand(I.getOperand(0));