1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-21 20:12:56 +02:00
Commit Graph

33 Commits

Author SHA1 Message Date
Benjamin Kramer
a2f57dee6d Remove all remaining uses of Value::getNameStr().
llvm-svn: 144648
2011-11-15 16:27:03 +00:00
Chandler Carruth
3cbbc35715 Fix the API usage in loop probability heuristics. It was incorrectly
classifying many edges as exiting which were in fact not. These mainly
formed edges into sub-loops. It was also not correctly classifying all
returning edges out of loops as leaving the loop. With this match most
of the loop heuristics are more rational.

Several serious regressions on loop-intesive benchmarks like perlbench's
loop tests when built with -enable-block-placement are fixed by these
updated heuristics. Unfortunately they in turn uncover some other
regressions. There are still several improvemenst that should be made to
loop heuristics including trip-count, and early back-edge management.

llvm-svn: 142917
2011-10-25 09:47:41 +00:00
Chandler Carruth
d04f838629 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.

llvm-svn: 142793
2011-10-24 12:01:08 +00:00
Chandler Carruth
c5722dbec0 Simplify the design of BranchProbabilityInfo by collapsing it into
a single class. Previously it was split between two classes, one
internal and one external. The concern seemed to center around exposing
the weights used, but those can remain confined to the implementation
file.

Having a single class to maintain the state and analyses in use will
also simplify several of the enhancements I want to make to our static
heuristics.

llvm-svn: 142783
2011-10-24 01:40:45 +00:00
Chandler Carruth
93ee01158c Tidy up a loop to be more idiomatic for LLVM's codebase, and remove some
extraneous whitespace. Trying to clean-up this pass as much as I can
before I start making functional changes.

llvm-svn: 142780
2011-10-23 22:40:13 +00:00
Chandler Carruth
151d4fc273 Teach the BranchProbabilityInfo pass to print its results, and use that
to bring it under direct test instead of merely indirectly testing it in
the BlockFrequencyInfo pass.

The next step is to start adding tests for the various heuristics
employed, and to start fixing those heuristics once they're under test.

llvm-svn: 142778
2011-10-23 21:21:50 +00:00
Benjamin Kramer
9adc582e35 Add compare operators to BranchProbability and use it to determine if an edge is hot.
llvm-svn: 142751
2011-10-23 11:19:14 +00:00
Benjamin Kramer
917737037d Extend the floating point heuristic to consider NaN checks unlikely.
llvm-svn: 142687
2011-10-21 21:13:47 +00:00
Benjamin Kramer
66a199d42f BranchProbabilityInfo: floating point equality is unlikely.
This is from the same paper from Ball and Larus as the rest of the currently implemented heuristics.

llvm-svn: 142677
2011-10-21 20:12:47 +00:00
Chandler Carruth
12a645d6f6 Generalize the reading of probability metadata to work for both branches
and switches, with arbitrary numbers of successors. Still optimized for
the common case of 2 successors for a conditional branch.

Add a test case for switch metadata showing up in the BlockFrequencyInfo pass.

llvm-svn: 142493
2011-10-19 10:32:19 +00:00
Chandler Carruth
18a382b4b6 Teach the BranchProbabilityInfo analysis pass to read any metadata
encoding of probabilities. In the absense of metadata, it continues to
fall back on static heuristics.

This allows __builtin_expect, after lowering through llvm.expect
a branch instruction's metadata, to actually enter the branch
probability model. This is one component of resolving PR2577.

llvm-svn: 142492
2011-10-19 10:30:30 +00:00
Chandler Carruth
0334d27ec8 Delete a dead member. Dunno if this was ever used, but the current code
directly manipulates the weights inside of the BranchProbabilityInfo
that is passed in.

llvm-svn: 142163
2011-10-16 22:27:54 +00:00
Benjamin Kramer
0c1a5d2067 Use canonical forms for the branch probability zero heutistic.
- Drop support for X >u 0, it's equivalent to X != 0 and should be canonicalized into the latter.
- Add X < 1 -> unlikely, which is what instcombine canonicalizes X <= 0 into.
- Add X > -1 -> likely, which is what instcombine canonicalizes X >= 0 into.

llvm-svn: 139110
2011-09-04 23:53:04 +00:00
Jakub Staszak
5a47c78397 Change SmallVector to SmallPtrSet in BranchProbabilityInfo. Handle cases where
one than one successor goes to the same block.

