Improve selectify
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- cpp, wasm
- Domain
- compilers, testing-qa
Research direction
Start with the selectify logic near src/passes/RemoveUnusedBrs.cpp#L1077 and the existing cases in lit/remove-unused-brs.wast. Add the supplied early-return regression case and verify that the test expects the if without a false arm to be canonicalized so selectify can produce the shown select form.
Written by the indexing model from the issue text.
Description
I think I already mentioned a similar problem, but it was a long time ago.
If we have an "if" branch without a false arm, you selectify stops working:
function selectify_early_return(x: i32): i32 {
if (x) return x;
return 1;
}
Just add this test into lit/remove-unused-brs.wast as:
;; CHECK: (func $selectify-early-return (param $x i32) (result i32)
;; CHECK-NEXT: (if
;; CHECK-NEXT: (local.get $x)
;; CHECK-NEXT: (return
;; CHECK-NEXT: (local.get $x)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: (i32.const 1)
;; CHECK-NEXT: )
(func $selectify-early-return (param $x i32) (result i32)
(if
(local.get $x)
(return (local.get $x))
)
(i32.const 1)
)
But obversely we expect something like this insted:
(func $selectify-early-return (param $x i32) (result i32)
(select
(local.get $0)
(i32.const 1)
(local.get $0)
)
)
The main problem here: https://github.com/WebAssembly/binaryen/blob/main/src/passes/RemoveUnusedBrs.cpp#L1077
selectify just skip optimisation if ifFalse is not exists. So it is necessary to canonicalze such cases before applying selectify. Any idea how best to do this?
- Dominant language
- WebAssembly
- Stars
- 8.6k
- Forks
- 885
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 70
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.
More from WebAssembly/binaryen
-
Difficulty 2/5 Half a day Newbie friendliness 76/100
WebAssembly/binaryen#9018 · 3 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 52/100
WebAssembly/binaryen#9123 ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
WebAssembly/binaryen#9122 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
WebAssembly/binaryen#9086 · 2 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
WebAssembly/binaryen#9038 · 5 comments ·
All issues in WebAssembly/binaryen
Similar issues
-
todo:perf
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
objectionary/eo#8894 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
objectionary/phie#154 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
objectionary/jeo-maven-plugin#1774 ·
-
Minor breakage w/ LLVM 7: `test_llvm.cpp: error: cannot convert 'llvm::Module' to 'llvm::Module*'` Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100