1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00

[ConstantFolding] Fold constant calls to log2()

Somehow, folding calls to `log2()` with a constant was missing.

Differential revision: https://reviews.llvm.org/D67300

llvm-svn: 373262
This commit is contained in:
Evandro Menezes 2019-09-30 20:53:23 +00:00
parent 15a5c7b05f
commit 4b361fd46d
2 changed files with 13 additions and 6 deletions

View File

@ -1508,6 +1508,7 @@ bool llvm::canConstantFoldCallTo(const CallBase *Call, const Function *F) {
Name == "fmod" || Name == "fmodf";
case 'l':
return Name == "log" || Name == "logf" ||
Name == "log2" || Name == "log2f" ||
Name == "log10" || Name == "log10f";
case 'n':
return Name == "nearbyint" || Name == "nearbyintf";
@ -1890,6 +1891,14 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
if (V > 0.0 && TLI->has(Func))
return ConstantFoldFP(log, V, Ty);
break;
case LibFunc_log2:
case LibFunc_log2f:
case LibFunc_log2_finite:
case LibFunc_log2f_finite:
if (V > 0.0 && TLI->has(Func))
// TODO: What about hosts that lack a C99 library?
return ConstantFoldFP(Log2, V, Ty);
break;
case LibFunc_log10:
case LibFunc_log10f:
case LibFunc_log10_finite:

View File

@ -92,14 +92,14 @@ define double @i_exp2() {
ret double %res
}
; FIXME
; FIXME: exp10() is not widely supported.
declare float @exp10f(float)
define float @f_exp10f() {
; CHECK-LABEL: @f_exp10f(
; CHECK-NEXT: [[RES:%.*]] = tail call fast float @exp10f(float 1.000000e+00)
; CHECK-NEXT: [[RES:%.*]] = tail call float @exp10f(float 1.000000e+00)
; CHECK-NEXT: ret float [[RES]]
;
%res = tail call fast float @exp10f(float 1.0)
%res = tail call float @exp10f(float 1.0)
ret float %res
}
@ -121,12 +121,10 @@ define double @i_log() {
ret double %res
}
; FIXME
declare float @log2f(float)
define float @f_log2f() {
; CHECK-LABEL: @f_log2f(
; CHECK-NEXT: [[RES:%.*]] = tail call fast float @log2f(float 1.000000e+00)
; CHECK-NEXT: ret float [[RES]]
; CHECK-NEXT: ret float 0.000000e+00
;
%res = tail call fast float @log2f(float 1.0)
ret float %res