Skip to content

Use getMaxBits in comparisons #5010

Open

Description

@kripken

E.g.

(i32.lt_u
 (i32.ne
  (local.get $0)
  (i32.const 0)
 )
 (i32.const 128)
)
 =->
(i32.const 1)

i32.ne returns 0 or 1, so it is max 1 bit, and that is always less than 128.

Found by the superoptimizer #4994 (for comparison to other findings: rule #20, benefit 13760).

Activity

  1. assigned and unassigned on Sep 2, 2022
  2. MaxGraey commented on Sep 3, 2022

    @MaxGraey
    Contributor

    generalize to:

    u32(x)  < C      ->      1,    iff  maxBits(x) < maxBits(C)
    u32(x) <= C      ->      1,    iff  maxBits(x) < maxBits(C)
  3. kripken commented on Sep 8, 2022

    @kripken
    MemberAuthor

    Also

    x == C   =>   0   if maxBits(x) < bits(C)
    x != C   =>   1   if maxBits(x) < bits(C)
    

    (to be equal, the number of bits must be equal, so if that differs, the values must differ).

  4. MaxGraey commented on Sep 9, 2022

    @MaxGraey
    Contributor

    Special case:

    x == -1   =>   0   if maxBits(x) != bits(-1)
    
  5. kripken commented on Sep 13, 2022

    @kripken
    MemberAuthor

    This should be complete except for the last part in #5010 (comment) That pattern is basically where the right side is -1 (or more generally a mask of lower bits), so we know more than just the min/max bits.

  6. removed their assignment
    on Sep 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions