aboutsummaryrefslogtreecommitdiffstats
path: root/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
commitb9de9f07d611823ea3371b65f87035f482ace2ad (patch)
treeb314e17b0444f33dc3be37eaeaeaa8ea7dd1d17e /lib/Transforms/IPO/SimplifyLibCalls.cpp
parent6d2c506cce46d4edcc314ca363b5e4ec4584cc38 (diff)
downloadexternal_llvm-b9de9f07d611823ea3371b65f87035f482ace2ad.zip
external_llvm-b9de9f07d611823ea3371b65f87035f482ace2ad.tar.gz
external_llvm-b9de9f07d611823ea3371b65f87035f482ace2ad.tar.bz2
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.) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41747 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/IPO/SimplifyLibCalls.cpp')
-rw-r--r--lib/Transforms/IPO/SimplifyLibCalls.cpp27
1 files changed, 16 insertions, 11 deletions
diff --git a/lib/Transforms/IPO/SimplifyLibCalls.cpp b/lib/Transforms/IPO/SimplifyLibCalls.cpp
index 5925f58..01d3c9f 100644
--- a/lib/Transforms/IPO/SimplifyLibCalls.cpp
+++ b/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);
}
}