diff options
author | Sanjay Patel <spatel@rotateright.com> | 2017-11-19 16:42:27 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2017-11-19 16:42:27 +0000 |
commit | 9771a96f6e725e108f263cc27f2c285d5cfffc02 (patch) | |
tree | 085063e0d1517de392b722147f780b4235d97e5b /llvm/lib | |
parent | fbd3e66b9ac094e57ad2ead5a3113260d5975504 (diff) | |
download | bcm5719-llvm-9771a96f6e725e108f263cc27f2c285d5cfffc02.tar.gz bcm5719-llvm-9771a96f6e725e108f263cc27f2c285d5cfffc02.zip |
[LibCallSimplifier] allow splat vectors for pow(x, 0.5) -> sqrt() transforms
llvm-svn: 318629
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp index 6e3adb14c53..c392492e331 100644 --- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp @@ -1081,11 +1081,10 @@ Value *LibCallSimplifier::replacePowWithSqrt(CallInst *Pow, IRBuilder<> &B) { if (!Pow->isFast()) return nullptr; - // TODO: This should use m_APFloat to allow vector splats. - ConstantFP *Op2C = dyn_cast<ConstantFP>(Pow->getArgOperand(1)); - if (!Op2C) + const APFloat *Arg1C; + if (!match(Pow->getArgOperand(1), m_APFloat(Arg1C))) return nullptr; - if (!Op2C->isExactlyValue(0.5) && !Op2C->isExactlyValue(-0.5)) + if (!Arg1C->isExactlyValue(0.5) && !Arg1C->isExactlyValue(-0.5)) return nullptr; // Fast-math flags from the pow() are propagated to all replacement ops. @@ -1114,7 +1113,7 @@ Value *LibCallSimplifier::replacePowWithSqrt(CallInst *Pow, IRBuilder<> &B) { } // If this is pow(x, -0.5), get the reciprocal. - if (Op2C->isExactlyValue(-0.5)) + if (Arg1C->isExactlyValue(-0.5)) Sqrt = B.CreateFDiv(ConstantFP::get(Ty, 1.0), Sqrt); return Sqrt; @@ -1170,6 +1169,9 @@ Value *LibCallSimplifier::optimizePow(CallInst *CI, IRBuilder<> &B) { } } + if (Value *Sqrt = replacePowWithSqrt(CI, B)) + return Sqrt; + ConstantFP *Op2C = dyn_cast<ConstantFP>(Op2); if (!Op2C) return Ret; @@ -1177,9 +1179,6 @@ Value *LibCallSimplifier::optimizePow(CallInst *CI, IRBuilder<> &B) { if (Op2C->getValueAPF().isZero()) // pow(x, 0.0) -> 1.0 return ConstantFP::get(CI->getType(), 1.0); - if (Value *Sqrt = replacePowWithSqrt(CI, B)) - return Sqrt; - // FIXME: Correct the transforms and pull this into replacePowWithSqrt(). if (Op2C->isExactlyValue(0.5) && hasUnaryFloatFn(TLI, Op2->getType(), LibFunc_sqrt, LibFunc_sqrtf, |