WebAssembly / WebAssembly/binaryen

Optimize sign checks on i8, i16 etc.

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

(select
 (local.get $0)
 (local.get $1)
 (i32.lt_s
  (i32.extend8_s
   (local.get $2)
  )
  (i32.const 0)
 )
)
 =->
(select
 (local.get $0)
 (local.get $1)
 (i32.and
  (local.get $2)
  (i32.const 128)
 )
)

When in a boolean context, doing an extend and then <0 is the same as checking the sign bit of the size we are extending from.

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

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 WebAssembly example in the issue and compare it with the superoptimizer findings in WebAssembly/binaryen pull request 4994. Locate the optimizer entry point that handles sign checks on narrow integers, then add coverage for the shown transformation and verify that the optimized output preserves the boolean result.

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
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.