WebAssembly / WebAssembly/binaryen

Remove masks that are shifted out later

Open
#5,011 1 comment 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.shl
 (i32.and
  (local.get $0)
  (i32.const 1073741823) ;; 0x3fffffff
 )
 (i32.const 2)
)
 =->
(i32.shl
 (local.get $0)
 (i32.const 2)
)

Only the top two bits are missing in the mask, and we shift left, so any effect the and had is removed.

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

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

Review the superoptimizer findings in WebAssembly/binaryen#4994, especially rule #23 and its reported benefit, then locate the optimizer pass that handles this shift-and-mask pattern. Done means the redundant mask is removed for the shown WAT case and the optimization preserves the expression's semantics.

Written by the indexing model from the issue text.

Assessment

Tech stack
wasm
Domain
compilers, performance
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.