Remove return heuristics from the static branch probabilities, and
authorChandler Carruth <chandlerc@gmail.com>
Mon, 24 Oct 2011 12:01:08 +0000 (12:01 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Mon, 24 Oct 2011 12:01:08 +0000 (12:01 +0000)
commitde1c9bb45017e25b5fc2b77e15d3c377f6572075
tree1b10995e8f3cd2b147e48b0533e942fa7278d2fd
parentaa337b7cd556a4e3929cf3944b809aae92f88e64
Remove return heuristics from the static branch probabilities, and
introduce no-return or unreachable heuristics.

The return heuristics from the Ball and Larus paper don't work well in
practice as they pessimize early return paths. The only good hitrate
return heuristics are those for:
 - NULL return
 - Constant return
 - negative integer return

Only the last of these three can possibly require significant code for
the returning block, and even the last is fairly rare and usually also
a constant. As a consequence, even for the cold return paths, there is
little code on that return path, and so little code density to be gained
by sinking it. The places where sinking these blocks is valuable (inner
loops) will already be weighted appropriately as the edge is a loop-exit
branch.

All of this aside, early returns are nearly as common as all three of
these return categories, and should actually be predicted as taken!
Rather than muddy the waters of the static predictions, just remain
silent on returns and let the CFG itself dictate any layout or other
issues.

However, the return heuristic was flagging one very important case:
unreachable. Unfortunately it still gave a 1/4 chance of the
branch-to-unreachable occuring. It also didn't do a rigorous job of
finding those blocks which post-dominate an unreachable block.

This patch builds a more powerful analysis that should flag all branches
to blocks known to then reach unreachable. It also has better worst-case
runtime complexity by not looping through successors for each block. The
previous code would perform an N^2 walk in the event of a single entry
block branching to N successors with a switch where each successor falls
through to the next and they finally fall through to a return.

Test case added for noreturn heuristics. Also doxygen comments improved
along the way.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@142793 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/Analysis/BranchProbabilityInfo.h
lib/Analysis/BranchProbabilityInfo.cpp
test/Analysis/BranchProbabilityInfo/noreturn.ll [new file with mode: 0644]