[llvm] r302408 - [APInt] Modify tcMultiplyPart's overflow detection to not depend on 'i' from the earlier loop. NFC

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Sun May 7 23:34:41 PDT 2017


Author: ctopper
Date: Mon May  8 01:34:41 2017
New Revision: 302408

URL: http://llvm.org/viewvc/llvm-project?rev=302408&view=rev
Log:
[APInt] Modify tcMultiplyPart's overflow detection to not depend on 'i' from the earlier loop. NFC

The value of 'i' is always the smaller of DstParts and SrcParts so we can just use that fact to write all the code in terms of SrcParts and DstParts.

Modified:
    llvm/trunk/lib/Support/APInt.cpp

Modified: llvm/trunk/lib/Support/APInt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/APInt.cpp?rev=302408&r1=302407&r2=302408&view=diff
==============================================================================
--- llvm/trunk/lib/Support/APInt.cpp (original)
+++ llvm/trunk/lib/Support/APInt.cpp Mon May  8 01:34:41 2017
@@ -2254,8 +2254,7 @@ int APInt::tcMultiplyPart(WordType *dst,
   /* N loops; minimum of dstParts and srcParts.  */
   unsigned n = std::min(dstParts, srcParts);
 
-  unsigned i;
-  for (i = 0; i < n; i++) {
+  for (unsigned i = 0; i < n; i++) {
     WordType low, mid, high, srcPart;
 
       /* [ LOW, HIGH ] = MULTIPLIER * SRC[i] + DST[i] + CARRY.
@@ -2306,10 +2305,10 @@ int APInt::tcMultiplyPart(WordType *dst,
     carry = high;
   }
 
-  if (i < dstParts) {
+  if (srcParts < dstParts) {
     /* Full multiplication, there is no overflow.  */
-    assert(i + 1 == dstParts);
-    dst[i] = carry;
+    assert(srcParts + 1 == dstParts);
+    dst[srcParts] = carry;
     return 0;
   }
 
@@ -2321,7 +2320,7 @@ int APInt::tcMultiplyPart(WordType *dst,
      non-zero.  This is true if any remaining src parts are non-zero
      and the multiplier is non-zero.  */
   if (multiplier)
-    for (; i < srcParts; i++)
+    for (unsigned i = dstParts; i < srcParts; i++)
       if (src[i])
         return 1;
 




More information about the llvm-commits mailing list