[llvm-commits] CVS: llvm/lib/Transforms/Utils/Local.cpp
Chris Lattner
lattner at cs.uiuc.edu
Fri Apr 16 17:36:01 PDT 2004
Changes in directory llvm/lib/Transforms/Utils:
Local.cpp updated: 1.20 -> 1.21
---
Log message:
Add support for evaluation of exp/log/log10/pow
---
Diffs of the changes: (+25 -1)
Index: llvm/lib/Transforms/Utils/Local.cpp
diff -u llvm/lib/Transforms/Utils/Local.cpp:1.20 llvm/lib/Transforms/Utils/Local.cpp:1.21
--- llvm/lib/Transforms/Utils/Local.cpp:1.20 Fri Apr 16 10:57:32 2004
+++ llvm/lib/Transforms/Utils/Local.cpp Fri Apr 16 17:35:33 2004
@@ -233,7 +233,8 @@
/// the specified function.
bool llvm::canConstantFoldCallTo(Function *F) {
const std::string &Name = F->getName();
- return Name == "sin" || Name == "cos" || Name == "tan" || Name == "sqrt";
+ return Name == "sin" || Name == "cos" || Name == "tan" || Name == "sqrt" ||
+ Name == "log" || Name == "log10" || Name == "exp" || Name == "pow";
}
/// ConstantFoldCall - Attempt to constant fold a call to the specified function
@@ -263,6 +264,29 @@
if (ConstantFP *CFP = dyn_cast<ConstantFP>(Operands[0]))
if (CFP->getValue() >= 0)
return ConstantFP::get(Ty, sqrt(CFP->getValue()));
+ } else if (Name == "exp") {
+ if (Operands.size() == 1)
+ if (ConstantFP *CFP = dyn_cast<ConstantFP>(Operands[0]))
+ return ConstantFP::get(Ty, exp(CFP->getValue()));
+ } else if (Name == "log") {
+ if (Operands.size() == 1)
+ if (ConstantFP *CFP = dyn_cast<ConstantFP>(Operands[0]))
+ if (CFP->getValue() > 0)
+ return ConstantFP::get(Ty, log(CFP->getValue()));
+ } else if (Name == "log10") {
+ if (Operands.size() == 1)
+ if (ConstantFP *CFP = dyn_cast<ConstantFP>(Operands[0]))
+ if (CFP->getValue() > 0)
+ return ConstantFP::get(Ty, log10(CFP->getValue()));
+ } else if (Name == "pow") {
+ if (Operands.size() == 2)
+ if (ConstantFP *Op1 = dyn_cast<ConstantFP>(Operands[0]))
+ if (ConstantFP *Op2 = dyn_cast<ConstantFP>(Operands[1])) {
+ errno = 0;
+ double V = pow(Op1->getValue(), Op2->getValue());
+ if (errno == 0)
+ return ConstantFP::get(Ty, V);
+ }
}
return 0;
}
More information about the llvm-commits
mailing list