Allow 0-weight branches in BranchProbabilityInfo.

Summary:
When computing branch weights in BPI, we used to disallow branches with
weight 0. This is a minor nuisance, because a branch with weight 0 is
different to "don't have information". In the context of
instrumentation, it may mean "never executed", in the context of
sampling, it means "never or seldom executed".

In allowing 0 weight branches, I ran into issues with the switch
expansion code in selection DAG. It is currently hardwired to not handle
branches with weight 0. To maintain the current behaviour, I changed it
to use 1 when it finds 0, but perhaps the algorithm needs changes to
tolerate branches with weight zero.

Reviewers: hansw

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D9533

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@236617 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Diego Novillo
2015-05-06 17:55:11 +00:00
parent 5a6ea245b0
commit 26e46f2283
5 changed files with 26 additions and 20 deletions

View File

@@ -52,8 +52,8 @@ while.cond: ; preds = %if.end, %entry
store i32 %inc, i32* %i, align 4, !dbg !14
%cmp = icmp slt i32 %0, 400000000, !dbg !14
br i1 %cmp, label %while.body, label %while.end, !dbg !14
; CHECK: edge while.cond -> while.body probability is 5391 / 5392 = 99.9815% [HOT edge]
; CHECK: edge while.cond -> while.end probability is 1 / 5392 = 0.018546%
; CHECK: edge while.cond -> while.body probability is 5391 / 5391 = 100% [HOT edge]
; CHECK: edge while.cond -> while.end probability is 0 / 5391 = 0%
while.body: ; preds = %while.cond
%1 = load i32, i32* %i, align 4, !dbg !16
@@ -63,8 +63,8 @@ while.body: ; preds = %while.cond
; both branches out of while.body had the same weight. In reality,
; the edge while.body->if.then is taken most of the time.
;
; CHECK: edge while.body -> if.then probability is 5752 / 5753 = 99.9826% [HOT edge]
; CHECK: edge while.body -> if.else probability is 1 / 5753 = 0.0173822%
; CHECK: edge while.body -> if.then probability is 5752 / 5752 = 100% [HOT edge]
; CHECK: edge while.body -> if.else probability is 0 / 5752 = 0%
if.then: ; preds = %while.body