WebAssembly / WebAssembly/binaryen
[New Optimization Proposal] Propagate conditional result to branch / switch arms
Open
Nobody has claimed this yet.
- Dominant language
- WebAssembly
- Stars
- 8.6k
- Forks
- 885
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 69
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?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
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.
Assessment
- Tech stack
- cpp, wasm
- Domain
- compilers, performance
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100