[llvm] r301053 - [APSInt] Use APInt::compare and APInt::compareSigned to implement APSInt::compareValue

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 21 15:32:28 PDT 2017


Author: ctopper
Date: Fri Apr 21 17:32:27 2017
New Revision: 301053

URL: http://llvm.org/viewvc/llvm-project?rev=301053&view=rev
Log:
[APSInt] Use APInt::compare and APInt::compareSigned to implement APSInt::compareValue

APInt just got compare methods that return -1, 0, or 1 instead of just having ult/slt and eq.

This patch uses these methods to implement APSInt::compareValues so that we don't have to call do an equal comparison and then possibly a second less than comparison.

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

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

Modified: llvm/trunk/include/llvm/ADT/APInt.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/APInt.h?rev=301053&r1=301052&r2=301053&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/APInt.h (original)
+++ llvm/trunk/include/llvm/ADT/APInt.h Fri Apr 21 17:32:27 2017
@@ -90,6 +90,8 @@ private:
 
   friend struct DenseMapAPIntKeyInfo;
 
+  friend class APSInt;
+
   /// \brief Fast internal constructor
   ///
   /// This constructor is used only internally for speed of construction of

Modified: llvm/trunk/include/llvm/ADT/APSInt.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/APSInt.h?rev=301053&r1=301052&r2=301053&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/APSInt.h (original)
+++ llvm/trunk/include/llvm/ADT/APSInt.h Fri Apr 21 17:32:27 2017
@@ -288,12 +288,12 @@ public:
   /// \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 @@ public:
         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); }




More information about the llvm-commits mailing list