diff options
author | Nick Lewycky <nicholas@mxc.ca> | 2011-12-28 06:57:32 +0000 |
---|---|---|
committer | Nick Lewycky <nicholas@mxc.ca> | 2011-12-28 06:57:32 +0000 |
commit | 8da7ddf2d28d27e8b7fd8b7f159e2d9584bdc819 (patch) | |
tree | 0e4e9eeaaf8bd499a2b9a96632fdb1c4064319e1 /lib/Transforms/Utils/SimplifyCFG.cpp | |
parent | 99f9a20ba396ea35b824fe4960133446f5484e1f (diff) |
Demystify this comment.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@147307 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils/SimplifyCFG.cpp')
-rw-r--r-- | lib/Transforms/Utils/SimplifyCFG.cpp | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp index 7c94bcc997..421156cdf9 100644 --- a/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/lib/Transforms/Utils/SimplifyCFG.cpp @@ -1664,12 +1664,23 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI) { // 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; |