summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp
diff options
context:
space:
mode:
authorDale Johannesen <dalej@apple.com>2007-09-06 18:13:44 +0000
committerDale Johannesen <dalej@apple.com>2007-09-06 18:13:44 +0000
commitbed9dc423ceadd08500869cf03e4c0819145d48b (patch)
tree1f39c25a045eca2e6d11262ae1be517e661d4010 /llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp
parenta07765b8f4d9da2836d8f89b26d7f476715dffb4 (diff)
downloadbcm5719-llvm-bed9dc423ceadd08500869cf03e4c0819145d48b.tar.gz
bcm5719-llvm-bed9dc423ceadd08500869cf03e4c0819145d48b.zip
Next round of APFloat changes.
Use APFloat in UpgradeParser and AsmParser. Change all references to ConstantFP to use the APFloat interface rather than double. Remove the ConstantFP double interfaces. Use APFloat functions for constant folding arithmetic and comparisons. (There are still way too many places APFloat is just a wrapper around host float/double, but we're getting there.) llvm-svn: 41747
Diffstat (limited to 'llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp')
-rw-r--r--llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp27
1 files changed, 16 insertions, 11 deletions
diff --git a/llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp b/llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp
index 5925f582ad4..01d3c9ff2ec 100644
--- a/llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp
@@ -1118,27 +1118,32 @@ public:
Value* base = ci->getOperand(1);
Value* expn = ci->getOperand(2);
if (ConstantFP *Op1 = dyn_cast<ConstantFP>(base)) {
- double Op1V = Op1->getValue();
- if (Op1V == 1.0) // pow(1.0,x) -> 1.0
- return ReplaceCallWith(ci, ConstantFP::get(Ty, 1.0));
+ if (Ty!=Type::FloatTy && Ty!=Type::DoubleTy)
+ return false; // FIXME long double not yet supported
+ if (Op1->isExactlyValue(1.0)) // pow(1.0,x) -> 1.0
+ return ReplaceCallWith(ci, ConstantFP::get(Ty,
+ Ty==Type::FloatTy ? APFloat(1.0f) : APFloat(1.0)));
} else if (ConstantFP* Op2 = dyn_cast<ConstantFP>(expn)) {
- double Op2V = Op2->getValue();
- if (Op2V == 0.0) {
+ if (Ty!=Type::FloatTy && Ty!=Type::DoubleTy)
+ return false; // FIXME long double not yet supported
+ if (Op2->getValueAPF().isZero()) {
// pow(x,0.0) -> 1.0
- return ReplaceCallWith(ci, ConstantFP::get(Ty,1.0));
- } else if (Op2V == 0.5) {
+ return ReplaceCallWith(ci, ConstantFP::get(Ty,
+ Ty==Type::FloatTy ? APFloat(1.0f) : APFloat(1.0)));
+ } else if (Op2->isExactlyValue(0.5)) {
// pow(x,0.5) -> sqrt(x)
CallInst* sqrt_inst = new CallInst(SLC.get_sqrt(), base,
ci->getName()+".pow",ci);
return ReplaceCallWith(ci, sqrt_inst);
- } else if (Op2V == 1.0) {
+ } else if (Op2->isExactlyValue(1.0)) {
// pow(x,1.0) -> x
return ReplaceCallWith(ci, base);
- } else if (Op2V == -1.0) {
+ } else if (Op2->isExactlyValue(-1.0)) {
// pow(x,-1.0) -> 1.0/x
Value *div_inst =
- BinaryOperator::createFDiv(ConstantFP::get(Ty, 1.0), base,
- ci->getName()+".pow", ci);
+ BinaryOperator::createFDiv(ConstantFP::get(Ty,
+ Ty==Type::FloatTy ? APFloat(1.0f) : APFloat(1.0)),
+ base, ci->getName()+".pow", ci);
return ReplaceCallWith(ci, div_inst);
}
}
OpenPOWER on IntegriCloud