[BFI] Solve irreducible SCCs instead of splitting their headers (#215170)
c5a3139ebd0d (2014) approximates irreducible control flow by modelling
an SCC as a loop with multiple headers, and
http://reviews.llvm.org/D10348 re-distributes the loop mass across those
headers in proportion to the backedge mass each one received -- one step
of a power iteration, from an assumed split.
Package the SCC with a single representative and solve it instead.
`solveIrreducibleMass` iterates the SCC's internal chain towards its
dominant eigenvector and reads the member masses, the exits and the
circulating mass off that, so the entries' relative frequencies come out
of the solve. Power iteration rather than a relaxation of `f = e +
f*P`: the mass `e` entering the SCC is unknown here, so there is no
fixed point to relax towards, only a direction. NumHeaders, the
per-header BackedgeMass, getHeaderIndex, the isHeader binary search and
adjustLoopHeaderMass go away with the split.
Relative error against an exact rational solve has improved.
```
higher is better | relative error (lower is better)
exact within 1% within 10% | p50 p90 max
before 93 111 118 | 0.99 5.27 521.6
after 93 112 129 | 0.77 2.40 46.2
```
Among the lit tests, selfloops and unequalrows converge to their exact
ratios, and nonentry's worst block is off by 1.9x rather than 31.5x.
Bound the iteration rather than run it to convergence: a periodic SCC
oscillates and never terminates, and over that corpus the error
distribution is the same at 16 iterations as at 1000, moving
non-monotonically in between. The work is bounded by the size of the
SCC rather than by the function.
This does not subsume -use-iterative-bfi-inference (0a0800c4d10c), which
relaxes the same equations over the whole function, where the entry mass
is known. On yyparse_1 in profile-correlation-irreducible-loops.ll the
solve alone puts b2 at 2.1x the entry against an exact 586.19x, and
inference reaches 586.19x either way. Over the corpus above the two
stack: enabling inference takes within 10% from 118 to 137 functions
before this patch and from 129 to 144 after.
CFGMST weights edges by BFI, so the instrumentation counter indices
permute. Re-record Inputs/irreducible{,_entry}.proftext under the new
numbering; the block counts the tests check are unchanged.
LLM-assisted