Skip to content

optimise LSBit mask (followed by branch) to use ctz #5752

@ggreif

Description

@ggreif

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)
  • i32.const 2_147_483_648; i32.and; if to i32.clz; if (with legs swapped)
  • i32.const 31; i32.shr_u; if to i32.clz; if (with legs swapped)
  • possibly 64-bit variants (but here probably instructions for truncation need to be added)
  • what about signedness testing? (cmp against 0 --> clz)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions