binaryen icon indicating copy to clipboard operation
binaryen copied to clipboard

Simplify mutable globals with single write in "start"

Open MaxGraey opened this issue 1 year ago • 1 comments

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)
 )
)

MaxGraey avatar Aug 10 '22 14:08 MaxGraey

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.

MaxGraey avatar Aug 28 '22 04:08 MaxGraey