-
Notifications
You must be signed in to change notification settings - Fork 832
Precompute: Avoid caching heap values of partial precomputations #7766
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| ;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited. | ||
|
|
||
| ;; RUN: foreach %s %t wasm-opt --precompute-propagate --optimize-level=2 -all -S -o - | filecheck %s | ||
|
|
||
| (module | ||
| ;; CHECK: (type $empty (struct)) | ||
| (type $empty (struct)) | ||
|
|
||
| ;; CHECK: (type $i32_any (sub (struct (field i32) (field (ref any))))) | ||
| (type $i32_any (sub (struct (field i32) (field (ref any))))) | ||
|
|
||
| ;; CHECK: (func $partial-gc-cache (type $1) (result i32) | ||
| ;; CHECK-NEXT: (local $x i32) | ||
| ;; CHECK-NEXT: (drop | ||
| ;; CHECK-NEXT: (struct.new $i32_any | ||
| ;; CHECK-NEXT: (i32.const 0) | ||
| ;; CHECK-NEXT: (select (result (ref (exact $empty))) | ||
| ;; CHECK-NEXT: (struct.new_default $empty) | ||
| ;; CHECK-NEXT: (struct.new_default $empty) | ||
| ;; CHECK-NEXT: (i32.trunc_f64_s | ||
| ;; CHECK-NEXT: (f64.const 562949953421311) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (i32.const 0) | ||
| ;; CHECK-NEXT: ) | ||
| (func $partial-gc-cache (result i32) | ||
| (local $x i32) | ||
| ;; The select here looks promising for partial computation. We will therefore | ||
| ;; try to precompute variations of the outer struct.new. While doing so we | ||
| ;; should not confuse later computations, and in particular, not store | ||
| ;; anything in the heap value cache - the risk is that these partial | ||
| ;; precomputations will not have the i32.trunc which traps, so they will | ||
| ;; execute without trapping, and if we cached that result for the outer | ||
| ;; struct.new, we'd later think that results applies here (if we did, we'd | ||
| ;; think this does not trap, and precompute it into a nop, removing the | ||
| ;; trap erroneously). | ||
| (drop | ||
| (struct.new $i32_any | ||
| (i32.const 0) | ||
| (select (result (ref $empty)) | ||
| (struct.new $empty) | ||
| (struct.new $empty) | ||
| (i32.trunc_f64_s | ||
| (f64.const 562949953421311) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| ;; This local causes propagation to work, which causes the extra | ||
| ;; optimizations that lead to the bug above. | ||
| (local.get $x) | ||
| ) | ||
| ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Maybe we simplify things by moving this logic to the very top of the function:
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.
Done.