[PATCH] D69777: [ConstantFolding] Fold calls to FP remainder function

Ehud Katz via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 3 13:06:43 PST 2019


ekatz created this revision.
ekatz added reviewers: chandlerc, lattner, majnemer.
ekatz added a project: LLVM.
Herald added subscribers: llvm-commits, hiraditya.

With the fixed implementation of the "remainder" operation, we can now add support to folding calls to it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D69777

Files:
  llvm/include/llvm/Analysis/TargetLibraryInfo.def
  llvm/lib/Analysis/ConstantFolding.cpp


Index: llvm/lib/Analysis/ConstantFolding.cpp
===================================================================
--- llvm/lib/Analysis/ConstantFolding.cpp
+++ llvm/lib/Analysis/ConstantFolding.cpp
@@ -1515,7 +1515,8 @@
   case 'p':
     return Name == "pow" || Name == "powf";
   case 'r':
-    return Name == "rint" || Name == "rintf" ||
+    return Name == "remainder" || Name == "remainderf" ||
+           Name == "rint" || Name == "rintf" ||
            Name == "round" || Name == "roundf";
   case 's':
     return Name == "sin" || Name == "sinf" ||
@@ -2095,6 +2096,14 @@
             return ConstantFP::get(Ty->getContext(), V);
         }
         break;
+      case LibFunc_remainder:
+      case LibFunc_remainderf:
+        if (TLI->has(Func)) {
+          APFloat V = Op1->getValueAPF();
+          if (APFloat::opStatus::opOK == V.remainder(Op2->getValueAPF()))
+            return ConstantFP::get(Ty->getContext(), V);
+        }
+        break;
       case LibFunc_atan2:
       case LibFunc_atan2f:
       case LibFunc_atan2_finite:
@@ -2624,6 +2633,9 @@
       case LibFunc_fmodl:
       case LibFunc_fmod:
       case LibFunc_fmodf:
+      case LibFunc_remainderl:
+      case LibFunc_remainder:
+      case LibFunc_remainderf:
         return Op0.isNaN() || Op1.isNaN() ||
                (!Op0.isInfinity() && !Op1.isZero());
 
Index: llvm/include/llvm/Analysis/TargetLibraryInfo.def
===================================================================
--- llvm/include/llvm/Analysis/TargetLibraryInfo.def
+++ llvm/include/llvm/Analysis/TargetLibraryInfo.def
@@ -1119,6 +1119,15 @@
 /// char *realpath(const char *file_name, char *resolved_name);
 TLI_DEFINE_ENUM_INTERNAL(realpath)
 TLI_DEFINE_STRING_INTERNAL("realpath")
+/// double remainder(double x, double y);
+TLI_DEFINE_ENUM_INTERNAL(remainder)
+TLI_DEFINE_STRING_INTERNAL("remainder")
+/// float remainderf(float x, float y);
+TLI_DEFINE_ENUM_INTERNAL(remainderf)
+TLI_DEFINE_STRING_INTERNAL("remainderf")
+/// long double remainderl(long double x, long double y);
+TLI_DEFINE_ENUM_INTERNAL(remainderl)
+TLI_DEFINE_STRING_INTERNAL("remainderl")
 /// int remove(const char *path);
 TLI_DEFINE_ENUM_INTERNAL(remove)
 TLI_DEFINE_STRING_INTERNAL("remove")


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69777.227633.patch
Type: text/x-patch
Size: 2231 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191103/892a75ac/attachment.bin>


More information about the llvm-commits mailing list