<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Oct 10, 2014 at 3:18 AM, Benjamin Kramer <span dir="ltr"><<a href="mailto:benny.kra@googlemail.com" target="_blank">benny.kra@googlemail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: d0k<br>
Date: Fri Oct 10 05:18:12 2014<br>
New Revision: 219487<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=219487&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=219487&view=rev</a><br>
Log:<br>
APInt: Unfold return expressions so RVO can work.<br>
<br>
Saves a couple of expensive deep copies. NFC.<br></blockquote><div><br></div><div>Perhaps somewhat annoying, but could we fix this more generically by providing an rvalue overload of clearUnusedBits? (that returns by value, moving out of the current object) I guess that'd still incur some moves, rather than the completely free NRVO.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Modified:<br>
    llvm/trunk/lib/Support/APInt.cpp<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=219487&r1=219486&r2=219487&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/APInt.cpp?rev=219487&r1=219486&r2=219487&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Support/APInt.cpp (original)<br>
+++ llvm/trunk/lib/Support/APInt.cpp Fri Oct 10 05:18:12 2014<br>
@@ -454,8 +454,10 @@ APInt APInt::XorSlowCase(const APInt& RH<br>
   for (unsigned i = 0; i < numWords; ++i)<br>
     val[i] = pVal[i] ^ RHS.pVal[i];<br>
<br>
+  APInt Result(val, getBitWidth());<br>
   // 0^0==1 so clear the high bits in case they got set.<br>
-  return APInt(val, getBitWidth()).clearUnusedBits();<br>
+  Result.clearUnusedBits();<br>
+  return Result;<br>
 }<br>
<br>
 APInt APInt::operator*(const APInt& RHS) const {<br>
@@ -473,7 +475,8 @@ APInt APInt::operator+(const APInt& RHS)<br>
     return APInt(BitWidth, VAL + RHS.VAL);<br>
   APInt Result(BitWidth, 0);<br>
   add(Result.pVal, this->pVal, RHS.pVal, getNumWords());<br>
-  return Result.clearUnusedBits();<br>
+  Result.clearUnusedBits();<br>
+  return Result;<br>
 }<br>
<br>
 APInt APInt::operator-(const APInt& RHS) const {<br>
@@ -482,7 +485,8 @@ APInt APInt::operator-(const APInt& RHS)<br>
     return APInt(BitWidth, VAL - RHS.VAL);<br>
   APInt Result(BitWidth, 0);<br>
   sub(Result.pVal, this->pVal, RHS.pVal, getNumWords());<br>
-  return Result.clearUnusedBits();<br>
+  Result.clearUnusedBits();<br>
+  return Result;<br>
 }<br>
<br>
 bool APInt::EqualSlowCase(const APInt& RHS) const {<br>
@@ -1114,7 +1118,9 @@ APInt APInt::ashr(unsigned shiftAmt) con<br>
   uint64_t fillValue = (isNegative() ? -1ULL : 0);<br>
   for (unsigned i = breakWord+1; i < getNumWords(); ++i)<br>
     val[i] = fillValue;<br>
-  return APInt(val, BitWidth).clearUnusedBits();<br>
+  APInt Result(val, BitWidth);<br>
+  Result.clearUnusedBits();<br>
+  return Result;<br>
 }<br>
<br>
 /// Logical right-shift this APInt by shiftAmt.<br>
@@ -1151,7 +1157,9 @@ APInt APInt::lshr(unsigned shiftAmt) con<br>
   // If we are shifting less than a word, compute the shift with a simple carry<br>
   if (shiftAmt < APINT_BITS_PER_WORD) {<br>
     lshrNear(val, pVal, getNumWords(), shiftAmt);<br>
-    return APInt(val, BitWidth).clearUnusedBits();<br>
+    APInt Result(val, BitWidth);<br>
+    Result.clearUnusedBits();<br>
+    return Result;<br>
   }<br>
<br>
   // Compute some values needed by the remaining shift algorithms<br>
@@ -1164,7 +1172,9 @@ APInt APInt::lshr(unsigned shiftAmt) con<br>
       val[i] = pVal[i+offset];<br>
     for (unsigned i = getNumWords()-offset; i < getNumWords(); i++)<br>
       val[i] = 0;<br>
-    return APInt(val,BitWidth).clearUnusedBits();<br>
+    APInt Result(val, BitWidth);<br>
+    Result.clearUnusedBits();<br>
+    return Result;<br>
   }<br>
<br>
   // Shift the low order words<br>
@@ -1178,7 +1188,9 @@ APInt APInt::lshr(unsigned shiftAmt) con<br>
   // Remaining words are 0<br>
   for (unsigned i = breakWord+1; i < getNumWords(); ++i)<br>
     val[i] = 0;<br>
-  return APInt(val, BitWidth).clearUnusedBits();<br>
+  APInt Result(val, BitWidth);<br>
+  Result.clearUnusedBits();<br>
+  return Result;<br>
 }<br>
<br>
 /// Left-shift this APInt by shiftAmt.<br>
@@ -1211,7 +1223,9 @@ APInt APInt::shlSlowCase(unsigned shiftA<br>
       val[i] = pVal[i] << shiftAmt | carry;<br>
       carry = pVal[i] >> (APINT_BITS_PER_WORD - shiftAmt);<br>
     }<br>
-    return APInt(val, BitWidth).clearUnusedBits();<br>
+    APInt Result(val, BitWidth);<br>
+    Result.clearUnusedBits();<br>
+    return Result;<br>
   }<br>
<br>
   // Compute some values needed by the remaining shift algorithms<br>
@@ -1224,7 +1238,9 @@ APInt APInt::shlSlowCase(unsigned shiftA<br>
       val[i] = 0;<br>
     for (unsigned i = offset; i < getNumWords(); i++)<br>
       val[i] = pVal[i-offset];<br>
-    return APInt(val,BitWidth).clearUnusedBits();<br>
+    APInt Result(val, BitWidth);<br>
+    Result.clearUnusedBits();<br>
+    return Result;<br>
   }<br>
<br>
   // Copy whole words from this to Result.<br>
@@ -1235,7 +1251,9 @@ APInt APInt::shlSlowCase(unsigned shiftA<br>
   val[offset] = pVal[0] << wordShift;<br>
   for (i = 0; i < offset; ++i)<br>
     val[i] = 0;<br>
-  return APInt(val, BitWidth).clearUnusedBits();<br>
+  APInt Result(val, BitWidth);<br>
+  Result.clearUnusedBits();<br>
+  return Result;<br>
 }<br>
<br>
 APInt APInt::rotl(const APInt &rotateAmt) 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></div>