[llvm] r290542 - [InstCombiner] Simplify lib calls to `round{,f}`

Bryant Wong via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 26 06:29:30 PST 2016


Author: bryant
Date: Mon Dec 26 08:29:29 2016
New Revision: 290542

URL: http://llvm.org/viewvc/llvm-project?rev=290542&view=rev
Log:
[InstCombiner] Simplify lib calls to `round{,f}`

Differential Revision: https://reviews.llvm.org/D28110

Modified:
    llvm/trunk/lib/Analysis/ConstantFolding.cpp
    llvm/trunk/test/Transforms/ConstProp/calls.ll

Modified: llvm/trunk/lib/Analysis/ConstantFolding.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ConstantFolding.cpp?rev=290542&r1=290541&r2=290542&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ConstantFolding.cpp (original)
+++ llvm/trunk/lib/Analysis/ConstantFolding.cpp Mon Dec 26 08:29:29 2016
@@ -1431,6 +1431,8 @@ bool llvm::canConstantFoldCallTo(const F
            Name == "log10f";
   case 'p':
     return Name == "pow" || Name == "powf";
+  case 'r':
+    return Name == "round" || Name == "roundf";
   case 's':
     return Name == "sin" || Name == "sinh" || Name == "sqrt" ||
            Name == "sinf" || Name == "sinhf" || Name == "sqrtf";
@@ -1695,6 +1697,10 @@ Constant *ConstantFoldScalarCall(StringR
           }
         }
         break;
+      case 'r':
+        if ((Name == "round" && TLI->has(LibFunc::round)) ||
+            (Name == "roundf" && TLI->has(LibFunc::roundf)))
+          return ConstantFoldFP(round, V, Ty);
       case 's':
         if ((Name == "sin" && TLI->has(LibFunc::sin)) ||
             (Name == "sinf" && TLI->has(LibFunc::sinf)))

Modified: llvm/trunk/test/Transforms/ConstProp/calls.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/ConstProp/calls.ll?rev=290542&r1=290541&r2=290542&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/ConstProp/calls.ll (original)
+++ llvm/trunk/test/Transforms/ConstProp/calls.ll Mon Dec 26 08:29:29 2016
@@ -16,6 +16,7 @@ declare double @fmod(double, double) rea
 declare double @log(double) readnone nounwind
 declare double @log10(double) readnone nounwind
 declare double @pow(double, double) readnone nounwind
+declare double @round(double) readnone nounwind
 declare double @sin(double) readnone nounwind
 declare double @sinh(double) readnone nounwind
 declare double @sqrt(double) readnone nounwind
@@ -37,6 +38,7 @@ declare float @fmodf(float, float) readn
 declare float @logf(float) readnone nounwind
 declare float @log10f(float) readnone nounwind
 declare float @powf(float, float) readnone nounwind
+declare float @roundf(float) readnone nounwind
 declare float @sinf(float) readnone nounwind
 declare float @sinhf(float) readnone nounwind
 declare float @sqrtf(float) readnone nounwind
@@ -102,6 +104,9 @@ define double @T() {
   %14 = call double @pow(double 3.000000e+00, double 4.000000e+00)
   store double %14, double* %slot
 ; FNOBUILTIN: call
+  %round_val = call double @round(double 3.000000e+00)
+  store double %round_val, double* %slot
+; FNOBUILTIN: call
   %15 = call double @sinh(double 3.000000e+00)
   store double %15, double* %slot
 ; FNOBUILTIN: call
@@ -153,6 +158,9 @@ define double @T() {
   %31 = call float @powf(float 3.000000e+00, float 4.000000e+00)
   store float %31, float* %slotf
 ; FNOBUILTIN: call
+  %roundf_val = call float @roundf(float 3.000000e+00)
+  store float %roundf_val, float* %slotf
+; FNOBUILTIN: call
   %32 = call float @sinf(float 3.000000e+00)
   store float %32, float* %slotf
 ; FNOBUILTIN: call




More information about the llvm-commits mailing list