Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

[New Optimization Proposal] Propagate conditional result to branch / switch arms

Open
#4,161 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
cpp, wasm

Research direction

Start by examining Binaryen's existing optimization paths for branch and switch arms, including br_table handling. Compare their behavior with the conditional-result examples in the issue and determine the intended transformations. Done means the proposed propagation is implemented consistently for the shown if/else and br_table cases, with tests demonstrating the optimized results.

Written by the indexing model from the issue text.

Description

Example:

if (x == 5) {
   return x + 1;
} else {
   return x - 1;
}

if (y == true) { // maxBits(y) <= 1
   return y | x; // maxBits(x) <= 1
} else {
   return y ^ x;
}

if (z < 5) {
   return z >= 5;
}

could be optimize to:

if (x == 5) {
   return 6; // 5 + 1
} else {
   return x - 1;
}

if (y == true) {
   return true; // we know y == true, so true | bool(x)  ->  true
} else {
   return x; // here y always `false` so `false ^ x` -> x
}

if (z < 5) {
   return false;
}

and same for br tables.

WDYT?

Dominant language
WebAssembly
Stars
8.6k
Forks
885
Avg merge
2d 4h
Merged PRs (30d)
77

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.

More from WebAssembly/binaryen

All issues in WebAssembly/binaryen

Similar issues

More Compilers issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.