From: Sanjay Patel Date: Tue, 12 Jan 2016 19:06:35 +0000 (+0000) Subject: [LibCallSimplifier] use instruction-level fast-math-flags to transform pow(x, 0.5... X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=44d6fd556f9e7753d5413bb0ec7b07e98179f4f8;p=oota-llvm.git [LibCallSimplifier] use instruction-level fast-math-flags to transform pow(x, 0.5) calls Also, propagate the FMF to the newly created sqrt() call. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@257503 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Utils/SimplifyLibCalls.cpp b/lib/Transforms/Utils/SimplifyLibCalls.cpp index 2551abef75b..dc074406014 100644 --- a/lib/Transforms/Utils/SimplifyLibCalls.cpp +++ b/lib/Transforms/Utils/SimplifyLibCalls.cpp @@ -1164,9 +1164,12 @@ Value *LibCallSimplifier::optimizePow(CallInst *CI, IRBuilder<> &B) { 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 diff --git a/test/Transforms/InstCombine/pow-sqrt.ll b/test/Transforms/InstCombine/pow-sqrt.ll index 8fc74e4a002..1e6166c5f11 100644 --- a/test/Transforms/InstCombine/pow-sqrt.ll +++ b/test/Transforms/InstCombine/pow-sqrt.ll @@ -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" } +