[PATCH] D67300: [ConstantFolding] Fold constant calls to log2()

Evandro Menezes via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 30 13:51:29 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL373262: [ConstantFolding] Fold constant calls to log2() (authored by evandro, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D67300?vs=219161&id=222492#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67300/new/

https://reviews.llvm.org/D67300

Files:
  llvm/trunk/lib/Analysis/ConstantFolding.cpp
  llvm/trunk/test/Analysis/ConstantFolding/math-1.ll


Index: llvm/trunk/test/Analysis/ConstantFolding/math-1.ll
===================================================================
--- llvm/trunk/test/Analysis/ConstantFolding/math-1.ll
+++ llvm/trunk/test/Analysis/ConstantFolding/math-1.ll
@@ -92,14 +92,14 @@
   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 @@
   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
Index: llvm/trunk/lib/Analysis/ConstantFolding.cpp
===================================================================
--- llvm/trunk/lib/Analysis/ConstantFolding.cpp
+++ llvm/trunk/lib/Analysis/ConstantFolding.cpp
@@ -1508,6 +1508,7 @@
            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 @@
       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:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67300.222492.patch
Type: text/x-patch
Size: 2078 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190930/eb25fda9/attachment.bin>


More information about the llvm-commits mailing list