emscripten-core/emscripten

Branch hinting status?

Opened this issue · 3 comments

Branch hinting proposal is standardized for WebAssembly, yet I see not a single mention of taking advantage of it when compiling code with Emscripten.

Can we use [[likely]], [[unlikely]] attributes along with C++20 and are they going to be translated to WASM branch hints? If no, are there some Emscripten-specific attributes that do this? Does this require some compilation flags?

@kripken was looking into this I believe. As of right now I don't think there is any support for this on the LLVM side.

Binaryen support is done, LLVM support has an open PR which has yet to land:

llvm/llvm-project#146230

Author of the mentioned PR here (sorry for the late notice):
We are currently adding an emitter for the branch hint section to LLVM. The emitted hints are based on the edge probabilities in the LLVM IR control flow graph, which in turn are calculated based on heuristics, profiles (from PGO) or annotations like [[likely]] or __builtin_expect.

Support for parts of the Compilation Hints proposal is also implemented and will be added as soon as the branch hints PR is merged.

In general, branch hinting is rather transparent for emscripten as long as tools downstream of clang, like binaryen, can also handle them (which seems like they can now).