mirror of
https://github.com/RPCSX/llvm.git
synced 2024-11-24 12:19:53 +00:00
[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
This commit is contained in:
parent
4377f132ae
commit
78a42b0707
@ -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<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
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user