diff options
| -rw-r--r-- | llvm/lib/Analysis/ConstantFolding.cpp | 9 | ||||
| -rw-r--r-- | llvm/test/Analysis/ConstantFolding/math-1.ll | 10 |
2 files changed, 13 insertions, 6 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index f8ea8cfc354..8dbcf7034fd 100644 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/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/llvm/test/Analysis/ConstantFolding/math-1.ll b/llvm/test/Analysis/ConstantFolding/math-1.ll index 173320789ae..59509501710 100644 --- a/llvm/test/Analysis/ConstantFolding/math-1.ll +++ b/llvm/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 |

