[BPI] Incorrect probability reported in case of mulptiple edges.
authorEvgeniy Brevnov <evgueni.brevnov@gmail.com>
Wed, 29 Apr 2020 07:08:01 +0000 (14:08 +0700)
committerEvgeniy Brevnov <evgueni.brevnov@gmail.com>
Thu, 30 Apr 2020 04:41:03 +0000 (11:41 +0700)
commitbb0842a3f11e5d5a13d3212b627d9f1521bff553
treee8e231555219bffa8f34daf678fa1c8c12bb6efe
parent3e68a667047d1541e445c8f47501d69f5b1a497d
[BPI] Incorrect probability reported in case of mulptiple edges.

Summary:
By design 'BranchProbabilityInfo:: getEdgeProbability(const BasicBlock *Src, const BasicBlock *Dst) const' should return sum of probabilities over all edges from Src to Dst. Current implementation is buggy and returns 1/num_of_successors if probabilities are not explicitly set.

Note current implementation of BPI printing has an issue as well and annotates each edge with sum of probabilities over all ages from one basic block to another. That's why 30% probability reported (instead of 10%) in the lit test. This is not urgent issue since only printing is affected.
Note also current implementation assumes that either all or none edges have probabilities set. This is not the only place which uses such assumption. At least we should assert that in verifier. In addition we can think on a more robust API of BPI which would prevent situations.

Reviewers: skatkov, yrouban, taewookoh

Reviewed By: skatkov

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D79071
llvm/lib/Analysis/BranchProbabilityInfo.cpp
llvm/test/Analysis/BranchProbabilityInfo/switch.ll [new file with mode: 0644]