Invalid optimization to select with --ignore-implicit-traps
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 38/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- wasm
- Domain
- compilers
Research direction
Reproduce the issue with the provided WAT module and -all -O1 --ignore-implicit-traps, then inspect the optimization that turns the conditional struct.get into a select. Done means the optimizer no longer makes potentially trapping code execute unconditionally, while preserving the valid optimized behavior.
Written by the indexing model from the issue text.
Description
Optimizing this program with -all -O1 --ignore-implicit-traps:
(module
(type $box (struct (field (mut i32)) (field (mut i64))))
(export "f" (func $f))
(func $f (param $0 (ref null $box)) (result i64)
(block $label$1
(block $label$2
(br_if $label$2
(ref.is_null
(local.get $0)
)
)
(br_if $label$1
(i64.gt_s
(struct.get $box 1
(local.get $0)
)
(i64.const 8)
)
)
)
(return
(i64.const 8)
)
)
(struct.get $box 1
(local.get $0)
)
)
)
yields
(module
(type $box (struct (field (mut i32)) (field (mut i64))))
(type $ref?|$box|_=>_i64 (func (param (ref null $box)) (result i64)))
(export "f" (func $f))
(func $f (param $0 (ref null $box)) (result i64)
(if
(select
(ref.is_null
(local.get $0)
)
(i32.const 1)
(i64.gt_s
(struct.get $box 1
(local.get $0)
)
(i64.const 8)
)
)
(return
(i64.const 8)
)
)
(struct.get $box 1
(local.get $0)
)
)
)
Even when assuming that no traps are executed, it is invalid in general to change potentially trapping code from being conditionally executed to being unconditionally executed. This happens with the first struct.get here, as it is placed as the second arm of the select.
- Dominant language
- WebAssembly
- Stars
- 8.6k
- Forks
- 885
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 77
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 1/5 Under an hour Newbie friendliness 88/100
WebAssembly/binaryen#9135 · 1 comment ·
-
Difficulty 2/5 Half a day Newbie friendliness 76/100
WebAssembly/binaryen#9018 · 3 comments ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
WebAssembly/binaryen#9133 ·
-
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 ·
All issues in WebAssembly/binaryen
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
internal.h中,漏掉了1个定义。 Open
Difficulty 1/5 Under an hour Newbie friendliness 95/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
oxc-project/oxc#26944 ·