diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/lit/help/wasm-opt.test | 2 | ||||
-rw-r--r-- | test/lit/help/wasm2js.test | 2 | ||||
-rw-r--r-- | test/lit/passes/simplify-globals-strings.wast | 65 | ||||
-rw-r--r-- | test/lit/passes/string-gathering.wast | 96 |
4 files changed, 100 insertions, 65 deletions
diff --git a/test/lit/help/wasm-opt.test b/test/lit/help/wasm-opt.test index fc33fce8d..8732f5e27 100644 --- a/test/lit/help/wasm-opt.test +++ b/test/lit/help/wasm-opt.test @@ -467,6 +467,8 @@ ;; CHECK-NEXT: --stack-check enforce limits on llvm's ;; CHECK-NEXT: __stack_pointer global ;; CHECK-NEXT: +;; CHECK-NEXT: --string-gathering gathers wasm strings to globals +;; CHECK-NEXT: ;; CHECK-NEXT: --strip deprecated; same as strip-debug ;; CHECK-NEXT: ;; CHECK-NEXT: --strip-debug strip debug info (including the diff --git a/test/lit/help/wasm2js.test b/test/lit/help/wasm2js.test index 7db564101..40d608857 100644 --- a/test/lit/help/wasm2js.test +++ b/test/lit/help/wasm2js.test @@ -426,6 +426,8 @@ ;; CHECK-NEXT: --stack-check enforce limits on llvm's ;; CHECK-NEXT: __stack_pointer global ;; CHECK-NEXT: +;; CHECK-NEXT: --string-gathering gathers wasm strings to globals +;; CHECK-NEXT: ;; CHECK-NEXT: --strip deprecated; same as strip-debug ;; CHECK-NEXT: ;; CHECK-NEXT: --strip-debug strip debug info (including the diff --git a/test/lit/passes/simplify-globals-strings.wast b/test/lit/passes/simplify-globals-strings.wast deleted file mode 100644 index 813e2964c..000000000 --- a/test/lit/passes/simplify-globals-strings.wast +++ /dev/null @@ -1,65 +0,0 @@ -;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. -;; NOTE: This test was ported using port_passes_tests_to_lit.py and could be cleaned up. - -;; We do not "inline" strings from globals, as that might cause more -;; allocations to happen. TODO if VMs optimize that, remove this - -;; RUN: foreach %s %t wasm-opt --simplify-globals -all -S -o - | filecheck %s - -;; Also test with -O3 --gufa to see that no other pass does this kind of thing, -;; as extra coverage. - -;; RUN: foreach %s %t wasm-opt -O3 --gufa -all -S -o - | filecheck %s --check-prefix=O3GUF - -(module - ;; CHECK: (type $0 (func (result anyref))) - - ;; CHECK: (global $string stringref (string.const "one")) - ;; O3GUF: (type $0 (func (result anyref))) - - ;; O3GUF: (global $string (ref string) (string.const "one")) - (global $string stringref (string.const "one")) - - ;; CHECK: (global $string-mut (mut stringref) (string.const "two")) - ;; O3GUF: (global $string-mut (mut (ref string)) (string.const "two")) - (global $string-mut (mut stringref) (string.const "two")) - - ;; CHECK: (export "global" (func $global)) - ;; O3GUF: (export "global" (func $global)) - (export "global" (func $global)) - - ;; CHECK: (export "written" (func $written)) - ;; O3GUF: (export "written" (func $written)) - (export "written" (func $written)) - - ;; CHECK: (func $global (type $0) (result anyref) - ;; CHECK-NEXT: (global.get $string) - ;; CHECK-NEXT: ) - ;; O3GUF: (func $global (type $0) (result anyref) - ;; O3GUF-NEXT: (global.get $string) - ;; O3GUF-NEXT: ) - (func $global (result anyref) - ;; This should not turn into "one". - (global.get $string) - ) - - ;; CHECK: (func $written (type $0) (result anyref) - ;; CHECK-NEXT: (global.set $string-mut - ;; CHECK-NEXT: (string.const "three") - ;; CHECK-NEXT: ) - ;; CHECK-NEXT: (global.get $string-mut) - ;; CHECK-NEXT: ) - ;; O3GUF: (func $written (type $0) (result anyref) - ;; O3GUF-NEXT: (global.set $string-mut - ;; O3GUF-NEXT: (string.const "three") - ;; O3GUF-NEXT: ) - ;; O3GUF-NEXT: (global.get $string-mut) - ;; O3GUF-NEXT: ) - (func $written (result anyref) - (global.set $string-mut - (string.const "three") - ) - ;; This should not turn into "three". - (global.get $string-mut) - ) -) diff --git a/test/lit/passes/string-gathering.wast b/test/lit/passes/string-gathering.wast new file mode 100644 index 000000000..21fe358a3 --- /dev/null +++ b/test/lit/passes/string-gathering.wast @@ -0,0 +1,96 @@ +;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. + +;; RUN: foreach %s %t wasm-opt --string-gathering -all -S -o - | filecheck %s + +;; All the strings should be collected into globals and used from there. They +;; should also be sorted deterministically (alphabetically). + +(module + ;; Note that $global will be reused: no new global will be added for "foo". + ;; $global2 almost can, but it has the wrong type, so it won't. + + ;; CHECK: (type $0 (func)) + + ;; CHECK: (global $string.const_bar (ref string) (string.const "bar")) + + ;; CHECK: (global $string.const_other (ref string) (string.const "other")) + + ;; CHECK: (global $global (ref string) (string.const "foo")) + (global $global (ref string) (string.const "foo")) + + ;; CHECK: (global $global2 stringref (global.get $string.const_bar)) + (global $global2 (ref null string) (string.const "bar")) + + ;; CHECK: (func $a (type $0) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (global.get $string.const_bar) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (global.get $global) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $a + (drop + (string.const "bar") + ) + (drop + (string.const "foo") + ) + ) + + ;; CHECK: (func $b (type $0) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (global.get $string.const_bar) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (global.get $string.const_other) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (global.get $global) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (global.get $global2) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $b + (drop + (string.const "bar") + ) + (drop + (string.const "other") + ) + ;; Existing global.gets are not modified (but after this pass, + ;; SimplifyGlobals could help; though in practice the globals would have + ;; been propagated here anyhow). + (drop + (global.get $global) + ) + (drop + (global.get $global2) + ) + ) +) + +;; Multiple possible reusable globals. Also test ignoring of imports. +(module + ;; CHECK: (import "a" "b" (global $import (ref string))) + (import "a" "b" (global $import (ref string))) + + ;; CHECK: (global $global1 (ref string) (string.const "foo")) + (global $global1 (ref string) (string.const "foo")) + + ;; CHECK: (global $global2 (ref string) (global.get $global1)) + (global $global2 (ref string) (string.const "foo")) + + ;; CHECK: (global $global3 (ref string) (global.get $global1)) + (global $global3 (ref string) (string.const "foo")) + + ;; CHECK: (global $global4 (ref string) (string.const "bar")) + (global $global4 (ref string) (string.const "bar")) + + ;; CHECK: (global $global5 (ref string) (global.get $global4)) + (global $global5 (ref string) (string.const "bar")) + + ;; CHECK: (global $global6 (ref string) (global.get $global4)) + (global $global6 (ref string) (string.const "bar")) +) |