[PATCH] D13745: Replace all uses of branch weights by branch probabilities on machine code level passes.
Cong Hou via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 14 14:56:09 PDT 2015
congh created this revision.
congh added reviewers: dexonsmith, davidxl.
congh added a subscriber: llvm-commits.
Herald added a subscriber: dsanders.
This patch replaces all uses of branch weights by branch probabilities on machine code level passes. Each machine basic block now stores successors' probabilities, which are represented by fixed points with constant denominator. Therefore there is no additional space overhead as branch probability is also 32-bit. The sum of all successors' probabilities should be approximate one (not exact one due to rounding issues when calculating probabilities). There are several advantages of using probabilities instead of weights:
It is much faster and convenient to calculate branch probability for each successor. Previously, in order to get the branch probability, the sum of weights of all successors is calculated first, which is not quite efficient as the potential overflow is considered. When iterating successors and get their probabilities, the code is usually written as (for performance reason) getting the sum first and use the sum and scale value to calculate each successor's probability, which is odd and inconvenient. With this patch, probabilities are directly stored in each machine basic block and all issues above are gone.
Weights are suffering from some maintenance issues, and probabilities are easier to understand and maintain. David's proposal has stated it clearly: http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20150803/291610.html
It is easier to validate the correctness of probabilities list rather than weights list: the sum of the former should be 1 while there is not restriction to the latter. This is quite useful when checking the probability updates after a CFG transformation are correct or not.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 101006 bytes
Desc: not available
More information about the llvm-commits