From: Evandro Menezes Date: Mon, 30 Sep 2019 20:53:23 +0000 (+0000) Subject: [ConstantFolding] Fold constant calls to log2() X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f47f0208a138c0a3576b2f3afa0a9841e61840ae;p=llvm [ConstantFolding] Fold constant calls to log2() Somehow, folding calls to `log2()` with a constant was missing. Differential revision: https://reviews.llvm.org/D67300 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@373262 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/ConstantFolding.cpp b/lib/Analysis/ConstantFolding.cpp index f8ea8cfc354..8dbcf7034fd 100644 --- a/lib/Analysis/ConstantFolding.cpp +++ b/lib/Analysis/ConstantFolding.cpp @@ -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: diff --git a/test/Analysis/ConstantFolding/math-1.ll b/test/Analysis/ConstantFolding/math-1.ll index 173320789ae..59509501710 100644 --- a/test/Analysis/ConstantFolding/math-1.ll +++ b/test/Analysis/ConstantFolding/math-1.ll @@ -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