-
Notifications
You must be signed in to change notification settings - Fork 758
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
Add a pass to propagate global constants to other globals #6287
Changes from all commits
6197791
5bc03e1
ff3f4dd
eb9128a
3e5d344
2aee24b
b57cef4
5a37645
63ad656
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 |
---|---|---|
|
@@ -369,6 +369,9 @@ void PassRegistry::registerPasses() { | |
registerPass("print-stack-ir", | ||
"print out Stack IR (useful for internal debugging)", | ||
createPrintStackIRPass); | ||
registerPass("propagate-globals-globally", | ||
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. Should this use 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 is useful also for comparing stringref to imported strings. |
||
"propagate global values to other globals (useful for tests)", | ||
createPropagateGlobalsGloballyPass); | ||
registerPass("remove-non-js-ops", | ||
"removes operations incompatible with js", | ||
createRemoveNonJSOpsPass); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. | ||
|
||
;; RUN: foreach %s %t wasm-opt --propagate-globals-globally -all -S -o - | filecheck %s | ||
;; RUN: foreach %s %t wasm-opt --simplify-globals -all -S -o - | filecheck %s --check-prefix SIMGB | ||
|
||
;; Check that propagate-globals-globally propagates constants globally but not | ||
;; to code. Also run simplify-globals for comparison, which does do that. | ||
|
||
(module | ||
;; CHECK: (type $struct (struct (field stringref) (field stringref))) | ||
;; SIMGB: (type $struct (struct (field stringref) (field stringref))) | ||
(type $struct (struct stringref stringref)) | ||
|
||
;; CHECK: (type $1 (func)) | ||
|
||
;; CHECK: (global $A i32 (i32.const 42)) | ||
;; SIMGB: (type $1 (func)) | ||
|
||
;; SIMGB: (global $A i32 (i32.const 42)) | ||
(global $A i32 (i32.const 42)) | ||
|
||
;; CHECK: (global $B i32 (i32.const 42)) | ||
;; SIMGB: (global $B i32 (i32.const 42)) | ||
(global $B i32 (global.get $A)) | ||
|
||
;; CHECK: (global $C i32 (i32.add | ||
;; CHECK-NEXT: (i32.const 42) | ||
;; CHECK-NEXT: (i32.const 42) | ||
;; CHECK-NEXT: )) | ||
;; SIMGB: (global $C i32 (i32.add | ||
;; SIMGB-NEXT: (i32.const 42) | ||
;; SIMGB-NEXT: (i32.const 42) | ||
;; SIMGB-NEXT: )) | ||
(global $C i32 (i32.add | ||
;; Both of these can be optimized, including $B which reads from $A. | ||
(global.get $B) | ||
(global.get $A) | ||
)) | ||
|
||
;; CHECK: (global $D (ref string) (string.const "foo")) | ||
;; SIMGB: (global $D (ref string) (string.const "foo")) | ||
(global $D (ref string) (string.const "foo")) | ||
|
||
;; CHECK: (global $E (ref string) (string.const "bar")) | ||
;; SIMGB: (global $E (ref string) (string.const "bar")) | ||
(global $E (ref string) (string.const "bar")) | ||
|
||
;; CHECK: (global $G (ref $struct) (struct.new $struct | ||
;; CHECK-NEXT: (string.const "foo") | ||
;; CHECK-NEXT: (string.const "bar") | ||
;; CHECK-NEXT: )) | ||
;; SIMGB: (global $G (ref $struct) (struct.new $struct | ||
;; SIMGB-NEXT: (string.const "foo") | ||
;; SIMGB-NEXT: (string.const "bar") | ||
;; SIMGB-NEXT: )) | ||
(global $G (ref $struct) (struct.new $struct | ||
(global.get $D) | ||
(global.get $E) | ||
)) | ||
|
||
;; CHECK: (func $test (type $1) | ||
;; CHECK-NEXT: (drop | ||
;; CHECK-NEXT: (global.get $A) | ||
;; CHECK-NEXT: ) | ||
;; CHECK-NEXT: (drop | ||
;; CHECK-NEXT: (global.get $B) | ||
;; CHECK-NEXT: ) | ||
;; CHECK-NEXT: (drop | ||
;; CHECK-NEXT: (global.get $C) | ||
;; CHECK-NEXT: ) | ||
;; CHECK-NEXT: (drop | ||
;; CHECK-NEXT: (global.get $D) | ||
;; CHECK-NEXT: ) | ||
;; CHECK-NEXT: ) | ||
;; SIMGB: (func $test (type $1) | ||
;; SIMGB-NEXT: (drop | ||
;; SIMGB-NEXT: (i32.const 42) | ||
;; SIMGB-NEXT: ) | ||
;; SIMGB-NEXT: (drop | ||
;; SIMGB-NEXT: (i32.const 42) | ||
;; SIMGB-NEXT: ) | ||
;; SIMGB-NEXT: (drop | ||
;; SIMGB-NEXT: (global.get $C) | ||
;; SIMGB-NEXT: ) | ||
;; SIMGB-NEXT: (drop | ||
;; SIMGB-NEXT: (string.const "foo") | ||
;; SIMGB-NEXT: ) | ||
;; SIMGB-NEXT: ) | ||
(func $test | ||
;; We should not change anything here: this pass propagates globals | ||
;; *globally*, and not to functions. (but simplify-globals does, except for | ||
;; $C which is not constant) | ||
(drop | ||
(global.get $A) | ||
) | ||
(drop | ||
(global.get $B) | ||
) | ||
(drop | ||
(global.get $C) | ||
) | ||
(drop | ||
(global.get $D) | ||
) | ||
) | ||
) |
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.
This looks like a bug fix. Which test case does it affect?
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 not a bugfix, see the second paragraph above: This makes us slightly more efficient in SimplifyGlobals, but we always did it.
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.
Testcase: https://github.com/WebAssembly/binaryen/pull/6287/files#diff-b20b12708a3cf7de01646f83ed600c7dc546c88505309a98ecb19e1b3f9eda65R35