[llvm] r320312 - [SimplifyLibCalls] propagate FMF when folding pow(x, -1.0) call
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 10 09:25:54 PST 2017
Author: spatel
Date: Sun Dec 10 09:25:54 2017
New Revision: 320312
URL: http://llvm.org/viewvc/llvm-project?rev=320312&view=rev
Log:
[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
Modified:
llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp
llvm/trunk/test/Transforms/InstCombine/pow-1.ll
Modified: llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp?rev=320312&r1=320311&r2=320312&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp Sun Dec 10 09:25:54 2017
@@ -1204,16 +1204,17 @@ Value *LibCallSimplifier::optimizePow(Ca
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(Ca
!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(Ca
// 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.
Modified: llvm/trunk/test/Transforms/InstCombine/pow-1.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/pow-1.ll?rev=320312&r1=320311&r2=320312&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/pow-1.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/pow-1.ll Sun Dec 10 09:25:54 2017
@@ -166,7 +166,7 @@ define float @pow_neg1_strict(float %x)
define double @pow_neg1_double_fast(double %x) {
; CHECK-LABEL: @pow_neg1_double_fast(
-; CHECK-NEXT: [[POWRECIP:%.*]] = fdiv double 1.000000e+00, %x
+; CHECK-NEXT: [[POWRECIP:%.*]] = fdiv fast double 1.000000e+00, %x
; CHECK-NEXT: ret double [[POWRECIP]]
;
%r = call fast double @pow(double %x, double -1.0)
More information about the llvm-commits
mailing list