[clang] [lld] [llvm] [LLVM][WebAssembly] Implement branch hinting proposal (PR #146230)
Lukas Döllerer via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 2 04:23:38 PDT 2025
================
@@ -2608,6 +2612,21 @@ void WebAssemblyCFGStackify::rewriteDepthImmediates(MachineFunction &MF) {
Stack.push_back(std::make_pair(&MBB, &MI));
break;
+ case WebAssembly::BR_IF: {
+ // this is the last place where we can easily calculate the branch
+ // probabilities. we do not emit scf-ifs, therefore, only br_ifs have
+ // to be annotated with branch probabilities.
+ if (MF.getSubtarget<WebAssemblySubtarget>().hasBranchHinting() &&
+ MI.getParent()->hasSuccessorProbabilities()) {
+ const auto Prob = MBPI->getEdgeProbability(
+ MI.getParent(), MI.operands().begin()->getMBB());
+ WebAssemblyFunctionInfo *MFI = MF.getInfo<WebAssemblyFunctionInfo>();
+ assert(!MFI->BranchProbabilities.contains(&MI));
+ MFI->BranchProbabilities[&MI] = Prob;
+ }
----------------
Lukasdoe wrote:

Preliminary benchmark with the new code. The `wamrc-aot-wasi-branch-hints` uses a patched wamr version that supports branch hints.
D8: V8 version 13.9.0 (candidate)
WAMR_IWASM: iwasm 2.3.1
CLANG_NATIVE: clang version 21.0.0git (https://github.com/Lukasdoe/llvm-project 7cca0fe5b78f98dfa378d6f61e8d77a58e708296)
GCC_NATIVE: gcc-14 (Ubuntu 14.2.0-4ubuntu2~24.04) 14.2.0
https://github.com/llvm/llvm-project/pull/146230
More information about the llvm-commits
mailing list