[llvm] r257503 - [LibCallSimplifier] use instruction-level fast-math-flags to transform pow(x, 0.5) calls
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 12 11:06:36 PST 2016
Author: spatel
Date: Tue Jan 12 13:06:35 2016
New Revision: 257503
URL: http://llvm.org/viewvc/llvm-project?rev=257503&view=rev
Log:
[LibCallSimplifier] use instruction-level fast-math-flags to transform pow(x, 0.5) calls
Also, propagate the FMF to the newly created sqrt() call.
Modified:
llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp
llvm/trunk/test/Transforms/InstCombine/pow-sqrt.ll
Modified: llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp?rev=257503&r1=257502&r2=257503&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp Tue Jan 12 13:06:35 2016
@@ -1164,9 +1164,12 @@ Value *LibCallSimplifier::optimizePow(Ca
LibFunc::fabsl)) {
// In -ffast-math, pow(x, 0.5) -> sqrt(x).
- if (UnsafeFPMath)
+ if (CI->hasUnsafeAlgebra()) {
+ IRBuilder<>::FastMathFlagGuard Guard(B);
+ B.setFastMathFlags(CI->getFastMathFlags());
return EmitUnaryFloatFnCall(Op1, TLI->getName(LibFunc::sqrt), B,
Callee->getAttributes());
+ }
// Expand pow(x, 0.5) to (x == -infinity ? +infinity : fabs(sqrt(x))).
// This is faster than calling pow, and still handles negative zero
Modified: llvm/trunk/test/Transforms/InstCombine/pow-sqrt.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/pow-sqrt.ll?rev=257503&r1=257502&r2=257503&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/pow-sqrt.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/pow-sqrt.ll Tue Jan 12 13:06:35 2016
@@ -1,15 +1,13 @@
; RUN: opt < %s -instcombine -S | FileCheck %s
-define double @mypow(double %x) #0 {
-entry:
- %pow = call double @llvm.pow.f64(double %x, double 5.000000e-01)
+define double @pow_half(double %x) {
+ %pow = call fast double @llvm.pow.f64(double %x, double 5.000000e-01)
ret double %pow
}
-; CHECK-LABEL: define double @mypow(
-; CHECK: %sqrt = call double @sqrt(double %x) #1
-; CHECK: ret double %sqrt
-; CHECK: }
+; CHECK-LABEL: define double @pow_half(
+; CHECK-NEXT: %sqrt = call fast double @sqrt(double %x)
+; CHECK-NEXT: ret double %sqrt
declare double @llvm.pow.f64(double, double)
-attributes #0 = { "unsafe-fp-math"="true" }
+
More information about the llvm-commits
mailing list