If you're doing this inside of APInt and APSInt, you could do it much more cheaply by actually comparing the values rather than building a larger zext'ed copy and then using the existing operator== logic...<div class="gmail_extra">
<br><br><div class="gmail_quote">On Sat, Jul 14, 2012 at 5:23 PM, Eric Christopher <span dir="ltr"><<a href="mailto:echristo@apple.com" target="_blank">echristo@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: echristo<br>
Date: Sat Jul 14 19:23:36 2012<br>
New Revision: 160223<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=160223&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=160223&view=rev</a><br>
Log:<br>
Move IsSameValue from clang's ASTImporter to be methods on the<br>
APInt/APSInt classes.<br>
<br>
Part of rdar://11875995<br>
<br>
Modified:<br>
    llvm/trunk/include/llvm/ADT/APInt.h<br>
    llvm/trunk/include/llvm/ADT/APSInt.h<br>
<br>
Modified: llvm/trunk/include/llvm/ADT/APInt.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/APInt.h?rev=160223&r1=160222&r2=160223&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/APInt.h?rev=160223&r1=160222&r2=160223&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/include/llvm/ADT/APInt.h (original)<br>
+++ llvm/trunk/include/llvm/ADT/APInt.h Sat Jul 14 19:23:36 2012<br>
@@ -511,6 +511,18 @@<br>
     return getAllOnesValue(numBits).lshr(numBits - loBitsSet);<br>
   }<br>
<br>
+  /// \brief Determine if two APInts have the same value, after zero-extending<br>
+  /// one of them (if needed!) to ensure that the bit-widths match.<br>
+  static bool isSameValue(const APInt &I1, const APInt &I2) {<br>
+    if (I1.getBitWidth() == I2.getBitWidth())<br>
+      return I1 == I2;<br>
+<br>
+    if (I1.getBitWidth() > I2.getBitWidth())<br>
+      return I1 == I2.zext(I1.getBitWidth());<br>
+<br>
+    return I1.zext(I2.getBitWidth()) == I2;<br>
+  }<br>
+<br>
   /// \brief Overload to compute a hash_code for an APInt value.<br>
   friend hash_code hash_value(const APInt &Arg);<br>
<br>
<br>
Modified: llvm/trunk/include/llvm/ADT/APSInt.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/APSInt.h?rev=160223&r1=160222&r2=160223&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/APSInt.h?rev=160223&r1=160222&r2=160223&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/include/llvm/ADT/APSInt.h (original)<br>
+++ llvm/trunk/include/llvm/ADT/APSInt.h Sat Jul 14 19:23:36 2012<br>
@@ -250,6 +250,33 @@<br>
                            : APInt::getSignedMinValue(numBits), Unsigned);<br>
   }<br>
<br>
+  /// \brief Determine if two APSInts have the same value, zero- or<br>
+  /// sign-extending as needed.<br>
+  static bool isSameValue(const APSInt &I1, const APSInt &I2) {<br>
+    if (I1.getBitWidth() == I2.getBitWidth() && I1.isSigned() == I2.isSigned())<br>
+      return I1 == I2;<br>
+<br>
+    // Check for a bit-width mismatch.<br>
+    if (I1.getBitWidth() > I2.getBitWidth())<br>
+      return isSameValue(I1, I2.extend(I1.getBitWidth()));<br>
+    else if (I2.getBitWidth() > I1.getBitWidth())<br>
+      return isSameValue(I1.extend(I2.getBitWidth()), I2);<br>
+<br>
+    // We have a signedness mismatch. Turn the signed value into an unsigned<br>
+    // value.<br>
+    if (I1.isSigned()) {<br>
+      if (I1.isNegative())<br>
+        return false;<br>
+<br>
+      return APSInt(I1, true) == I2;<br>
+    }<br>
+<br>
+    if (I2.isNegative())<br>
+      return false;<br>
+<br>
+    return I1 == APSInt(I2, true);<br>
+  }<br>
+<br>
   /// Profile - Used to insert APSInt objects, or objects that contain APSInt<br>
   ///  objects, into FoldingSets.<br>
   void Profile(FoldingSetNodeID& ID) const;<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>