<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Wed, May 10, 2017 at 1:14 PM Craig Topper via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: ctopper<br>
Date: Wed May 10 15:01:38 2017<br>
New Revision: 302716<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=302716&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=302716&view=rev</a><br>
Log:<br>
[APInt] Add negate helper method to implement twos complement. Use it to shorten code.<br>
<br>
Modified:<br>
    llvm/trunk/include/llvm/ADT/APInt.h<br>
    llvm/trunk/lib/Support/APInt.cpp<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=302716&r1=302715&r2=302716&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/APInt.h?rev=302716&r1=302715&r2=302716&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/ADT/APInt.h (original)<br>
+++ llvm/trunk/include/llvm/ADT/APInt.h Wed May 10 15:01:38 2017<br>
@@ -1437,6 +1437,12 @@ public:<br>
   /// as "bitPosition".<br>
   void flipBit(unsigned bitPosition);<br>
<br>
+  /// Negate this APInt in place.<br>
+  void negate() {<br>
+    flipAllBits();<br>
+    ++(*this);<br></blockquote><div><br>If you like, you can drop the () here ^ and write: ++*this<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+  }<br>
+<br>
   /// Insert the bits from a smaller APInt starting at bitPosition.<br>
   void insertBits(const APInt &SubBits, unsigned bitPosition);<br>
<br>
@@ -1996,8 +2002,7 @@ inline raw_ostream &operator<<(raw_ostre<br>
 }<br>
<br>
 inline APInt operator-(APInt v) {<br>
-  v.flipAllBits();<br>
-  ++v;<br>
+  v.negate();<br>
   return v;<br>
 }<br>
<br>
<br>
Modified: llvm/trunk/lib/Support/APInt.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/APInt.cpp?rev=302716&r1=302715&r2=302716&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/APInt.cpp?rev=302716&r1=302715&r2=302716&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Support/APInt.cpp (original)<br>
+++ llvm/trunk/lib/Support/APInt.cpp Wed May 10 15:01:38 2017<br>
@@ -1846,10 +1846,8 @@ void APInt::fromString(unsigned numbits,<br>
     *this += digit;<br>
   }<br>
   // If its negative, put it in two's complement form<br>
-  if (isNeg) {<br>
-    --(*this);<br>
-    this->flipAllBits();<br>
-  }<br>
+  if (isNeg)<br>
+    this->negate();<br></blockquote><div><br>Any particular reason for the "this->" qualification? <br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
 }<br>
<br>
 void APInt::toString(SmallVectorImpl<char> &Str, unsigned Radix,<br>
@@ -1927,8 +1925,7 @@ void APInt::toString(SmallVectorImpl<cha<br>
     // They want to print the signed version and it is a negative value<br>
     // Flip the bits and add one to turn it into the equivalent positive<br>
     // value and put a '-' in the result.<br>
-    Tmp.flipAllBits();<br>
-    ++Tmp;<br>
+    Tmp.negate();<br>
     Str.push_back('-');<br>
   }<br>
<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div></div>