WebAssembly / WebAssembly/binaryen

Use getMaxBits in comparisons

Open
#5,010 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
WebAssembly
Stars
8.6k
Forks
885
Avg merge
1d 19h
Merged PRs (30d)
69

Description

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 https://github.com/WebAssembly/binaryen/pull/4994 (for comparison to other findings: rule #20, benefit 13760).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the comparison optimization logic around getMaxBits and review the superoptimizer finding in pull request #4994, especially rule #20. Use the provided i32 example as a regression case; done means the comparison is recognized as always true and the result is reduced to i32.const 1.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, wasm
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.