[llvm] r256964 - [LibCallSimplifier] use instruction-level fast-math-flags for tan/atan transform
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 6 11:23:35 PST 2016
Author: spatel
Date: Wed Jan 6 13:23:35 2016
New Revision: 256964
URL: http://llvm.org/viewvc/llvm-project?rev=256964&view=rev
Log:
[LibCallSimplifier] use instruction-level fast-math-flags for tan/atan transform
Modified:
llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp
llvm/trunk/test/Transforms/InstCombine/tan.ll
Modified: llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp?rev=256964&r1=256963&r2=256964&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp Wed Jan 6 13:23:35 2016
@@ -1457,6 +1457,7 @@ Value *LibCallSimplifier::optimizeSqrt(C
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(Ca
!FT->getParamType(0)->isFloatingPointTy())
return Ret;
- if (!canUseUnsafeFPMath(CI->getParent()->getParent()))
- return Ret;
Value *Op1 = CI->getArgOperand(0);
auto *OpC = dyn_cast<CallInst>(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
Modified: llvm/trunk/test/Transforms/InstCombine/tan.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/tan.ll?rev=256964&r1=256963&r2=256964&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/tan.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/tan.ll Wed Jan 6 13:23:35 2016
@@ -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)
+
More information about the llvm-commits
mailing list