WebAssembly / WebAssembly/binaryen

Fold extend followed by operations that do not care about the extended bits

Open
#5,005 0 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.

(i64.eqz
 (i64.extend_i32_u
  (i64.eqz
   (local.get $0)
  )
 )
)
 =->
(i64.ne
 (local.get $0)
 (i64.const 0)
)

Comparing to zero is the same with or without extending: if was zero, it'll remain so, and if it wasn't zero, it still won't be zero.

Found by the superoptimizer https://github.com/WebAssembly/binaryen/pull/4994 (for comparison to other findings: rule #1, benefit 140074).

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 with the WAT transformation in this issue and compare it with the superoptimizer findings in Binaryen pull request #4994. Locate the optimizer rule and its regression tests for extending values before operations that do not depend on the extended bits. Done means the shown equivalent form is recognized and the relevant tests pass.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.