bytecodealliance / bytecodealliance/wasmtime
x64 load-op-store imm folding
- Dominant language
- Rust
- Stars
- 18.6k
- Forks
- 1.8k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 135
Description
Right now the given CLIF
```
v1 = load.i32 v0+32
v2 = iconst.i32 2
v3 = iadd v1, v2
store v3, v0+32
```
generates the following assembly
```
movl $2, %eax
addl %eax, 32(%rdi)
```
However, x64 allows the following encoding
```
addl $2, 32(%rdi)
```
I tried to fix that, by:
1. Change the `src2` of `AluRM` from `Gpr` to `GprMemImm`,
2. Add the corresponding encoding.
3. Change the `alu_rm` constructor to take `GprMemImm`
4. Change the `x64_add_mem`&co constructors to take `GprMemImm`.
This is a bit stupid since `AluRM` already takes a memory operand, so there is no way to encode the `Mem` part of `GprMemImm`. I guess maybe we could introduce `RegImm` and `GprImm` types. But that feels wrong and redundant.
Related issue where this first was brought up https://github.com/bytecodealliance/wasmtime/issues/1925
Contributor guide
Research direction
Start by reading the related issue 1925 and inspecting the named AluRM type, alu_rm constructor, and x64_add_mem constructors. Determine how an immediate source operand can be represented without duplicating memory handling. Done means the given load/add/store CLIF produces the immediate-memory add encoding on x64, with coverage for the new encoding.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100