]> granicus.if.org Git - llvm/commitdiff
[APInt] Modify tcMultiplyPart's overflow detection to not depend on 'i' from the...
authorCraig Topper <craig.topper@gmail.com>
Mon, 8 May 2017 06:34:41 +0000 (06:34 +0000)
committerCraig Topper <craig.topper@gmail.com>
Mon, 8 May 2017 06:34:41 +0000 (06:34 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@302408 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/APInt.cpp

index 4a136f72e86f5e2cfe149d371719dabb50086499..caa0691f9205039bb2fd65bb7416d4b2fe9075d0 100644 (file)
@@ -2254,8 +2254,7 @@ int APInt::tcMultiplyPart(WordType *dst, const WordType *src,
   /* 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, const WordType *src,
     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, const WordType *src,
      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;