binaryen
binaryen copied to clipboard
Remove masks that are shifted out later
E.g.
(i32.shl
(i32.and
(local.get $0)
(i32.const 1073741823) ;; 0x3fffffff
)
(i32.const 2)
)
=->
(i32.shl
(local.get $0)
(i32.const 2)
)
Only the top two bits are missing in the mask, and we shift left, so any effect the and had is removed.
Found by the superoptimizer https://github.com/WebAssembly/binaryen/pull/4994 (for comparison to other findings: rule #23, benefit 12936).
A related example, rule #27
(i32.and
(i32.or
(local.get $0)
(i32.shl
(local.get $1)
(i32.const 16)
)
)
(i32.const 4)
)
=->
(i32.and
(local.get $0)
(i32.const 4)
)
$1 is shifted left so much that it can't contribute to the final and.