binaryen
binaryen copied to clipboard
Optimize checks for higher bits using a low bit mask
E.g.
(i32.ne
(i32.and
(local.get $0)
(i32.const 268435455) ;; 0x0fffffff
)
(local.get $0)
)
=->
(i32.ge_u
(local.get $0)
(i32.const 268435456)
)
(x & low-bit-mask) != x implies that x has some bit set that is larger than the bitmask, so we can just look for those bits.
Found by the superoptimizer https://github.com/WebAssembly/binaryen/pull/4994 (for comparison to other findings: rule #15, benefit 16737).
The same thing can be done with a high bit mask, e.g.
(i32.eqz
(i32.and
(local.get $0)
(i32.const -8) ;; 0xfffffff8
)
)
=->
(i32.lt_u
(local.get $0)
(i32.const 8)
)
(rule #16)