-
Notifications
You must be signed in to change notification settings - Fork 838
RemoveUnusedBrs: Make branches to traps just trap themselves #8398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| ;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited. | ||
| ;; RUN: wasm-opt %s --remove-unused-brs -all -S -o - | filecheck %s | ||
|
|
||
| (module | ||
| ;; CHECK: (import "a" "b" (func $import (type $0))) | ||
| (import "a" "b" (func $import)) | ||
|
|
||
| ;; CHECK: (func $jump-to-trap (type $1) (param $x i32) (result i32) | ||
| ;; CHECK-NEXT: (block $trap | ||
| ;; CHECK-NEXT: (call $import) | ||
| ;; CHECK-NEXT: (br_if $trap | ||
| ;; CHECK-NEXT: (local.get $x) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (call $import) | ||
| ;; CHECK-NEXT: (if | ||
| ;; CHECK-NEXT: (local.get $x) | ||
| ;; CHECK-NEXT: (then | ||
| ;; CHECK-NEXT: (call $import) | ||
| ;; CHECK-NEXT: (return | ||
| ;; CHECK-NEXT: (i32.const 0) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (else | ||
| ;; CHECK-NEXT: (call $import) | ||
| ;; CHECK-NEXT: (call $import) | ||
| ;; CHECK-NEXT: (unreachable) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (return | ||
| ;; CHECK-NEXT: (i32.const 1) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (unreachable) | ||
| ;; CHECK-NEXT: ) | ||
| (func $jump-to-trap (param $x i32) (result i32) | ||
| (block $trap | ||
| (call $import) ;; add effects to avoid other opts | ||
| ;; This might go to the trap outside, but might not, so we do nothing. | ||
| (br_if $trap | ||
| (local.get $x) | ||
| ) | ||
| (call $import) | ||
| (if | ||
| (local.get $x) | ||
| (then | ||
| (call $import) | ||
| (return (i32.const 0)) | ||
| ) | ||
| (else | ||
| (call $import) | ||
| (call $import) | ||
| ;; This goes to a trap, and we can just turn it into a trap. | ||
| (br $trap) | ||
| ) | ||
| ) | ||
| (return (i32.const 1)) | ||
| ) | ||
| (unreachable) | ||
| ) | ||
|
|
||
| ;; CHECK: (func $dispatch (type $2) (param $x i32) | ||
| ;; CHECK-NEXT: (block $trap | ||
| ;; CHECK-NEXT: (block $mid | ||
| ;; CHECK-NEXT: (block $top | ||
| ;; CHECK-NEXT: (br_table $top $mid $trap | ||
| ;; CHECK-NEXT: (local.get $x) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (call $import) | ||
| ;; CHECK-NEXT: (unreachable) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (call $import) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (unreachable) | ||
| ;; CHECK-NEXT: ) | ||
| (func $dispatch (export "a") (param $x i32) | ||
| ;; A realistic example with br_table (which also avoids other opts from | ||
| ;; getting in the way). | ||
| (block $trap | ||
| (block $mid | ||
| (block $top | ||
| (br_table $top $mid $trap (local.get $x)) | ||
| ) | ||
| (call $import) ;; add effects to avoid other opts | ||
| ;; This goes to a trap, and we can just turn it into a trap. | ||
| (br $trap) | ||
| ) | ||
| (call $import) | ||
| ) | ||
| (unreachable) | ||
| ) | ||
| ) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be nice to port this to lit! Then I would be able to see what test input corresponds to the changed output.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can port this test after, or do you want it first?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After is fine. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2396,7 +2396,7 @@ | |
| (unreachable) | ||
| ) | ||
| (then | ||
| (br $label$3) | ||
| (unreachable) | ||
| ) | ||
| ) | ||
| ) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the purpose of having two calls here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's nice to help differentiate the if arms. could also have been a call param.