[PATCH] D32381: [APSInt] Use APInt::compare and APInt::compareSigned to implement APSInt::compareValue

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 21 15:45:25 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL301053: [APSInt] Use APInt::compare and APInt::compareSigned to implement APSInt… (authored by ctopper).

Changed prior to commit:
  https://reviews.llvm.org/D32381?vs=96245&id=96256#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D32381

Files:
  llvm/trunk/include/llvm/ADT/APInt.h
  llvm/trunk/include/llvm/ADT/APSInt.h


Index: llvm/trunk/include/llvm/ADT/APSInt.h
===================================================================
--- llvm/trunk/include/llvm/ADT/APSInt.h
+++ llvm/trunk/include/llvm/ADT/APSInt.h
@@ -288,12 +288,12 @@
   /// \brief Compare underlying values of two numbers.
   static int compareValues(const APSInt &I1, const APSInt &I2) {
     if (I1.getBitWidth() == I2.getBitWidth() && I1.isSigned() == I2.isSigned())
-      return I1 == I2 ? 0 : I1 > I2 ? 1 : -1;
+      return I1.IsUnsigned ? I1.compare(I2) : I1.compareSigned(I2);
 
     // Check for a bit-width mismatch.
     if (I1.getBitWidth() > I2.getBitWidth())
       return compareValues(I1, I2.extend(I1.getBitWidth()));
-    else if (I2.getBitWidth() > I1.getBitWidth())
+    if (I2.getBitWidth() > I1.getBitWidth())
       return compareValues(I1.extend(I2.getBitWidth()), I2);
 
     // We have a signedness mismatch. Check for negative values and do an
@@ -308,7 +308,7 @@
         return 1;
     }
 
-    return I1.eq(I2) ? 0 : I1.ugt(I2) ? 1 : -1;
+    return I1.compare(I2);
   }
 
   static APSInt get(int64_t X) { return APSInt(APInt(64, X), false); }
Index: llvm/trunk/include/llvm/ADT/APInt.h
===================================================================
--- llvm/trunk/include/llvm/ADT/APInt.h
+++ llvm/trunk/include/llvm/ADT/APInt.h
@@ -90,6 +90,8 @@
 
   friend struct DenseMapAPIntKeyInfo;
 
+  friend class APSInt;
+
   /// \brief Fast internal constructor
   ///
   /// This constructor is used only internally for speed of construction of


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32381.96256.patch
Type: text/x-patch
Size: 1527 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170421/552ad223/attachment.bin>


More information about the llvm-commits mailing list