bytecodealliance / bytecodealliance/wasmtime

Cranelift: reuse compare results (flags) when possible

Open
#4,124 3 comments 0 reactions 0 assignees View on GitHub
cranelift cranelift:area:aarch64 cranelift:area:x64 enhancement
Dominant language
Rust
Stars
18.6k
Forks
1.8k
Avg merge
1d 18h
Merged PRs (30d)
126

Description

Currently, in both the x64 and aarch64 backends, we generate flags "locally" whenever needed. So, for example, the sequence

```
v0 = icmp ...
v1 = select v0, ...
brnz v0, blockN
jmp blockM
```

would generate the compare for `v0` twice.

This is generally a simplification over the old `iflags` approach, which we prefer for some of the reasons described in #3249. In particular, `iflags`-typed values are "weird" (cannot be stored or loaded, only one can be live at a time, cannot be directly observed) and these restrictions complicate other analyses/transforms. The tradeoff of effectively regenerating them on each use has been reasonable so far.

However, locally in cases where we do use the results of a compare more than once, we should be able to share a single compare operation. We might be able to reason about this by building a forward pass that tracks the last generated flags and using this information from within the backend's pattern-matching. For extra credit, we might be able to factor this information into the "unique use" framework, allowing a compare with multiple uses but only one codegen'd occurrence to merge load operations directly on x64.

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.