-
Notifications
You must be signed in to change notification settings - Fork 869
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
base: main
Are you sure you want to change the base?
Changes from all commits
38858ed
82da827
41346c2
85d8857
b0d1598
c065728
d7667f9
89992f2
f831abf
a10b3d4
18c69b4
6e6b532
75a1b26
b8f99e8
6f2dad1
d3104b6
96a21e0
2054302
a49415f
cca0d4e
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,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 | ||
| ;; 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 | ||
| ;; CHECK: (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)) | ||
|
|
||
| ;; CHECK: (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) | ||
| ) | ||
|
|
||
| ;; CHECK: (export "export" (func $export)) | ||
|
|
||
| ;; CHECK: (func $export (type $func) | ||
| ;; CHECK-NEXT: (call_indirect $table (type $func) | ||
| ;; CHECK-NEXT: (i32.const 0) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-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 | ||
| ;; CHECK: (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)) | ||
|
|
||
| ;; CHECK: (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) | ||
|
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. Nit: How about
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. 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? |
||
|
|
||
| ;; CHECK: (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) | ||
| ) | ||
|
|
||
| ;; CHECK: (export "export" (func $export)) | ||
|
|
||
| ;; CHECK: (func $export (type $func) | ||
| ;; CHECK-NEXT: (call_indirect $table (type $func) | ||
| ;; CHECK-NEXT: (i32.const 0) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-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) | ||
| ) | ||
| ) | ||
| ) | ||
|
|
||
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.
How about making this
CLOSED_WORLDto be contrasted withOPEN_WORLDbelow?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.
I renamed it OPEN_TRAPS to make it clear that it is open world + possible traps.
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.
Not terribly important, but what I meant was to rename
CHECKthat we would know what are the two things that are compared