bytecodealliance / bytecodealliance/wasmtime
Cranelift: improve codegen for booleans and icmp/br[n]z pairs
- Dominant language
- Rust
- Stars
- 18.6k
- Forks
- 1.8k
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 126
Description
The code generation for (i) branches on booleans, and (ii) branches on integer values that come from compares but are not directly observable (e.g. in a different basic block), is suboptimal. We often see:
- Masking, like `AND reg, 1`, because we pessimistically assume that the upper bits of a boolean value are undefined;
- `cmp`, `setcc` (x64) / `cset` (aarch64) into a register followed by a conditional branch sometime later;
- A combination of the above two.
The root causes are:
- We do not pattern-match far enough back, in some cases, to fuse the `brz` and `icmp` at the Cranelift level, and this is exacerbated by GVN and LICM that hoist icmps earlier in the function;
- We do not have combination patterns that recognize when some producers of bools-as-integers will actually define the high bits.
Some combination of more aggressive pattern matching and demanded-bits analysis could improve the codegen in these cases.
Contributor guide
Assessment
This issue has not been assessed yet.