WebAssembly / WebAssembly/binaryen

Merge two if-blocks into one if conditions the same

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

example:

export function test(cond: i32): void {
  if (cond) g(1);
  // could be some "side effect"-free (movable) code
  if (cond) g(2);
}

actual output:

(func $test (param $0 i32)
  local.get $0
  if
   i32.const 1
   call $g
  end
  local.get $0
  if
   i32.const 2
   call $g
  end
 )

expected output:

(func $test (param $0 i32)
  local.get $0
  if
   i32.const 1
   call $g
   i32.const 2
   call $g
  end
 )

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 TypeScript example and compare its current and expected WAT output. Trace the optimizer's handling of adjacent if-blocks with identical conditions, checking that intervening movable code remains valid. Done means the two blocks are combined without changing observable behavior.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.