WebAssembly / WebAssembly/binaryen

[Proposal] Add getMaxSignBits for tracking sign values

Open
#4,329 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

With existing getMaxBits we could provide wide range of optimizations but getMaxBits completely blind for signed operations and values. This leaves a lot of places that could be relatively easily optimised. For example:

i32(x) - i32(y) < 0   ->   x < y

If we know x - y never overflow (it required getMaxSignBits for signed comparison). Or more expressive example:

i32(x) * 400 / 100  ->  x * 4

if we know getMaxSignBits(x) >= 9.

For example:

(i32(x) >> 9) * 400 / 100   ->   (x >> 9) << 2

In general, getMaxSignBits is the building block for helpers that calculate the signed overflow for +, - and *

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 locating the existing getMaxBits implementation and the optimizer paths for signed comparisons and arithmetic. Determine the intended getMaxSignBits behavior from the examples, then define the helper and its overflow-analysis uses; done means the proposed signed optimizations are supported without incorrect transformations.

Written by the indexing model from the issue text.

Assessment

Tech stack
wasm
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.