WebAssembly / WebAssembly/binaryen
CSE doesn't work for subexpressions with implicit trap
Open
Nobody has claimed this yet.
- Dominant language
- WebAssembly
- Stars
- 8.6k
- Forks
- 885
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 69
Description
I have very simple example:
(func $test (export "test") (type $t0) (param $p0 i32) (param $p1 i32) (result i32)
local.get $p0
local.get $p1
i32.rem_u
i32.eqz
local.get $p0
local.get $p1
i32.rem_u
i32.const 1
i32.eq
i32.or)
and expect this:
(func $test (export "test") (type $t0) (param $p0 i32) (param $p1 i32) (result i32)
local.get $p0
local.get $p1
i32.rem_u
local.tee $p0
i32.eqz
local.get $p0
i32.const 1
i32.eq
i32.or)
But unfortunately CSE didn't apply. Thoughts?
Upd: It seems this happened due to side effect. Because x % 10 properly eliminated
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
No source file or test is named. Start by reproducing the WAT example and comparing CSE behavior for i32.rem_u with the reported x % 10 case, then trace the CSE handling of subexpressions with implicit traps. Done means the example has a defined, tested outcome consistent with the intended optimization behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- wasm
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100