llvm-svn: 136638
2011-08-01 19:16:26 +00:00
Jakub Staszak
8f686498df Do not handle cases with >= and <= predicates.
llvm-svn: 136588
2011-07-31 05:54:04 +00:00
Jakub Staszak
0fe2246aab Remove untrue comment.
llvm-svn: 136587
2011-07-31 04:51:14 +00:00
Jakub Staszak
6795c54cb7 Do not handle case where LHS is equal to zero, because InstCombiner always moves
it to RHS anyway.

llvm-svn: 136586
2011-07-31 04:47:20 +00:00
Jakub Staszak
384a405be9 Add Zero Heurestics to BranchProbabilityInfo. If we compare value to zero we
decide whether condition is likely to be true this way:

x == 0  ->  false
x <  0  ->  false
x <= 0  ->  false
x != 0  ->  true
x >  0  ->  true
x >= 0  ->  true

llvm-svn: 136583
2011-07-31 03:27:24 +00:00
Jakub Staszak
02fa079dc3 Add more constantness in BranchProbabilityInfo.
llvm-svn: 136502
2011-07-29 19:30:00 +00:00
Jakub Staszak
ad93033183 Remove incEdgeWeight and decEdgeWeight. Set edge weight directly to avoid
rounding errors.

llvm-svn: 136456
2011-07-29 02:36:53 +00:00
Jakub Staszak
d6d0b202f1 Change LBH_TAKEN_WEIGHT to 124 (from 128). Right now, sum of
LBH_TAKEN_WEIGHT + LBH_NONTAKEN_WEIGHT = 128 which in _most_ cases reduce
number of rounding errors.

llvm-svn: 136428
2011-07-28 23:42:08 +00:00
Jakub Staszak
53da869f0c Heuristics are in descending priority now. If we use one of them, skip the rest.
llvm-svn: 136402
2011-07-28 21:45:07 +00:00
Jakub Staszak
c5d6bbc669 Add InEdges (edges from header to the loop) in Loop Branch Heuristics, so
there is no frequency difference whether condition is in the header or in
the latch.

llvm-svn: 136398
2011-07-28 21:33:46 +00:00
Jakub Staszak
7bd3be24d8 Remove "LoopInfo.h" include from BranchProbabilityInfo.h.
llvm-svn: 135353
2011-07-16 20:31:15 +00:00
Jakub Staszak
ada22d8fca Fix pointer heuristic. Check whether predicator is ICMP_NE instead of if it is
not isEquality().

llvm-svn: 135296
2011-07-15 20:51:06 +00:00
Jakub Staszak
4cd344d775 Calculate backedge probability correctly.
llvm-svn: 133776
2011-06-23 23:52:11 +00:00
Jakub Staszak
d74cc36bcb Introduce BlockFrequency analysis for BasicBlocks.
llvm-svn: 133766
2011-06-23 21:45:20 +00:00
Jakub Staszak
5c7b7d64ba Introduce MachineBranchProbabilityInfo class, which has similar API to
BranchProbabilityInfo (expect setEdgeWeight which is not available here).
Branch Weights are kept in MachineBasicBlocks. To turn off this analysis
set -use-mbpi=false.

llvm-svn: 133184
2011-06-16 20:22:37 +00:00
Benjamin Kramer
8f8ff3e797 Move class into an anonymous namespace.
llvm-svn: 132925
2011-06-13 18:38:56 +00:00
Andrew Trick
4591f882c2 Branch profiling: floating-point avoidance.
Patch by: Jakub Staszak!

Introduces BranchProbability. Changes unsigned to uint32_t all over and
uint64_t only when overflow is expected.

llvm-svn: 132867
2011-06-11 01:05:22 +00:00
Nick Lewycky
813e24b6a9 Fold assert-only-used variable into the assert.
llvm-svn: 132620
2011-06-04 02:07:10 +00:00
Andrew Trick
c894f04286 Missing include of climits in the new BranchProbability pass.
llvm-svn: 132616
2011-06-04 01:30:52 +00:00
Andrew Trick
7a9eb604a9 New BranchProbabilityInfo analysis. Patch by Jakub Staszak!
BranchProbabilityInfo provides an interface for IR passes to query the
likelihood that control follows a CFG edge. This patch provides an
initial implementation of static branch predication that will populate
BranchProbabilityInfo for branches with no external profile
information using very simple heuristics. It currently isn't hooked up
to any external profile data, so static prediction does all the work.

llvm-svn: 132613
2011-06-04 01:16:30 +00:00