Skip to content

Conversation

kripken
Copy link
Member

@kripken kripken commented May 27, 2025

This pass statically infers branch hint annotations, inspired by
LLVM's BranchProbabilityInfo:

https://github.com/llvm/llvm-project/blob/main/llvm/lib/Analysis/BranchProbabilityInfo.cpp

So far this sets low priority for throwing paths and even lower for
unreachable ones. It propagates such indications back to calling
blocks and even calling functions.

LLVM does a little more, it also has some minor hints for things like
a float being NaN (unlikely) and an integer/pointer being 0 (unlikely),
etc.

This pass has no benefit I can measure. My best guess is that we mostly
end up marking exit paths from functions (error handling, etc.), and VMs
can place those blocks and regalloc them efficiently without our hints.
The cross-function part can't be done by VMs, and adds a signficant
amount of hints (3-50% on real-world binaries) but even that does not
help any benchmark I have tried (Emscripten benchmark suite). Opening
this PR as draft to share that information, and maybe as a basis for future
work.

@tlively
Copy link
Member

tlively commented May 27, 2025

Is that 3-50% of original code size or number of hints?

@kripken
Copy link
Member Author

kripken commented May 27, 2025

Number of hints. So if function analysis gives 100 hints in the entire module, cross-function analysis adds 3-50 on top.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants