summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2017-12-10 17:25:54 +0000
committerSanjay Patel <spatel@rotateright.com>2017-12-10 17:25:54 +0000
commitb23e148114d81898d7357ca5d6d18966497a37c1 (patch)
tree30e574ad3743135edf30c65f498b14861264dbc3 /llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
parentac9cbd6c56e7bc6bcc6af3bf32c61e9dac5a48d2 (diff)
downloadbcm5719-llvm-b23e148114d81898d7357ca5d6d18966497a37c1.tar.gz
bcm5719-llvm-b23e148114d81898d7357ca5d6d18966497a37c1.zip
[SimplifyLibCalls] propagate FMF when folding pow(x, -1.0) call
Follow-up for a bug that's similar to: https://bugs.llvm.org/show_bug.cgi?id=35601 llvm-svn: 320312
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp25
1 files changed, 11 insertions, 14 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
index 273a5e79a7d..60f6c600b5a 100644
--- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -1204,16 +1204,17 @@ Value *LibCallSimplifier::optimizePow(CallInst *CI, IRBuilder<> &B) {
return Sel;
}
- if (Op2C->isExactlyValue(1.0)) // pow(x, 1.0) -> x
+ // Propagate fast-math-flags from the call to any created instructions.
+ IRBuilder<>::FastMathFlagGuard Guard(B);
+ B.setFastMathFlags(CI->getFastMathFlags());
+ // pow(x, 1.0) --> x
+ if (Op2C->isExactlyValue(1.0))
return Op1;
- if (Op2C->isExactlyValue(2.0)) {
- // pow(x, 2.0) --> x * x
- IRBuilder<>::FastMathFlagGuard Guard(B);
- B.setFastMathFlags(CI->getFastMathFlags());
+ // pow(x, 2.0) --> x * x
+ if (Op2C->isExactlyValue(2.0))
return B.CreateFMul(Op1, Op1, "pow2");
- }
- // FIXME: This should propagate the FMF of the call to the fdiv.
- if (Op2C->isExactlyValue(-1.0)) // pow(x, -1.0) -> 1.0/x
+ // pow(x, -1.0) --> 1.0 / x
+ if (Op2C->isExactlyValue(-1.0))
return B.CreateFDiv(ConstantFP::get(CI->getType(), 1.0), Op1, "powrecip");
// In -ffast-math, generate repeated fmul instead of generating pow(x, n).
@@ -1225,10 +1226,6 @@ Value *LibCallSimplifier::optimizePow(CallInst *CI, IRBuilder<> &B) {
!V.isInteger())
return nullptr;
- // Propagate fast math flags.
- IRBuilder<>::FastMathFlagGuard Guard(B);
- B.setFastMathFlags(CI->getFastMathFlags());
-
// We will memoize intermediate products of the Addition Chain.
Value *InnerChain[33] = {nullptr};
InnerChain[1] = Op1;
@@ -1236,8 +1233,8 @@ Value *LibCallSimplifier::optimizePow(CallInst *CI, IRBuilder<> &B) {
// We cannot readily convert a non-double type (like float) to a double.
// So we first convert V to something which could be converted to double.
- bool ignored;
- V.convert(APFloat::IEEEdouble(), APFloat::rmTowardZero, &ignored);
+ bool Ignored;
+ V.convert(APFloat::IEEEdouble(), APFloat::rmTowardZero, &Ignored);
Value *FMul = getPow(InnerChain, V.convertToDouble(), B);
// For negative exponents simply compute the reciprocal.
OpenPOWER on IntegriCloud