[llvm-commits] [llvm] r147307 - /llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp

Nick Lewycky nicholas at mxc.ca
Tue Dec 27 22:57:32 PST 2011


Author: nicholas
Date: Wed Dec 28 00:57:32 2011
New Revision: 147307

URL: http://llvm.org/viewvc/llvm-project?rev=147307&view=rev
Log:
Demystify this comment.

Modified:
    llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp

Modified: llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp?rev=147307&r1=147306&r2=147307&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp Wed Dec 28 00:57:32 2011
@@ -1664,12 +1664,23 @@
     // Merge probability data into PredBlock's branch.
     APInt A, B, C, D;
     if (ExtractBranchMetadata(PBI, C, D) && ExtractBranchMetadata(BI, A, B)) {
-      // bbA: br bbB (a% probability), bbC (b% prob.)
-      // bbB: br bbD (c% probability), bbC (d% prob.)
-      // --> bbA: br bbD ((a*c)% prob.), bbC ((b+a*d)% prob.)
+      // Given IR which does:
+      //   bbA:
+      //     br i1 %x, label %bbB, label %bbC
+      //   bbB:
+      //     br i1 %y, label %bbD, label %bbC
+      // Let's call the probability that we take the edge from %bbA to %bbB
+      // 'a', from %bbA to %bbC, 'b', from %bbB to %bbD 'c' and from %bbB to
+      // %bbC probability 'd'.
       //
-      // Probabilities aren't stored as ratios directly. Converting to
-      // probability-numerator form, we get:
+      // We transform the IR into:
+      //   bbA:
+      //     br i1 %z, label %bbD, label %bbC
+      // where the probability of going to %bbD is (a*c) and going to bbC is
+      // (b+a*d).
+      //
+      // Probabilities aren't stored as ratios directly. Using branch weights,
+      // we get:
       // (a*c)% = A*C, (b+(a*d))% = A*D+B*C+B*D.
 
       bool Overflow1 = false, Overflow2 = false, Overflow3 = false;





More information about the llvm-commits mailing list