WebAssembly / WebAssembly/binaryen
Redundant global read
Open
Nobody has claimed this yet.
- Dominant language
- WebAssembly
- Stars
- 8.6k
- Forks
- 885
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 69
Description
In situations when global reads immediately after write we could avoid this read and use argument of global.set. For example this:
(module
(global $g (mut i32) (i32.const 0))
(func $test (param $0 i32) (result i32)
(global.set $g (local.get $0))
(global.get $g)
)
)
can be optimized as:
(module
(global $g (mut i32) (i32.const 0))
(func $test (param $0 i32) (result i32)
(global.set $g (local.get $0))
(local.get $0)
)
)
if arg is simple like local.get or i32.const
and something like this if arg more complex:
(module
(global $g (mut i32) (i32.const 0))
(func $test (param $0 i32) (result i32)
(global.set $g (local.tee $tmp (...complex expr...)))
(local.get $tmp)
)
)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating Binaryen's optimization pass that handles global.set and global.get, then inspect existing tests for global transformations. Add coverage for simple and complex values as shown in the issue, and consider the work done when the redundant read is removed while the examples retain their behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- wasm
- Domain
- compilers, performance
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100