Wasm-opt not deduplicating repeated struct.gets on unchanged local
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 38/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- wasm
- Domain
- compilers
Research direction
Start with wasm-opt and reproduce the repeated local.get/struct.get pattern from the issue. Trace the optimizer behavior for unchanged locals and determine where repeated struct.gets could be recognized. Done means the pattern is deduplicated while preserving the shown control flow, with code-size or performance impact checked.
Written by the indexing model from the issue text.
Description
Consider the larger wasm snippet below. There are multiple instances of the same group of instructions:
local.get $var0
struct.get $#Top $field0
$var0 doesn't change between these struct.gets. I would expect wasm-opt to be able to identify this, do the lookup once and store it in a local prior to entering the block. This would save both code size and performance. We have some functions with hundreds of these patterns so the code size savings from this could be significant.
...
block $label1
block $label0 (result (ref $#Top))
local.get $var0
br_on_non_null $label0
local.get $var0
global.get $C6307 SymbolConstant(#[]=)
local.get $var4
call $_typeArgumentsToList
local.get $var3
call $_positionalParametersToList
local.get $var10
call $_namedParametersToMap
call $_Invocation.method
call $NoSuchMethodError._throwWithInvocation
unreachable
end $label0
local.tee $var0
struct.get $#Top $field0
i32.const 15
i32.eq
br_if $label1
local.get $var0
struct.get $#Top $field0
i32.const 16
i32.eq
if
local.get $var0
ref.as_non_null
local.get $var4
local.get $var3
global.get $C5979 WasmArray<Object>[0]
call $__ConstMap&_HashFieldBase&MapMixin&_HashBase&_OperatorEqualsAndHashCode&_LinkedHashMapMixin&_MapCreateIndexMixin&_UnmodifiableMapMixin.[]= invocation type checker
drop
return
end
local.get $var0
struct.get $#Top $field0
i32.const 17
i32.eq
br_if $label1
local.get $var0
struct.get $#Top $field0
i32.const 18
i32.eq
if
local.get $var0
ref.as_non_null
local.get $var4
local.get $var3
global.get $C5979 WasmArray<Object>[0]
i32.const 0
call_indirect (param (ref $#Top) (ref $Array<_Type>) (ref $Array<Object?>) (ref $Array<Object?>)) (result (ref null $#Top)) $&
drop
return
end
local.get $var0
struct.get $#Top $field0
i32.const 51
i32.eq
if
local.get $var0
ref.as_non_null
local.get $var4
local.get $var3
global.get $C5979 WasmArray<Object>[0]
call $CrossappCacheStorage.[]= invocation type checker
drop
return
end
...
- Dominant language
- WebAssembly
- Stars
- 8.6k
- Forks
- 885
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 64
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.
More from WebAssembly/binaryen
-
Difficulty 2/5 Half a day Newbie friendliness 76/100
WebAssembly/binaryen#9018 · 3 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 52/100
WebAssembly/binaryen#9123 ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
WebAssembly/binaryen#9122 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
WebAssembly/binaryen#9086 · 2 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
WebAssembly/binaryen#9038 · 5 comments ·
All issues in WebAssembly/binaryen
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
objectionary/eo#8869 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
EricSpencer00/Resilient#4824 · 1 comment ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
objectionary/jeo-maven-plugin#1758 ·
-
generics
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
mlir
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
llvm/llvm-project#224908 · 1 comment ·