This is an archive of the discontinued LLVM Phabricator instance.

Allow 0-weight branches in BranchProbabilityInfo.
ClosedPublic

Authored by dnovillo on May 6 2015, 9:25 AM.

Details

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.

Hans, could you take a look at the code I added to compensate for 0-weight
branches in the switch lowering code? I've tried to look for a better
place to add the flooring code, but couldn't find it.

The rest of the patch just mechanically adjusts for branches that now have
the correct weight set to 0.

Diff Detail

Repository
rL LLVM

Event Timeline

dnovillo updated this revision to Diff 25056.May 6 2015, 9:25 AM
dnovillo retitled this revision from to Allow 0-weight branches in BranchProbabilityInfo..
dnovillo updated this object.
dnovillo edited the test plan for this revision. (Show Details)
dnovillo added a reviewer: hansw.
dnovillo added a subscriber: Unknown Object (MLST).
hans added a subscriber: hans.May 6 2015, 9:41 AM
hans added inline comments.
lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
8024 ↗(On Diff #25056)

This looks good. I can address this TODO later.

I figured this would be the only change necessary for the switch lowering code. Are the changes to getEdgeWeight() and lowerWorkItem() also necessary?

dnovillo updated this revision to Diff 25065.May 6 2015, 10:18 AM
  • Only floor branch weights to 1 in visitSwitch().
This revision was automatically updated to reflect the committed changes.