WebAssembly / WebAssembly/binaryen

Avoid wrapping when 64-bit operations are enough

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

(i32.eq
 (i32.and
  (i32.wrap_i64
   (local.get $0)
  )
  (i32.const 255)
 )
 (i32.const 4)
)
 =->
(i64.eq
 (i64.and
  (local.get $0)
  (i64.const 255)
 )
 (i64.const 4)
)

All the operations work fine on 32 or 64 bit. The local input happens to be 64, so we can keep it that way until the final operations which always returns i32 anyhow.

Are there CPUs where 64-bit operations are slower than 32?

Sort of the complement to #5004 (use i64 rather than i32).

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

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 reviewing the transformation shown in the issue and the related superoptimizer pull request #4994, especially rule #5 and its reported benefit. Compare it with the complementary change in issue #5004, then determine how to recognize this 64-bit-preserving form and verify that the final result remains i32.

Written by the indexing model from the issue text.

Assessment

Tech stack
wasm
Domain
compilers, performance
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 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.