WebAssembly / WebAssembly/binaryen

[Feature] Evaluated case elimination pass

Open
#2,468 6 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

function test(x: i32) : i32 {
  switch (x) {
    case 1: return 2;
    case 2: return 2;
  }
  return 2;
}

current with -O4:

  (func $test (export "test") (type $t0) (param $p0 i32) (result i32)
    block $B0
      block $B1
        get_local $p0
        i32.const 1
        i32.ne
        if $I2
          get_local $p0
          i32.const 2
          i32.eq
          br_if $B1
          br $B0
        end
        i32.const 2
        return
      end
      i32.const 2
      return
    end
    i32.const 2)

optimal (with evaluated case elimination transform):

(func $test (export "test") (type $t0) (param $p0 i32) (result i32)
   i32.const 2
)

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

Reproduce the example with -O4 and compare the current WebAssembly output with the optimal output shown in the issue. Locate the existing optimizer passes that simplify switch or evaluated cases, then verify that this example reduces to a function returning i32.const 2.

Written by the indexing model from the issue text.

Assessment

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