[llvm] [BFI] Solve irreducible SCCs instead of splitting their headers (PR #215170)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 15 16:17:36 PDT 2026
MaskRay wrote:
> where inference runs, I don't see evidence this patch improves the final result.
Follow-up measurements. `-iterative-bfi-max-iterations-per-block=K` is K sweeps over the function, so it is directly comparable to the 16 sweeps `solveIrreducibleMass` runs over the SCC.
Corpus: 800 generated functions of 70-110 blocks with small embedded irreducible cycles, intra-cycle edges ~10% of
function edges, scored as the worst per-block relative error against an exact rational solve of `f = e + f*P`.
```
<=1% <=10% <=20%
main 16 22 28
+ inference K=1 30 71 109
+ inference K=2 79 215 308
+ inference K=4 191 448 538
+ inference K=8 376 594 621
+ inference K=16 545 648 682
this PR 25 40 51
+ inference K=1 52 103 139
+ inference K=2 113 256 354
+ inference K=4 224 469 569
+ inference K=8 391 622 674
+ inference K=16 552 683 715
```
Across the halves: inference is a refinement seeded by `getFloatingBlockFreq`, not an alternative to it, so the seed is worth iterations.
Inference's smallest possible unit of work is one relaxation pass over the whole reachable function; the solve's is one power iteration over the cycle. On `sqlite3WhereBegin` at `-O3` -- 985 blocks, 1651 edges, one irreducible cycle of 22 blocks and 42 edges -- the solve's *entire* budget is `16 * 42 = 672` multiply-adds, while a single inference sweep is 1651. There is no way to configure inference to cost what the solve costs; its minimum quantum is already 2.5x the solve's total.
And it does not stop at one sweep. Inference on that function runs to its cap and gives up
short of the precision it was asked for:
```
Initial discrepancy = 10.09574105
Completed 985001 inference iterations (1000 per block)
Final discrepancy = 0.0008833567885
```
985001 updates at an average in-degree of 1651/985 is ~1.65M multiply-adds against the solve's
672, and 8.8e-4 is three and a half orders of magnitude short of the 1e-12 target. That ratio
is where the 3.09% geomean goes: the work is proportional to the function, the payoff to the
SCC, and on the functions that actually have irreducible CFGs those differ by three orders of
magnitude.
https://github.com/llvm/llvm-project/pull/215170
More information about the llvm-commits
mailing list