diff options
author | Chris Lattner <sabre@nondot.org> | 2004-05-27 07:25:00 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2004-05-27 07:25:00 +0000 |
commit | c6e21fbd5c35ea8a92bc3a9608ceaaa7a58aa647 (patch) | |
tree | 1872373dc9f9107dd1ea2556ec7353cc1fb6101d /llvm/lib/Transforms | |
parent | 5f1a5bb735a792c2e6b34272cc25940ea1ae6c5c (diff) | |
download | bcm5719-llvm-c6e21fbd5c35ea8a92bc3a9608ceaaa7a58aa647.tar.gz bcm5719-llvm-c6e21fbd5c35ea8a92bc3a9608ceaaa7a58aa647.zip |
Implement constant folding of fmod, which is used a lot in povray
llvm-svn: 13823
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/Utils/Local.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index 1675f716109..256ddfdbccb 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/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); } |