[PATCH] D35804: [BPI] Detect branches in loops that make themselves not taken

John Brawn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 20 08:51:37 PST 2018


john.brawn added a comment.

In https://reviews.llvm.org/D35804#1002438, @davidxl wrote:

> The branch probability depends on other factors which is not considered here.
>
> For instance
>
> 1. the value of MAX. In the example, if MAX is 1, then the branch probablity should be 50%
> 2. the step /increment of n
>
>   More generally, the predicted probability should depend on MAX/step. The larger the value, the less likely the branch is taken.


That's true, but making the probability more precise would make the analysis here more complicated and I don't think it's worth it. 50% is a safe lower bound: we know the branch will be not taken at least 50% of the time and never less than that, assuming a large enough number of iterations (for small numbers of iterations whether the iteration count is even/odd will have an effect, e.g. for 1 iteration the branch may be always taken, but when the loop has a small number of iterations it won't be hot so it doesn't matter what we think the probability is).


Repository:
  rL LLVM

https://reviews.llvm.org/D35804





More information about the llvm-commits mailing list