-
Notifications
You must be signed in to change notification settings - Fork 871
RemoveUnusedModuleElements: Handle null table segments #8884
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
+478
−5
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
38858ed
fix
kripken 82da827
fix
kripken 41346c2
add comment
kripken 85d8857
testcase showing a second issue [ci skip]
kripken b0d1598
wip
kripken c065728
update.tests
kripken d7667f9
comment
kripken 89992f2
comment
kripken f831abf
simpl
kripken a10b3d4
clean
kripken 18c69b4
test
kripken 6e6b532
tes
kripken 75a1b26
test
kripken b8f99e8
test
kripken 6f2dad1
typo
kripken d3104b6
test
kripken 96a21e0
test
kripken 2054302
fix lit test
kripken a49415f
Update src/passes/RemoveUnusedModuleElements.cpp
kripken cca0d4e
feedback: move comment
kripken c5e884d
rename
kripken 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
116 changes: 116 additions & 0 deletions
116
test/lit/passes/remove-unused-module-elements-closed-tnh.wast
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,116 @@ | ||
| ;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. | ||
|
|
||
| ;; Test the optimal path of closed-world and traps-never happen, compared to the | ||
| ;; default of open world with trapping. | ||
|
|
||
| ;; RUN: foreach %s %t wasm-opt --remove-unused-module-elements --closed-world -tnh -all -S -o - | filecheck %s --check-prefix CLOSED_TNH | ||
| ;; RUN: foreach %s %t wasm-opt --remove-unused-module-elements -all -S -o - | filecheck %s --check-prefix OPEN_TRAPS | ||
|
|
||
| ;; A table with a single elem with non-constant offset that we can remove. | ||
| ;; Usually a non-constant segment suggests it might overlap with others, which | ||
| ;; causes us to keep all elems, but here there is just one, so we can optimize. | ||
| ;; We require closed world (to know about which calls can reach it - the only | ||
| ;; call is to type $func, so elem $elem which contains $other is not needed). | ||
| ;; We also require traps-never-happen, as an elem with non-constant offset can | ||
| ;; trap, normally. When both closed world and tnh, we remove elem $elem. | ||
| (module | ||
| ;; CLOSED_TNH: (type $func (func)) | ||
| ;; OPEN_TRAPS: (type $func (func)) | ||
| (type $func (func)) | ||
|
|
||
| ;; OPEN_TRAPS: (type $other (func (result i32))) | ||
| (type $other (func (result i32))) | ||
|
|
||
| ;; OPEN_TRAPS: (import "a" "b" (global $offset i32)) | ||
| (import "a" "b" (global $offset i32)) | ||
|
|
||
| ;; CLOSED_TNH: (table $table 6 6 funcref) | ||
| ;; OPEN_TRAPS: (table $table 6 6 funcref) | ||
| (table $table 6 6 funcref) | ||
|
|
||
| ;; OPEN_TRAPS: (elem $elem (global.get $offset) $other) | ||
| (elem $elem (global.get $offset) $other) | ||
|
|
||
| ;; OPEN_TRAPS: (export "export" (func $export)) | ||
|
|
||
| ;; OPEN_TRAPS: (func $other (type $other) (result i32) | ||
| ;; OPEN_TRAPS-NEXT: (i32.const 42) | ||
| ;; OPEN_TRAPS-NEXT: ) | ||
| (func $other (type $other) (result i32) | ||
| (i32.const 42) | ||
| ) | ||
|
|
||
| ;; CLOSED_TNH: (export "export" (func $export)) | ||
|
|
||
| ;; CLOSED_TNH: (func $export (type $func) | ||
| ;; CLOSED_TNH-NEXT: (call_indirect $table (type $func) | ||
| ;; CLOSED_TNH-NEXT: (i32.const 0) | ||
| ;; CLOSED_TNH-NEXT: ) | ||
| ;; CLOSED_TNH-NEXT: ) | ||
| ;; OPEN_TRAPS: (func $export (type $func) | ||
| ;; OPEN_TRAPS-NEXT: (call_indirect $table (type $func) | ||
| ;; OPEN_TRAPS-NEXT: (i32.const 0) | ||
| ;; OPEN_TRAPS-NEXT: ) | ||
| ;; OPEN_TRAPS-NEXT: ) | ||
| (func $export (export "export") | ||
| ;; Call with type $func, but the table contains $other. | ||
| (call_indirect $table (type $func) | ||
| (i32.const 0) | ||
| ) | ||
| ) | ||
| ) | ||
|
|
||
| ;; As above, but now we have two segments, one constant. We don't know if they | ||
| ;; overlap, so we normally assume the worst. However, with tnh, we can assume no | ||
| ;; traps, and remove elem $elem. (We cannot remove elem $second in either case, | ||
| ;; as it contains a function we have an indirect call for its type.) | ||
| (module | ||
| ;; CLOSED_TNH: (type $func (func)) | ||
| ;; OPEN_TRAPS: (type $func (func)) | ||
| (type $func (func)) | ||
|
|
||
| ;; OPEN_TRAPS: (type $other (func (result i32))) | ||
| (type $other (func (result i32))) | ||
|
|
||
| ;; OPEN_TRAPS: (import "a" "b" (global $offset i32)) | ||
| (import "a" "b" (global $offset i32)) | ||
|
|
||
| ;; CLOSED_TNH: (table $table 6 6 funcref) | ||
| ;; OPEN_TRAPS: (table $table 6 6 funcref) | ||
| (table $table 6 6 funcref) | ||
|
|
||
| ;; OPEN_TRAPS: (elem $elem (global.get $offset) $other) | ||
| (elem $elem (global.get $offset) $other) | ||
|
|
||
| ;; CLOSED_TNH: (elem $second (i32.const 0) $export) | ||
| ;; OPEN_TRAPS: (elem $second (i32.const 0) $export) | ||
| (elem $second (i32.const 0) $export) | ||
|
|
||
| ;; OPEN_TRAPS: (export "export" (func $export)) | ||
|
|
||
| ;; OPEN_TRAPS: (func $other (type $other) (result i32) | ||
| ;; OPEN_TRAPS-NEXT: (i32.const 42) | ||
| ;; OPEN_TRAPS-NEXT: ) | ||
| (func $other (type $other) (result i32) | ||
| (i32.const 42) | ||
| ) | ||
|
|
||
| ;; CLOSED_TNH: (export "export" (func $export)) | ||
|
|
||
| ;; CLOSED_TNH: (func $export (type $func) | ||
| ;; CLOSED_TNH-NEXT: (call_indirect $table (type $func) | ||
| ;; CLOSED_TNH-NEXT: (i32.const 0) | ||
| ;; CLOSED_TNH-NEXT: ) | ||
| ;; CLOSED_TNH-NEXT: ) | ||
| ;; OPEN_TRAPS: (func $export (type $func) | ||
| ;; OPEN_TRAPS-NEXT: (call_indirect $table (type $func) | ||
| ;; OPEN_TRAPS-NEXT: (i32.const 0) | ||
| ;; OPEN_TRAPS-NEXT: ) | ||
| ;; OPEN_TRAPS-NEXT: ) | ||
| (func $export (export "export") | ||
| (call_indirect $table (type $func) | ||
| (i32.const 0) | ||
| ) | ||
| ) | ||
| ) | ||
|
|
||
Oops, something went wrong.
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.
Nit: How about
elem $firstbecause the next elem is$second?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.
Hmm, but the first test has only one, so calling it "first" there would be confusing I think - and I want to keep the name the same in the two tests, to make it clear what is unchanged between them?