mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-10-19 02:52:53 +02:00
[SimplifyLibCalls] Transform log(exp2(y)) to y*log(2) under fast-math.
llvm-svn: 254317
This commit is contained in:
parent
8619fd0740
commit
0f427b7147
@ -1322,6 +1322,15 @@ Value *LibCallSimplifier::optimizeLog(CallInst *CI, IRBuilder<> &B) {
|
|||||||
return B.CreateFMul(OpC->getArgOperand(1),
|
return B.CreateFMul(OpC->getArgOperand(1),
|
||||||
EmitUnaryFloatFnCall(OpC->getOperand(0), Callee->getName(), B,
|
EmitUnaryFloatFnCall(OpC->getOperand(0), Callee->getName(), B,
|
||||||
Callee->getAttributes()), "mul");
|
Callee->getAttributes()), "mul");
|
||||||
|
|
||||||
|
// log(exp2(y)) -> y*log(2)
|
||||||
|
if (F && Name == "log" && TLI->getLibFunc(F->getName(), Func) &&
|
||||||
|
TLI->has(Func) && Func == LibFunc::exp2)
|
||||||
|
return B.CreateFMul(
|
||||||
|
OpC->getArgOperand(0),
|
||||||
|
EmitUnaryFloatFnCall(ConstantFP::get(CI->getType(), 2.0),
|
||||||
|
Callee->getName(), B, Callee->getAttributes()),
|
||||||
|
"logmul");
|
||||||
return Ret;
|
return Ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2301,7 +2310,6 @@ void LibCallSimplifier::replaceAllUsesWith(Instruction *I, Value *With) {
|
|||||||
// log, logf, logl:
|
// log, logf, logl:
|
||||||
// * log(exp(x)) -> x
|
// * log(exp(x)) -> x
|
||||||
// * log(exp(y)) -> y*log(e)
|
// * log(exp(y)) -> y*log(e)
|
||||||
// * log(exp2(y)) -> y*log(2)
|
|
||||||
// * log(exp10(y)) -> y*log(10)
|
// * log(exp10(y)) -> y*log(10)
|
||||||
// * log(sqrt(x)) -> 0.5*log(x)
|
// * log(sqrt(x)) -> 0.5*log(x)
|
||||||
//
|
//
|
||||||
|
@ -13,5 +13,18 @@ entry:
|
|||||||
; CHECK: ret double %call
|
; CHECK: ret double %call
|
||||||
; CHECK: }
|
; CHECK: }
|
||||||
|
|
||||||
|
define double @test3(double %x) #0 {
|
||||||
|
%call2 = call double @exp2(double %x) #0
|
||||||
|
%call3 = call double @log(double %call2) #0
|
||||||
|
ret double %call3
|
||||||
|
}
|
||||||
|
|
||||||
|
; CHECK-LABEL: @test3
|
||||||
|
; CHECK: %call2 = call double @exp2(double %x)
|
||||||
|
; CHECK: %call3 = call double @log(double %call2)
|
||||||
|
; CHECK: ret double %call3
|
||||||
|
; CHECK: }
|
||||||
|
|
||||||
declare double @log(double) #0
|
declare double @log(double) #0
|
||||||
|
declare double @exp2(double)
|
||||||
declare double @llvm.pow.f64(double, double)
|
declare double @llvm.pow.f64(double, double)
|
||||||
|
@ -22,7 +22,20 @@ define double @test2(double ()* %fptr, double %p1) #0 {
|
|||||||
; CHECK-LABEL: @test2
|
; CHECK-LABEL: @test2
|
||||||
; CHECK: log
|
; CHECK: log
|
||||||
|
|
||||||
|
define double @test3(double %x) #0 {
|
||||||
|
%call2 = call double @exp2(double %x) #0
|
||||||
|
%call3 = call double @log(double %call2) #0
|
||||||
|
ret double %call3
|
||||||
|
}
|
||||||
|
|
||||||
|
; CHECK-LABEL: @test3
|
||||||
|
; CHECK: %call2 = call double @exp2(double %x) #0
|
||||||
|
; CHECK: %logmul = fmul fast double %x, 0x3FE62E42FEFA39EF
|
||||||
|
; CHECK: ret double %logmul
|
||||||
|
; CHECK: }
|
||||||
|
|
||||||
declare double @log(double) #0
|
declare double @log(double) #0
|
||||||
|
declare double @exp2(double) #0
|
||||||
declare double @llvm.pow.f64(double, double)
|
declare double @llvm.pow.f64(double, double)
|
||||||
|
|
||||||
attributes #0 = { "unsafe-fp-math"="true" }
|
attributes #0 = { "unsafe-fp-math"="true" }
|
||||||
|
Loading…
Reference in New Issue
Block a user