binaryen
binaryen copied to clipboard
Simplify mutable globals with single write in "start"
It looks like simplify global pass doesn't take into account v128 types. For example:
(module
(global $g (mut v128) (v128.const i32x4 0x00000000 0x00000000 0x00000000 0x00000000))
(start $~start)
(func (export "getG") $getG (result v128)
(global.get $g)
)
(func $~start
(global.set $g
(v128.const i32x4 0x00000003 0x00000003 0x00000003 0x00000003)
)
)
)
Cannot be optimized to:
(module
(global $g (mut v128) (v128.const i32x4 0x00000003 0x00000003 0x00000003 0x00000003))
(func (export "getG") $getG (result v128)
(global.get $g)
)
)
I figured out it's basically a usual issue for all mutable globals. Optimized such mutable globals quite useful due to may give further improvements like remove "mut" from global if it has only single global.set
in start
and the rest are global.get
. After that just propagate this global as constant.