[PATCH] D31572: [APInt] Allow GreatestCommonDivisor to take rvalue inputs efficiently. Use moves instead of copies in the loop.

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 1 13:43:29 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL299314: [APInt] Allow GreatestCommonDivisor to take rvalue inputs efficiently. Useā€¦ (authored by ctopper).

Changed prior to commit:
  https://reviews.llvm.org/D31572?vs=93753&id=93755#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D31572

Files:
  llvm/trunk/include/llvm/ADT/APInt.h
  llvm/trunk/lib/Support/APInt.cpp


Index: llvm/trunk/lib/Support/APInt.cpp
===================================================================
--- llvm/trunk/lib/Support/APInt.cpp
+++ llvm/trunk/lib/Support/APInt.cpp
@@ -876,13 +876,11 @@
   return Reversed;
 }
 
-APInt llvm::APIntOps::GreatestCommonDivisor(const APInt& API1,
-                                            const APInt& API2) {
-  APInt A = API1, B = API2;
+APInt llvm::APIntOps::GreatestCommonDivisor(APInt A, APInt B) {
   while (!!B) {
-    APInt T = B;
-    B = A.urem(B);
-    A = T;
+    APInt R = A.urem(B);
+    A = std::move(B);
+    B = std::move(R);
   }
   return A;
 }
Index: llvm/trunk/include/llvm/ADT/APInt.h
===================================================================
--- llvm/trunk/include/llvm/ADT/APInt.h
+++ llvm/trunk/include/llvm/ADT/APInt.h
@@ -1937,8 +1937,8 @@
 /// This function returns the greatest common divisor of the two APInt values
 /// using Euclid's algorithm.
 ///
-/// \returns the greatest common divisor of Val1 and Val2
-APInt GreatestCommonDivisor(const APInt &Val1, const APInt &Val2);
+/// \returns the greatest common divisor of \param A and \param B.
+APInt GreatestCommonDivisor(APInt A, APInt B);
 
 /// \brief Converts the given APInt to a double value.
 ///


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31572.93755.patch
Type: text/x-patch
Size: 1247 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170401/ebeb8af4/attachment.bin>


More information about the llvm-commits mailing list