From 805fa97a0f5ff61624855da37d4881708fb8f0fb Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 22 May 2011 22:22:35 +0000 Subject: [PATCH] implement PR9315, constant folding exp2 in terms of pow (since hosts without C99 runtimes don't have exp2). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131872 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/ConstantFolding.cpp | 8 +++++++- test/Transforms/ConstProp/calls.ll | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/Analysis/ConstantFolding.cpp b/lib/Analysis/ConstantFolding.cpp index 5de2b04e80..08a6065b31 100644 --- a/lib/Analysis/ConstantFolding.cpp +++ b/lib/Analysis/ConstantFolding.cpp @@ -1085,7 +1085,7 @@ llvm::canConstantFoldCallTo(const Function *F) { case 'c': return Name == "cos" || Name == "ceil" || Name == "cosf" || Name == "cosh"; case 'e': - return Name == "exp"; + return Name == "exp" || Name == "exp2"; case 'f': return Name == "fabs" || Name == "fmod" || Name == "floor"; case 'l': @@ -1221,6 +1221,12 @@ llvm::ConstantFoldCall(Function *F, case 'e': if (Name == "exp") return ConstantFoldFP(exp, V, Ty); + + if (Name == "exp2") { + // Constant fold exp2(x) as pow(2,x) in case the host doesn't have a + // C99 library. + return ConstantFoldBinaryFP(pow, 2.0, V, Ty); + } break; case 'f': if (Name == "fabs") diff --git a/test/Transforms/ConstProp/calls.ll b/test/Transforms/ConstProp/calls.ll index 82d73245ad..3b6010a0dc 100644 --- a/test/Transforms/ConstProp/calls.ll +++ b/test/Transforms/ConstProp/calls.ll @@ -7,6 +7,7 @@ declare double @sin(double) declare double @tan(double) declare double @sqrt(double) +declare double @exp2(double) define double @T() { ; CHECK: @T @@ -19,7 +20,11 @@ define double @T() { %b = fadd double %a, %C %D = call double @sqrt(double 4.000000e+00) %c = fadd double %b, %D - ret double %c + + ; PR9315 + %E = call double @exp2(double 4.0) + %d = fadd double %c, %E + ret double %d } define i1 @test_sse_cvt() nounwind readnone { -- 2.11.4.GIT