binaryen
binaryen copied to clipboard
Avoid extend/wrap to 64 bits when 32 are enough
E.g.
(i32.wrap_i64
(i64.add
(i64.extend_i32_u
(local.get $0)
)
(i64.const 8)
)
)
=->
(i32.add
(local.get $0)
(i32.const 8)
)
This is an example of a more general rule: we could avoid extending and wrapping if the work in the middle will not matter after the wrapping.
Found by the superoptimizer #4994 (for comparison to other findings: rule #0, benefit 1560922).
Another example (rule #6):
(i32.wrap_i64
(i64.mul
(i64.extend_i32_u
(local.get $0)
)
(i64.const 48)
)
)
=->
(i32.mul
(local.get $0)
(i32.const 48)
)