mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-18 12:29:21 +00:00
use the new ConstantFP::get method to make this work with
long double and simplify the code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@49435 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
d6d48c4e5b
commit
8bb9a4f28f
@ -1149,10 +1149,6 @@ public:
|
|||||||
|
|
||||||
/// @brief Perform the pow optimization.
|
/// @brief Perform the pow optimization.
|
||||||
virtual bool OptimizeCall(CallInst *CI, SimplifyLibCalls &SLC) {
|
virtual bool OptimizeCall(CallInst *CI, SimplifyLibCalls &SLC) {
|
||||||
const Type *Ty = CI->getType();
|
|
||||||
if (Ty != Type::FloatTy && Ty != Type::DoubleTy)
|
|
||||||
return false; // FIXME long double not yet supported
|
|
||||||
|
|
||||||
Value *Op1 = CI->getOperand(1);
|
Value *Op1 = CI->getOperand(1);
|
||||||
Value *Op2 = CI->getOperand(2);
|
Value *Op2 = CI->getOperand(2);
|
||||||
if (ConstantFP *Op1C = dyn_cast<ConstantFP>(Op1)) {
|
if (ConstantFP *Op1C = dyn_cast<ConstantFP>(Op1)) {
|
||||||
@ -1165,8 +1161,7 @@ public:
|
|||||||
|
|
||||||
if (Op2C->getValueAPF().isZero()) {
|
if (Op2C->getValueAPF().isZero()) {
|
||||||
// pow(x, 0.0) -> 1.0
|
// pow(x, 0.0) -> 1.0
|
||||||
return ReplaceCallWith(CI, ConstantFP::get(Ty,
|
return ReplaceCallWith(CI, ConstantFP::get(CI->getType(), 1.0));
|
||||||
Ty==Type::FloatTy ? APFloat(1.0f) : APFloat(1.0)));
|
|
||||||
} else if (Op2C->isExactlyValue(0.5)) {
|
} else if (Op2C->isExactlyValue(0.5)) {
|
||||||
// pow(x, 0.5) -> sqrt(x)
|
// pow(x, 0.5) -> sqrt(x)
|
||||||
Value *Sqrt = CallInst::Create(SLC.get_sqrt(), Op1, "sqrt", CI);
|
Value *Sqrt = CallInst::Create(SLC.get_sqrt(), Op1, "sqrt", CI);
|
||||||
@ -1180,11 +1175,9 @@ public:
|
|||||||
return ReplaceCallWith(CI, Sq);
|
return ReplaceCallWith(CI, Sq);
|
||||||
} else if (Op2C->isExactlyValue(-1.0)) {
|
} else if (Op2C->isExactlyValue(-1.0)) {
|
||||||
// pow(x, -1.0) -> 1.0/x
|
// pow(x, -1.0) -> 1.0/x
|
||||||
Value *div_inst =
|
Value *R = BinaryOperator::createFDiv(ConstantFP::get(CI->getType(), 1.0),
|
||||||
BinaryOperator::createFDiv(ConstantFP::get(Ty,
|
Op1, CI->getName()+".pow", CI);
|
||||||
Ty==Type::FloatTy ? APFloat(1.0f) : APFloat(1.0)),
|
return ReplaceCallWith(CI, R);
|
||||||
Op1, CI->getName()+".pow", CI);
|
|
||||||
return ReplaceCallWith(CI, div_inst);
|
|
||||||
}
|
}
|
||||||
return false; // opt failed
|
return false; // opt failed
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user