Skip to content

BranchHintAnalysis pass #7625

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 64 commits into
base: main
Choose a base branch
from
Draft

BranchHintAnalysis pass #7625

wants to merge 64 commits into from

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