[llvm-commits] CVS: llvm/lib/Transforms/Utils/Local.cpp
Chris Lattner
lattner at cs.uiuc.edu
Thu May 27 02:28:02 PDT 2004
Changes in directory llvm/lib/Transforms/Utils:
Local.cpp updated: 1.23 -> 1.24
---
Log message:
Implement constant folding of fmod, which is used a lot in povray
---
Diffs of the changes: (+9 -2)
Index: llvm/lib/Transforms/Utils/Local.cpp
diff -u llvm/lib/Transforms/Utils/Local.cpp:1.23 llvm/lib/Transforms/Utils/Local.cpp:1.24
--- llvm/lib/Transforms/Utils/Local.cpp:1.23 Thu May 27 01:26:28 2004
+++ llvm/lib/Transforms/Utils/Local.cpp Thu May 27 02:25:00 2004
@@ -236,7 +236,7 @@
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 @@
} 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);
}
More information about the llvm-commits
mailing list