[llvm] [Analysis] Use CycleInfo for BlockFrequencyInfo (PR #213488)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 1 15:43:03 PDT 2026


MaskRay wrote:

Context:

BlockFrequencyInfo is based on the Wu-Larus algorithm, which only handles reducible loops. @dexonsmith added irreducible loop support in 2014 (384d0e8ad4e1). It remains single-pass and does not solve for the Markov
chain's stationary distribution, which is what this problem is. The 2014 `llvm/test/Analysis/BlockFrequencyInfo/irreducible.ll` remains the primary test case - many check-llvm tests are lenient to BFI experiments I am running.

https://reviews.llvm.org/D103289 (2021) added `-use-iterative-bfi-inference` (used by Meta Platforms), an opt-in chaotic relaxation for SamplePGO. This PR changes the default, non-iterative algorithm.

---

20 of the 21 touched tests are pass-plumbing.
`llvm/test/CodeGen/AArch64/late-taildup-computed-goto.ll` is the only codegen change, and there **the new algorithm computes the closed form**. After late tail duplication the machine CFG is a 6-block clique where every block has the same successor distribution -- 31/36 to `loop.header`, 1/36 to each `op` -- so the
stationary vector is that row and the exact ratio is 31.

```
% fllc -mtriple=aarch64 -stop-before=block-placement < llvm/test/CodeGen/AArch64/late-taildup-computed-goto.ll -o /tmp/t/taildup.mir && fllc -mtriple=aarch64 -p 'print<machine-block-freq>,print<machine-cycles>,print<machine-loops>' /tmp/t/taildup.mir
Machine block frequency for machine function: test_interp
block-frequency-info: test_interp
...

    depth=1: entries(bb.5.op5.bb bb.4.op4.bb bb.3.op2.bb bb.1.loop.header bb.6.op6.bb bb.2.op1.bb)
        depth=2: entries(bb.4.op4.bb bb.3.op2.bb bb.1.loop.header bb.6.op6.bb bb.2.op1.bb)
            depth=3: entries(bb.3.op2.bb bb.1.loop.header bb.6.op6.bb bb.2.op1.bb)
                depth=4: entries(bb.1.loop.header bb.6.op6.bb bb.2.op1.bb)
                    depth=5: entries(bb.6.op6.bb bb.2.op1.bb)
                        depth=6: entries(bb.2.op1.bb)
Machine loop info for machine function 'test_interp':
Loop at depth 1 containing: %bb.5<header><latch><exiting>
Loop at depth 1 containing: %bb.4<header><latch><exiting>
Loop at depth 1 containing: %bb.3<header><latch><exiting>
Loop at depth 1 containing: %bb.1<header><latch><exiting>
Loop at depth 1 containing: %bb.6<header><latch><exiting>
Loop at depth 1 containing: %bb.2<header><latch><exiting>
```

https://github.com/llvm/llvm-project/pull/213488


More information about the llvm-commits mailing list