summaryrefslogtreecommitdiff
path: root/lib/Transforms/Utils/Local.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-05-27 07:25:00 +0000
committerChris Lattner <sabre@nondot.org>2004-05-27 07:25:00 +0000
commit8dfe5705b16eeebec701f725351cc5a6102e0dfd (patch)
tree83e62332694c4b63cdf2f12597277b1a7a98779b /lib/Transforms/Utils/Local.cpp
parentb04cb7daf5a9d7b57450b0612e699df49fcb7cbe (diff)
downloadllvm-8dfe5705b16eeebec701f725351cc5a6102e0dfd.tar.gz
llvm-8dfe5705b16eeebec701f725351cc5a6102e0dfd.tar.bz2
llvm-8dfe5705b16eeebec701f725351cc5a6102e0dfd.tar.xz
Implement constant folding of fmod, which is used a lot in povray
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13823 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils/Local.cpp')
-rw-r--r--lib/Transforms/Utils/Local.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/Transforms/Utils/Local.cpp b/lib/Transforms/Utils/Local.cpp
index 1675f71610..256ddfdbcc 100644
--- a/lib/Transforms/Utils/Local.cpp
+++ b/lib/Transforms/Utils/Local.cpp
@@ -236,7 +236,7 @@ bool llvm::canConstantFoldCallTo(Function *F) {
const std::string &Name = F->getName();
return Name == "sin" || Name == "cos" || Name == "tan" || Name == "sqrt" ||
Name == "log" || Name == "log10" || Name == "exp" || Name == "pow" ||
- Name == "acos" || Name == "asin";
+ Name == "acos" || Name == "asin" || Name == "atan" || Name == "fmod";
}
static Constant *ConstantFoldFP(double (*NativeFP)(double), double V,
@@ -282,9 +282,16 @@ Constant *llvm::ConstantFoldCall(Function *F,
} else if (Operands.size() == 2) {
if (ConstantFP *Op1 = dyn_cast<ConstantFP>(Operands[0]))
if (ConstantFP *Op2 = dyn_cast<ConstantFP>(Operands[1])) {
+ double Op1V = Op1->getValue(), Op2V = Op2->getValue();
+
if (Name == "pow") {
errno = 0;
- double V = pow(Op1->getValue(), Op2->getValue());
+ double V = pow(Op1V, Op2V);
+ if (errno == 0)
+ return ConstantFP::get(Ty, V);
+ } else if (Name == "fmod") {
+ errno = 0;
+ double V = fmod(Op1V, Op2V);
if (errno == 0)
return ConstantFP::get(Ty, V);
}