Conversation
0b56af7 to
d3bd563
Compare
| (func (export "swapped") (param i32 i32) (result i32) | ||
| local.get 0 | ||
| (@metadata.code.branch_hint "\01") | ||
| if (result i32) |
There was a problem hiding this comment.
Is this patch focuses on if-else construct? Can we do the swap in byte code level?
There was a problem hiding this comment.
I think bytecode level remapping can be problematic in TryCatch instruction.
There was a problem hiding this comment.
Good point. You need to swap them as well.
Btw this is a good idea. We could introduce the concept of basic blocks before this change, and we could reorganize them to reduce jumps. This could be useful for try-catch blocks as well.
|
Before adding such feature, perhaps we should implement a system for managing basic blocks in JIT. This could go in a separate patch. The |
|
I think that feature needs big change for analysis and bytecode generation, so it should handled by another patch. There are some ways how to implement that feature, but I have no confidence what things should be like or how can be implemented onto this project. I think I need some feedback how can be basic block flow control be like. |
|
I also mentioned the separate patch. I think features like this should be built upon the basic block system, otherwise it will be hard to maintain these optimizations. Basic blocks are sub regions of the instruction list, so the concatenation of the basic blocks is the instruction list. Each basic block should end with a jump, which keeps the next instruction pointer even if the basic blocks are reorganized. Then the unnecessary jumps (=jump to the next instruction) must be removed after the basic blocks are reorganized. The basic blocks can be constructed and reorganized after the register allocation. However, the extra jumps should be inserted at the first phase. This might allow some optimizations of the liveness analysis, since a label is always preceded by a jump. The unnecessary jump removal should also include br_true/br_false followed by a jump cases, e.g. a br_true+jump -> br_false if possible. With this system basic blocks can be freely reorganized later. If you prefer I can work on this system, and you can add this work on the top of it later. Of course you can also do it if you are interested in. |
7eb2bd2 to
3c0ed03
Compare
|
This patch will be rebased when #494 is merged in main branch |
3c0ed03 to
3aaac9e
Compare
|
Now I'll rebase this. |
3aaac9e to
ad281e1
Compare
WASM proposes branch hinting uses metadata that can be mark a likely/unlikely in branch.
so this implements that proposal in JIT, so we can reduce half of branch execution in pref record.
ref: https://github.com/WebAssembly/spec/blob/main/proposals/branch-hinting/Overview.md