diff options
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp | 27 | ||||
| -rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 2 |
2 files changed, 17 insertions, 12 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); } } diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index 4902fb710ad..26df55531a8 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -2348,7 +2348,7 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) { // "In IEEE floating point, x*1 is not equivalent to x for nans. However, // ANSI says we can drop signals, so we can do this anyway." (from GCC) - if (Op1F->getValue() == 1.0) + if (Op1F->isExactlyValue(1.0)) return ReplaceInstUsesWith(I, Op0); // Eliminate 'mul double %X, 1.0' } |

