================
@@ -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:

![fadec_normalized](https://github.com/user-attachments/assets/f5bce708-05f5-4864-8df4-49656a17f279)
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
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to