From: Sanjay Patel Date: Wed, 6 Jan 2016 19:23:35 +0000 (+0000) Subject: [LibCallSimplifier] use instruction-level fast-math-flags for tan/atan transform X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=78a42b0707069a5927c635bc52cb1c477307110c;p=oota-llvm.git [LibCallSimplifier] use instruction-level fast-math-flags for tan/atan transform git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256964 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Utils/SimplifyLibCalls.cpp b/lib/Transforms/Utils/SimplifyLibCalls.cpp index dc5fee523d4..563b65ce5d3 100644 --- a/lib/Transforms/Utils/SimplifyLibCalls.cpp +++ b/lib/Transforms/Utils/SimplifyLibCalls.cpp @@ -1457,6 +1457,7 @@ Value *LibCallSimplifier::optimizeSqrt(CallInst *CI, IRBuilder<> &B) { return Ret; } +// TODO: Generalize to handle any trig function and its inverse. Value *LibCallSimplifier::optimizeTan(CallInst *CI, IRBuilder<> &B) { Function *Callee = CI->getCalledFunction(); Value *Ret = nullptr; @@ -1471,13 +1472,15 @@ Value *LibCallSimplifier::optimizeTan(CallInst *CI, IRBuilder<> &B) { !FT->getParamType(0)->isFloatingPointTy()) return Ret; - if (!canUseUnsafeFPMath(CI->getParent()->getParent())) - return Ret; Value *Op1 = CI->getArgOperand(0); auto *OpC = dyn_cast(Op1); if (!OpC) return Ret; + // Both calls must allow unsafe optimizations in order to remove them. + if (!CI->hasUnsafeAlgebra() || !OpC->hasUnsafeAlgebra()) + return Ret; + // tan(atan(x)) -> x // tanf(atanf(x)) -> x // tanl(atanl(x)) -> x diff --git a/test/Transforms/InstCombine/tan.ll b/test/Transforms/InstCombine/tan.ll index 15a832f253a..6ea116839fe 100644 --- a/test/Transforms/InstCombine/tan.ll +++ b/test/Transforms/InstCombine/tan.ll @@ -1,24 +1,23 @@ ; RUN: opt < %s -instcombine -S | FileCheck %s -define float @mytan(float %x) #0 { -entry: - %call = call float @atanf(float %x) - %call1 = call float @tanf(float %call) +define float @mytan(float %x) { + %call = call fast float @atanf(float %x) + %call1 = call fast float @tanf(float %call) ret float %call1 } ; CHECK-LABEL: define float @mytan( ; CHECK: ret float %x -define float @test2(float ()* %fptr) #0 { - %call1 = call float %fptr() - %tan = call float @tanf(float %call1) +define float @test2(float ()* %fptr) { + %call1 = call fast float %fptr() + %tan = call fast float @tanf(float %call1) ret float %tan } ; CHECK-LABEL: @test2 ; CHECK: tanf -declare float @tanf(float) #0 -declare float @atanf(float) #0 -attributes #0 = { "unsafe-fp-math"="true" } +declare float @tanf(float) +declare float @atanf(float) +