bytecodealliance / bytecodealliance/wasmtime
Cranelift: develop demanded-bits and defined-bits analyses
- Dominant language
- Rust
- Stars
- 18.6k
- Forks
- 1.8k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 121
Description
In some cases, it is possible to perform better optimizations and instruction selection if one knows that only part of a value is needed (demanded bits). At other times, it is possible to do better if one knows that the operation or instruction actually generating a value sets more bits than are necessary in the destination register (defined-bits).
We should develop these analyses and use them during optimization and during lowering. Some examples:
- Bitmasks can be simplified or elided when demanded-bits allows: for example, `and x, 1` with only the LSB demanded is just `x`.
- An extend operator can be elided if the upper (extended-into) bits are not demanded.
- An extend operator can be elided if the upper bits are already actually defined by the chosen producer instruction(s).
The demanded-bits analysis should be at the CLIF level as it is a machine-independent concept (what bits do the CLIF semantics of the use(s) actually depend on). The defined-bits analysis is fundamentally a lowered-MachInst-level concept, as it has to do (in our case, since no bits within the type are undefined) with bits above a value in a register (e.g., upper 32 for an `I32` a 64-bit register).
Contributor guide
Assessment
This issue has not been assessed yet.