Estimating branch probability using Intel LBR feature

Estimating branch probability using Intel LBR feature

Intel LBR (Last branch record) is one of my favorite CPU performance monitoring features. We also can confirm it with collecting perf statistics:

Next step is to locate the exact place in the code where the most of branch mispredictions happen. Now we can also calculate how often this condition was true or false:

I was really surprised with such numbers so I decided to manually instrument the code and log all the branch outcomes in this place of the benchmark:

And indeed this branch has 50% probability of being true.

Source: easyperf.net