[llvm] [EarlyIfConversion] Limit critical-path growth for strongly biased branches (PR #228709)

Dávid Bolvanský via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 4 03:22:10 PDT 2026


davidbolvansky wrote:

> If you keep the branch the core can execute loop iterations in parallel speculatively, but once you introduce a select you serialize the execution

Yes, that makes sense. I tried a local prototype which sets the conversion budget to zero when the selected value directly feeds a loop-header PHI, without using branch weights.

On a small decode loop on an Apple M CPU, keeping the branch reduced elapsed time by 54.6% with randomly distributed 99.9% biased inputs, but was 4.2x slower with random 50/50 inputs. Five alternating rounds, same IR; these are microbenchmark results, not full zstd results. It also replaced a csinc with extra branches in the existing ifcvt-select.ll test, so I haven't pushed it.

So I think the recurrence is important, but the check I tried is too broad. Would accounting for the added recurrence latency, while keeping a branch predictability heuristic, be a reasonable direction? Or is there a better way to model this in the existing trace analysis?

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


More information about the llvm-commits mailing list