[llvm] r371236 - [ConstantFolding] Refactor functions not available before C99 (NFC)

Evandro Menezes via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 6 11:24:22 PDT 2019


Author: evandro
Date: Fri Sep  6 11:24:21 2019
New Revision: 371236

URL: http://llvm.org/viewvc/llvm-project?rev=371236&view=rev
Log:
[ConstantFolding] Refactor functions not available before C99 (NFC)

Note the cases when calling a function at compile time may fail if the host
does not support the C99 run time library.

Modified:
    llvm/trunk/lib/Analysis/ConstantFolding.cpp

Modified: llvm/trunk/lib/Analysis/ConstantFolding.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ConstantFolding.cpp?rev=371236&r1=371235&r2=371236&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ConstantFolding.cpp (original)
+++ llvm/trunk/lib/Analysis/ConstantFolding.cpp Fri Sep  6 11:24:21 2019
@@ -1773,13 +1773,16 @@ static Constant *ConstantFoldScalarCall1
       case Intrinsic::log:
         return ConstantFoldFP(log, V, Ty);
       case Intrinsic::log2:
+        // TODO: What about hosts that lack a C99 library?
         return ConstantFoldFP(Log2, V, Ty);
       case Intrinsic::log10:
+        // TODO: What about hosts that lack a C99 library?
         return ConstantFoldFP(log10, V, Ty);
       case Intrinsic::exp:
         return ConstantFoldFP(exp, V, Ty);
       case Intrinsic::exp2:
-        return ConstantFoldFP(exp2, V, Ty);
+        // Fold exp2(x) as pow(2, x), in case the host lacks a C99 library.
+        return ConstantFoldBinaryFP(pow, 2.0, V, Ty);
       case Intrinsic::sin:
         return ConstantFoldFP(sin, V, Ty);
       case Intrinsic::cos:
@@ -1870,6 +1873,7 @@ static Constant *ConstantFoldScalarCall1
     case LibFunc_log10_finite:
     case LibFunc_log10f_finite:
       if (V > 0.0 && TLI->has(Func))
+        // TODO: What about hosts that lack a C99 library?
         return ConstantFoldFP(log10, V, Ty);
       break;
     case LibFunc_round:
@@ -2037,6 +2041,7 @@ static Constant *ConstantFoldScalarCall2
       case LibFunc_fmod:
       case LibFunc_fmodf:
         if (TLI->has(Func))
+          // TODO: What about hosts that lack a C99 library?
           return ConstantFoldBinaryFP(fmod, Op1V, Op2V, Ty);
         break;
       case LibFunc_atan2:




More information about the llvm-commits mailing list