binaryen icon indicating copy to clipboard operation
binaryen copied to clipboard

optimise LSBit mask (followed by branch) to use `ctz`

Open ggreif opened this issue 2 years ago • 0 comments

I have code snippets like

i32.const 1
i32.and
i32.eqz
br_if 1 (;@1;)

which could be optimised to

i32.ctz
br_if 1 (;@1;)

Similar analogous transformations:

  • i32.const 1; i32.and; i32.eqz; if to i32.ctz; if
  • i32.const 1; i32.and; if to i32.ctz; if (with legs swapped)
  • possibly 64-bit variants (but here probably instructions for truncation need to be added)
  • what about sightedness testing? (cmp against 0 --> clz)

ggreif avatar Jun 05 '23 13:06 ggreif