-
Notifications
You must be signed in to change notification settings - Fork 832
Handle return calls in CodeFolding #6474
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 |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ | |
| ;; CHECK: (tag $e-i32 (param i32)) | ||
| (tag $e-i32 (param i32)) | ||
|
|
||
| ;; CHECK: (func $pop-test (type $0) | ||
| ;; CHECK: (func $pop-test (type $1) | ||
| ;; CHECK-NEXT: (block $folding-inner0 | ||
| ;; CHECK-NEXT: (try | ||
| ;; CHECK-NEXT: (do | ||
|
|
@@ -67,12 +67,55 @@ | |
| ) | ||
| ) | ||
|
|
||
| ;; CHECK: (func $foo (type $0) | ||
| ;; CHECK: (func $try-call-optimize-terminating-tails-success (type $0) (result i32) | ||
| ;; CHECK-NEXT: (block $folding-inner0 | ||
| ;; CHECK-NEXT: (return | ||
| ;; CHECK-NEXT: (block (result i32) | ||
| ;; CHECK-NEXT: (try | ||
| ;; CHECK-NEXT: (do | ||
| ;; CHECK-NEXT: (br $folding-inner0) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (catch_all | ||
| ;; CHECK-NEXT: (br $folding-inner0) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (i32.const 0) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (drop | ||
| ;; CHECK-NEXT: (i32.const 1) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (drop | ||
| ;; CHECK-NEXT: (i32.const 1) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (return | ||
| ;; CHECK-NEXT: (i32.const 0) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| (func $try-call-optimize-terminating-tails-success (result i32) | ||
| (try | ||
| (do | ||
| (drop (i32.const 1)) | ||
| (drop (i32.const 1)) | ||
| (return (i32.const 0)) | ||
| ) | ||
| (catch_all | ||
| (drop (i32.const 1)) | ||
| (drop (i32.const 1)) | ||
| (return (i32.const 0)) | ||
| ) | ||
| ) | ||
| (i32.const 0) | ||
| ) | ||
|
|
||
|
|
||
| ;; CHECK: (func $foo (type $1) | ||
| ;; CHECK-NEXT: (nop) | ||
| ;; CHECK-NEXT: ) | ||
| (func $foo) | ||
|
|
||
| ;; CHECK: (func $try-call-optimize-terminating-tails (type $1) (result i32) | ||
| ;; CHECK: (func $try-call-optimize-terminating-tails (type $0) (result i32) | ||
| ;; CHECK-NEXT: (try | ||
| ;; CHECK-NEXT: (do | ||
| ;; CHECK-NEXT: (call $foo) | ||
|
|
@@ -116,7 +159,145 @@ | |
| (i32.const 0) | ||
| ) | ||
|
|
||
| ;; CHECK: (func $try-call-optimize-expression-tails (type $0) | ||
| ;; CHECK: (func $foo-i32 (type $0) (result i32) | ||
| ;; CHECK-NEXT: (i32.const 0) | ||
| ;; CHECK-NEXT: ) | ||
| (func $foo-i32 (result i32) | ||
| (i32.const 0) | ||
| ) | ||
|
|
||
| ;; CHECK: (func $try-call-optimize-terminating-tails-call-return (type $0) (result i32) | ||
| ;; CHECK-NEXT: (try | ||
| ;; CHECK-NEXT: (do | ||
| ;; CHECK-NEXT: (drop | ||
| ;; CHECK-NEXT: (i32.const 1) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (drop | ||
| ;; CHECK-NEXT: (i32.const 1) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (return | ||
| ;; CHECK-NEXT: (call $foo-i32) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (catch_all | ||
| ;; CHECK-NEXT: (drop | ||
| ;; CHECK-NEXT: (i32.const 1) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (drop | ||
| ;; CHECK-NEXT: (i32.const 1) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (return | ||
| ;; CHECK-NEXT: (call $foo-i32) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (i32.const 0) | ||
| ;; CHECK-NEXT: ) | ||
| (func $try-call-optimize-terminating-tails-call-return (result i32) | ||
| (try | ||
| (do | ||
| (drop (i32.const 1)) | ||
| (drop (i32.const 1)) | ||
| ;; Cannot be folded out of the try because it might throw. | ||
| (return (call $foo-i32)) | ||
| ) | ||
| (catch_all | ||
| (drop (i32.const 1)) | ||
| (drop (i32.const 1)) | ||
| (return (call $foo-i32)) | ||
| ) | ||
| ) | ||
| (i32.const 0) | ||
| ) | ||
|
|
||
| ;; CHECK: (func $try-call-optimize-terminating-tails-return-call (type $0) (result i32) | ||
| ;; CHECK-NEXT: (block $folding-inner0 | ||
| ;; CHECK-NEXT: (return | ||
| ;; CHECK-NEXT: (block (result i32) | ||
| ;; CHECK-NEXT: (try | ||
| ;; CHECK-NEXT: (do | ||
| ;; CHECK-NEXT: (br $folding-inner0) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (catch_all | ||
| ;; CHECK-NEXT: (br $folding-inner0) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (i32.const 0) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (drop | ||
| ;; CHECK-NEXT: (i32.const 1) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (drop | ||
| ;; CHECK-NEXT: (i32.const 1) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (drop | ||
| ;; CHECK-NEXT: (i32.const 1) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (return_call $foo-i32) | ||
| ;; CHECK-NEXT: ) | ||
| (func $try-call-optimize-terminating-tails-return-call (result i32) | ||
| (try | ||
| (do | ||
| (drop (i32.const 1)) | ||
| (drop (i32.const 1)) | ||
| (drop (i32.const 1)) | ||
| (return_call $foo-i32) | ||
| ) | ||
| (catch_all | ||
| (drop (i32.const 1)) | ||
| (drop (i32.const 1)) | ||
| (drop (i32.const 1)) | ||
| (return_call $foo-i32) | ||
| ) | ||
| ) | ||
| (i32.const 0) | ||
| ) | ||
|
|
||
| ;; CHECK: (func $try-call-optimize-expression-tails-success (type $1) | ||
| ;; CHECK-NEXT: (block $x | ||
| ;; CHECK-NEXT: (try | ||
| ;; CHECK-NEXT: (do | ||
| ;; CHECK-NEXT: (br $x) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (catch_all | ||
| ;; CHECK-NEXT: (br $x) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (unreachable) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (drop | ||
| ;; CHECK-NEXT: (i32.const 1) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (drop | ||
| ;; CHECK-NEXT: (i32.const 1) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (drop | ||
| ;; CHECK-NEXT: (i32.const 1) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| (func $try-call-optimize-expression-tails-success | ||
| (block $x | ||
| (try | ||
| (do | ||
| (drop (i32.const 1)) | ||
| (drop (i32.const 1)) | ||
| (drop (i32.const 1)) | ||
| (br $x) | ||
| ) | ||
| (catch_all | ||
| (drop (i32.const 1)) | ||
| (drop (i32.const 1)) | ||
| (drop (i32.const 1)) | ||
| (br $x) | ||
| ) | ||
| ) | ||
| (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. did we not have a test for this before?
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. No, not that I was able to find for either of these tests. Except for the throws effect analysis, the implementation does not seem to special case try-catch at all, so it's reasonable that we wouldn't need tests for the success cases. But when I was trying to debug and figure out how to get this change working, it was useful to prove to myself locally that similar cases did already work correctly. |
||
|
|
||
| ;; CHECK: (func $try-call-optimize-expression-tails (type $1) | ||
| ;; CHECK-NEXT: (block $x | ||
| ;; CHECK-NEXT: (try | ||
| ;; CHECK-NEXT: (do | ||
|
|
@@ -156,7 +337,7 @@ | |
| ) | ||
| ) | ||
|
|
||
| ;; CHECK: (func $if-arms-in-catch (type $1) (result i32) | ||
| ;; CHECK: (func $if-arms-in-catch (type $0) (result i32) | ||
| ;; CHECK-NEXT: (local $0 i32) | ||
| ;; CHECK-NEXT: (try | ||
| ;; CHECK-NEXT: (do | ||
|
|
||
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.
same question.