bytecodealliance / bytecodealliance/wasmtime

Cranelift: develop demanded-bits and defined-bits analyses

Open
#4,133 2 comments 1 reaction 0 assignees View on GitHub
cranelift enhancement
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.