[llvm-branch-commits] [llvm-branch] r223716 - Merging r223500 (this time for real):

Duncan P. N. Exon Smith dexonsmith at apple.com
Mon Dec 8 15:29:14 PST 2014


Author: dexonsmith
Date: Mon Dec  8 17:29:14 2014
New Revision: 223716

URL: http://llvm.org/viewvc/llvm-project?rev=223716&view=rev
Log:
Merging r223500 (this time for real):
------------------------------------------------------------------------
r223500 | dexonsmith | 2014-12-05 11:13:42 -0800 (Fri, 05 Dec 2014) | 9 lines

BFI: Saturate when combining edges to a successor

When a loop gets bundled up, its outgoing edges are quite large, and can
just barely overflow 64-bits.  If one successor has multiple incoming
edges -- and that successor is getting all the incoming mass --
combining just its edges can overflow.  Handle that by saturating rather
than asserting.

This fixes PR21622.
------------------------------------------------------------------------

Added:
    llvm/branches/release_35/test/Analysis/BlockFrequencyInfo/extremely-likely-loop-successor.ll
      - copied unchanged from r223500, llvm/trunk/test/Analysis/BlockFrequencyInfo/extremely-likely-loop-successor.ll
Modified:
    llvm/branches/release_35/   (props changed)
    llvm/branches/release_35/lib/Analysis/BlockFrequencyInfoImpl.cpp

Propchange: llvm/branches/release_35/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Dec  8 17:29:14 2014
@@ -1,3 +1,3 @@
 /llvm/branches/Apple/Pertwee:110850,110961
 /llvm/branches/type-system-rewrite:133420-134817
-/llvm/trunk:155241,213653,213665,213726,213749,213773,213793,213798-213799,213815,213847,213880,213883-213884,213894-213896,213899,213915,213966,213999,214060,214129,214180,214287,214331,214423,214429,214519,214670,214674,214679,215685,215711,215806,216064,216262,216531,216891,216920,217102,217115,217257,218745,221009,221318,221408,221453,221501,222338,222376,222500,223163,223170-223171
+/llvm/trunk:155241,213653,213665,213726,213749,213773,213793,213798-213799,213815,213847,213880,213883-213884,213894-213896,213899,213915,213966,213999,214060,214129,214180,214287,214331,214423,214429,214519,214670,214674,214679,215685,215711,215806,216064,216262,216531,216891,216920,217102,217115,217257,218745,221009,221318,221408,221453,221501,222338,222376,222500,223163,223170-223171,223500

Modified: llvm/branches/release_35/lib/Analysis/BlockFrequencyInfoImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_35/lib/Analysis/BlockFrequencyInfoImpl.cpp?rev=223716&r1=223715&r2=223716&view=diff
==============================================================================
--- llvm/branches/release_35/lib/Analysis/BlockFrequencyInfoImpl.cpp (original)
+++ llvm/branches/release_35/lib/Analysis/BlockFrequencyInfoImpl.cpp Mon Dec  8 17:29:14 2014
@@ -14,7 +14,7 @@
 #include "llvm/Analysis/BlockFrequencyInfoImpl.h"
 #include "llvm/ADT/SCCIterator.h"
 #include "llvm/Support/raw_ostream.h"
-#include <deque>
+#include <numeric>
 
 using namespace llvm;
 using namespace llvm::bfi_detail;
@@ -123,8 +123,12 @@ static void combineWeight(Weight &W, con
   }
   assert(W.Type == OtherW.Type);
   assert(W.TargetNode == OtherW.TargetNode);
-  assert(W.Amount < W.Amount + OtherW.Amount && "Unexpected overflow");
-  W.Amount += OtherW.Amount;
+  assert(OtherW.Amount && "Expected non-zero weight");
+  if (W.Amount > W.Amount + OtherW.Amount)
+    // Saturate on overflow.
+    W.Amount = UINT64_MAX;
+  else
+    W.Amount += OtherW.Amount;
 }
 static void combineWeightsBySorting(WeightList &Weights) {
   // Sort so edges to the same node are adjacent.
@@ -207,11 +211,19 @@ void Distribution::normalize() {
     Shift = 33 - countLeadingZeros(Total);
 
   // Early exit if nothing needs to be scaled.
-  if (!Shift)
+  if (!Shift) {
+    // If we didn't overflow then combineWeights() shouldn't have changed the
+    // sum of the weights, but let's double-check.
+    assert(Total == std::accumulate(Weights.begin(), Weights.end(), UINT64_C(0),
+                                    [](uint64_t Sum, const Weight &W) {
+                      return Sum + W.Amount;
+                    }) &&
+           "Expected total to be correct");
     return;
+  }
 
   // Recompute the total through accumulation (rather than shifting it) so that
-  // it's accurate after shifting.
+  // it's accurate after shifting and any changes combineWeights() made above.
   Total = 0;
 
   // Sum the weights to each node and shift right if necessary.





More information about the llvm-branch-commits mailing list