diff options
-rw-r--r-- | src/passes/RemoveUnusedModuleElements.cpp | 5 | ||||
-rw-r--r-- | test/lit/merge/chain.wat | 6 | ||||
-rw-r--r-- | test/lit/passes/O3_inline-functions-with-loops_flexible-inline-max-function-size=30.wast | 7 | ||||
-rw-r--r-- | test/lit/passes/extract-function.wast | 14 | ||||
-rw-r--r-- | test/lit/passes/remove-unused-module-elements-refs.wast | 14 | ||||
-rw-r--r-- | test/lit/passes/remove-unused-module-elements_all-features.wast | 68 | ||||
-rw-r--r-- | test/metadce/threaded.wast.dced | 15 | ||||
-rw-r--r-- | test/metadce/threaded_cycle.wast.dced | 20 | ||||
-rw-r--r-- | test/passes/remove-unused-nonfunction-module-elements_all-features.txt | 6 | ||||
-rw-r--r-- | test/wasm2js/dot_import.2asm.js | 6 | ||||
-rw-r--r-- | test/wasm2js/dot_import.2asm.js.opt | 6 | ||||
-rw-r--r-- | test/wasm2js/emscripten.2asm.js | 6 | ||||
-rw-r--r-- | test/wasm2js/emscripten.2asm.js.opt | 6 | ||||
-rw-r--r-- | test/wasm2js/func_ptrs.2asm.js | 7 |
14 files changed, 144 insertions, 42 deletions
diff --git a/src/passes/RemoveUnusedModuleElements.cpp b/src/passes/RemoveUnusedModuleElements.cpp index cf1f265bc..ed3c9ed7b 100644 --- a/src/passes/RemoveUnusedModuleElements.cpp +++ b/src/passes/RemoveUnusedModuleElements.cpp @@ -717,6 +717,11 @@ struct RemoveUnusedModuleElements : public Pass { // Do simple work that prepares the module to be efficiently optimized. void prepare(Module* module) { + // FIXME Disable these optimizations for now, as they uncovered bugs in + // both LLVM and Binaryen, + // https://github.com/WebAssembly/binaryen/pull/6026#issuecomment-1775674882 + return; + // If a function export is a function that just calls another function, we // can export that one directly. Doing so might make the function in the // middle unused: diff --git a/test/lit/merge/chain.wat b/test/lit/merge/chain.wat index 76004e9bd..528b20d0e 100644 --- a/test/lit/merge/chain.wat +++ b/test/lit/merge/chain.wat @@ -13,8 +13,12 @@ ;; CHECK: (export "g" (func $0)) -;; CHECK: (export "h" (func $0)) +;; CHECK: (export "h" (func $0_2)) ;; CHECK: (func $0 (type $0) ;; CHECK-NEXT: (nop) ;; CHECK-NEXT: ) + +;; CHECK: (func $0_2 (type $0) +;; CHECK-NEXT: (call $0) +;; CHECK-NEXT: ) diff --git a/test/lit/passes/O3_inline-functions-with-loops_flexible-inline-max-function-size=30.wast b/test/lit/passes/O3_inline-functions-with-loops_flexible-inline-max-function-size=30.wast index 907891aee..e0045579d 100644 --- a/test/lit/passes/O3_inline-functions-with-loops_flexible-inline-max-function-size=30.wast +++ b/test/lit/passes/O3_inline-functions-with-loops_flexible-inline-max-function-size=30.wast @@ -18,7 +18,7 @@ ;; CHECK: (export "t1" (func $t1)) - ;; CHECK: (export "t2" (func $fib)) + ;; CHECK: (export "t2" (func $t2)) ;; CHECK: (export "t3" (func $t3)) @@ -155,6 +155,11 @@ ) ) ) + ;; CHECK: (func $t2 (; has Stack IR ;) (param $0 i32) (result i32) + ;; CHECK-NEXT: (call $fib + ;; CHECK-NEXT: (local.get $0) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) (func $t2 (export "t2") (type $t0) (param $p0 i32) (result i32) (call $fib (local.get $p0) diff --git a/test/lit/passes/extract-function.wast b/test/lit/passes/extract-function.wast index e4b804abe..9258f8c63 100644 --- a/test/lit/passes/extract-function.wast +++ b/test/lit/passes/extract-function.wast @@ -5,6 +5,15 @@ ;; RUN: foreach %s %t wasm-opt --extract-function-index --pass-arg=extract-function-index@0 -S -o - | filecheck %s (module + ;; CHECK: (type $0 (func)) + + ;; CHECK: (import "env" "bar" (func $bar)) + + ;; CHECK: (export "foo" (func $foo)) + + ;; CHECK: (func $foo + ;; CHECK-NEXT: (call $bar) + ;; CHECK-NEXT: ) (func $foo (call $bar) ) @@ -18,11 +27,6 @@ ) ) -;; CHECK: (type $0 (func)) - -;; CHECK: (import "env" "bar" (func $bar)) - -;; CHECK: (export "foo" (func $bar)) (module ;; Use another function in the table, but the table is not used in the ;; extracted function diff --git a/test/lit/passes/remove-unused-module-elements-refs.wast b/test/lit/passes/remove-unused-module-elements-refs.wast index 377639e51..00ea9767f 100644 --- a/test/lit/passes/remove-unused-module-elements-refs.wast +++ b/test/lit/passes/remove-unused-module-elements-refs.wast @@ -656,18 +656,24 @@ (ref.func $d) )) + ;; CHECK: (export "export" (func $export)) + + ;; CHECK: (func $export (type $void) + ;; CHECK-NEXT: (call $b) + ;; CHECK-NEXT: ) + ;; OPEN_WORLD: (export "export" (func $export)) + + ;; OPEN_WORLD: (func $export (type $void) + ;; OPEN_WORLD-NEXT: (call $b) + ;; OPEN_WORLD-NEXT: ) (func $export (export "export") ;; Call $b but not $a or $c (call $b) ) - ;; CHECK: (export "export" (func $b)) - ;; CHECK: (func $a (type $void) ;; CHECK-NEXT: (unreachable) ;; CHECK-NEXT: ) - ;; OPEN_WORLD: (export "export" (func $b)) - ;; OPEN_WORLD: (func $a (type $void) ;; OPEN_WORLD-NEXT: (call_ref $void ;; OPEN_WORLD-NEXT: (struct.get $vtable 0 diff --git a/test/lit/passes/remove-unused-module-elements_all-features.wast b/test/lit/passes/remove-unused-module-elements_all-features.wast index b5c5d701e..efa9ece60 100644 --- a/test/lit/passes/remove-unused-module-elements_all-features.wast +++ b/test/lit/passes/remove-unused-module-elements_all-features.wast @@ -19,7 +19,7 @@ ;; CHECK: (export "memory" (memory $0)) - ;; CHECK: (export "exported" (func $called2)) + ;; CHECK: (export "exported" (func $exported)) ;; CHECK: (export "other1" (func $other1)) @@ -64,6 +64,9 @@ (func $called_indirect (type $0) (nop) ) + ;; CHECK: (func $exported (type $0) + ;; CHECK-NEXT: (call $called2) + ;; CHECK-NEXT: ) (func $exported (type $0-dupe) (call $called2) ) @@ -456,15 +459,15 @@ (func $waka) ;; used in table ) (module ;; one is exported, and one->two->int global, whose init->imported - ;; CHECK: (type $0 (func (param i32) (result i32))) + ;; CHECK: (type $0 (func (result i32))) - ;; CHECK: (type $1 (func (result i32))) + ;; CHECK: (type $1 (func)) - ;; CHECK: (type $2 (func)) + ;; CHECK: (type $2 (func (param i32) (result i32))) ;; CHECK: (import "env" "imported" (global $imported i32)) (import "env" "imported" (global $imported i32)) - ;; CHECK: (import "env" "_puts" (func $_puts (type $0) (param i32) (result i32))) + ;; CHECK: (import "env" "_puts" (func $_puts (type $2) (param i32) (result i32))) (import "env" "forgetme" (global $forgetme i32)) (import "env" "_puts" (func $_puts (param i32) (result i32))) (import "env" "forget_puts" (func $forget_puts (param i32) (result i32))) @@ -475,26 +478,32 @@ (global $forglobal.get (mut i32) (i32.const 500)) ;; CHECK: (global $exp_glob i32 (i32.const 600)) (global $exp_glob i32 (i32.const 600)) - ;; CHECK: (export "one" (func $two)) + ;; CHECK: (export "one" (func $one)) (export "one" (func $one)) - ;; CHECK: (export "three" (func $four)) + ;; CHECK: (export "three" (func $three)) (export "three" (func $three)) ;; CHECK: (export "exp_glob" (global $exp_glob)) (export "exp_glob" (global $exp_glob)) (start $starter) + ;; CHECK: (func $one (type $0) (result i32) + ;; CHECK-NEXT: (call $two) + ;; CHECK-NEXT: ) (func $one (result i32) (call $two) ) - ;; CHECK: (func $two (type $1) (result i32) + ;; CHECK: (func $two (type $0) (result i32) ;; CHECK-NEXT: (global.get $int) ;; CHECK-NEXT: ) (func $two (result i32) (global.get $int) ) + ;; CHECK: (func $three (type $1) + ;; CHECK-NEXT: (call $four) + ;; CHECK-NEXT: ) (func $three (call $four) ) - ;; CHECK: (func $four (type $2) + ;; CHECK: (func $four (type $1) ;; CHECK-NEXT: (global.set $set ;; CHECK-NEXT: (i32.const 200) ;; CHECK-NEXT: ) @@ -766,19 +775,25 @@ ;; CHECK: (export "export-import" (func $import)) (export "export-import" (func $import)) - ;; CHECK: (export "export-middle" (func $import)) + ;; CHECK: (export "export-middle" (func $middle)) (export "export-middle" (func $middle)) - ;; CHECK: (export "export-other-middle" (func $internal)) + ;; CHECK: (export "export-other-middle" (func $other-middle)) (export "export-other-middle" (func $other-middle)) ;; CHECK: (export "export-internal" (func $internal)) (export "export-internal" (func $internal)) + ;; CHECK: (func $middle (type $0) + ;; CHECK-NEXT: (call $import) + ;; CHECK-NEXT: ) (func $middle (call $import) ) + ;; CHECK: (func $other-middle (type $0) + ;; CHECK-NEXT: (call $internal) + ;; CHECK-NEXT: ) (func $other-middle (call $internal) ) @@ -812,7 +827,7 @@ ;; CHECK: (export "export-import-B" (func $import-B)) (export "export-import-B" (func $import-B)) - ;; CHECK: (export "export-middle-A-A" (func $import-A)) + ;; CHECK: (export "export-middle-A-A" (func $middle-A-A)) (export "export-middle-A-A" (func $middle-A-A)) ;; CHECK: (export "export-middle-A-B" (func $middle-A-B)) @@ -821,9 +836,12 @@ ;; CHECK: (export "export-middle-B-A" (func $middle-B-A)) (export "export-middle-B-A" (func $middle-B-A)) - ;; CHECK: (export "export-middle-B-B" (func $import-B)) + ;; CHECK: (export "export-middle-B-B" (func $middle-B-B)) (export "export-middle-B-B" (func $middle-B-B)) + ;; CHECK: (func $middle-A-A (type $A) + ;; CHECK-NEXT: (call $import-A) + ;; CHECK-NEXT: ) (func $middle-A-A (type $A) (call $import-A) ) @@ -842,6 +860,9 @@ (call $import-A) ) + ;; CHECK: (func $middle-B-B (type $B) + ;; CHECK-NEXT: (call $import-B) + ;; CHECK-NEXT: ) (func $middle-B-B (type $B) (call $import-B) ) @@ -858,7 +879,7 @@ ;; CHECK: (export "export-import" (func $import)) (export "export-import" (func $import)) - ;; CHECK: (export "export-middle" (func $import)) + ;; CHECK: (export "export-middle" (func $middle)) (export "export-middle" (func $middle)) ;; CHECK: (export "export-middle-local" (func $middle-local)) @@ -870,6 +891,12 @@ ;; CHECK: (export "export-middle-noncall" (func $middle-noncall)) (export "export-middle-noncall" (func $middle-noncall)) + ;; CHECK: (func $middle (type $0) (param $x i32) + ;; CHECK-NEXT: (local $y i32) + ;; CHECK-NEXT: (call $import + ;; CHECK-NEXT: (local.get $x) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) (func $middle (param $x i32) ;; This extra local is not a problem. (local $y i32) @@ -927,12 +954,18 @@ ;; CHECK: (import "a" "b" (func $import (type $0) (param i32 i32) (result f64))) (import "a" "b" (func $import (param i32) (param i32) (result f64))) - ;; CHECK: (export "export-middle-right" (func $import)) + ;; CHECK: (export "export-middle-right" (func $middle-right)) (export "export-middle-right" (func $middle-right)) ;; CHECK: (export "export-middle-wrong" (func $middle-wrong)) (export "export-middle-wrong" (func $middle-wrong)) + ;; CHECK: (func $middle-right (type $0) (param $x i32) (param $y i32) (result f64) + ;; CHECK-NEXT: (call $import + ;; CHECK-NEXT: (local.get $x) + ;; CHECK-NEXT: (local.get $y) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) (func $middle-right (param $x i32) (param $y i32) (result f64) (call $import (local.get $x) @@ -963,9 +996,12 @@ ;; CHECK: (import "a" "b" (func $import (type $0))) (import "a" "b" (func $import)) - ;; CHECK: (export "export-middle" (func $import)) + ;; CHECK: (export "export-middle" (func $middle)) (export "export-middle" (func $middle)) + ;; CHECK: (func $middle (type $0) + ;; CHECK-NEXT: (return_call $import) + ;; CHECK-NEXT: ) (func $middle (return_call $import) ) diff --git a/test/metadce/threaded.wast.dced b/test/metadce/threaded.wast.dced index 3157a360a..0d5d2f98d 100644 --- a/test/metadce/threaded.wast.dced +++ b/test/metadce/threaded.wast.dced @@ -3,11 +3,20 @@ (import "env" "js_func4" (func $js_func_4 (type $0))) (import "env" "js_func3" (func $js_func_3 (type $0))) (import "env" "js_func2" (func $js_func_2 (type $0))) - (export "wasm_func1" (func $js_func_2)) - (export "wasm_func2" (func $js_func_3)) - (export "wasm_func3" (func $js_func_4)) + (export "wasm_func1" (func $wasm_func_1)) + (export "wasm_func2" (func $wasm_func_2)) + (export "wasm_func3" (func $wasm_func_3)) (export "wasm_func4" (func $wasm_func_4)) (func $wasm_func_4 (type $0) (nop) ) + (func $wasm_func_3 (type $0) + (call $js_func_4) + ) + (func $wasm_func_2 (type $0) + (call $js_func_3) + ) + (func $wasm_func_1 (type $0) + (call $js_func_2) + ) ) diff --git a/test/metadce/threaded_cycle.wast.dced b/test/metadce/threaded_cycle.wast.dced index 1b30eadc5..302cb3faf 100644 --- a/test/metadce/threaded_cycle.wast.dced +++ b/test/metadce/threaded_cycle.wast.dced @@ -4,8 +4,20 @@ (import "env" "js_func3" (func $js_func_3 (type $0))) (import "env" "js_func2" (func $js_func_2 (type $0))) (import "env" "js_func1" (func $js_func_1 (type $0))) - (export "wasm_func1" (func $js_func_2)) - (export "wasm_func2" (func $js_func_3)) - (export "wasm_func3" (func $js_func_4)) - (export "wasm_func4" (func $js_func_1)) + (export "wasm_func1" (func $wasm_func_1)) + (export "wasm_func2" (func $wasm_func_2)) + (export "wasm_func3" (func $wasm_func_3)) + (export "wasm_func4" (func $wasm_func_4)) + (func $wasm_func_4 (type $0) + (call $js_func_1) + ) + (func $wasm_func_3 (type $0) + (call $js_func_4) + ) + (func $wasm_func_2 (type $0) + (call $js_func_3) + ) + (func $wasm_func_1 (type $0) + (call $js_func_2) + ) ) diff --git a/test/passes/remove-unused-nonfunction-module-elements_all-features.txt b/test/passes/remove-unused-nonfunction-module-elements_all-features.txt index 186bdd69b..d19fcc514 100644 --- a/test/passes/remove-unused-nonfunction-module-elements_all-features.txt +++ b/test/passes/remove-unused-nonfunction-module-elements_all-features.txt @@ -6,7 +6,7 @@ (table $0 1 1 funcref) (elem $0 (i32.const 0) $called_indirect) (export "memory" (memory $0)) - (export "exported" (func $called2)) + (export "exported" (func $exported)) (export "other1" (func $other1)) (export "other2" (func $other2)) (start $start) @@ -240,8 +240,8 @@ (global $int (mut i32) (global.get $imported)) (global $set (mut i32) (i32.const 100)) (global $exp_glob i32 (i32.const 600)) - (export "one" (func $two)) - (export "three" (func $four)) + (export "one" (func $one)) + (export "three" (func $three)) (export "exp_glob" (global $exp_glob)) (func $one (type $1) (result i32) (call $two) diff --git a/test/wasm2js/dot_import.2asm.js b/test/wasm2js/dot_import.2asm.js index 0cd48aaf1..a35eabe95 100644 --- a/test/wasm2js/dot_import.2asm.js +++ b/test/wasm2js/dot_import.2asm.js @@ -13,8 +13,12 @@ function asmFunc(imports) { var Math_sqrt = Math.sqrt; var mod_ule = imports["mod.ule"]; var base = mod_ule["ba.se"]; + function $0() { + base(); + } + return { - "exported": base + "exported": $0 }; } diff --git a/test/wasm2js/dot_import.2asm.js.opt b/test/wasm2js/dot_import.2asm.js.opt index 0cd48aaf1..a35eabe95 100644 --- a/test/wasm2js/dot_import.2asm.js.opt +++ b/test/wasm2js/dot_import.2asm.js.opt @@ -13,8 +13,12 @@ function asmFunc(imports) { var Math_sqrt = Math.sqrt; var mod_ule = imports["mod.ule"]; var base = mod_ule["ba.se"]; + function $0() { + base(); + } + return { - "exported": base + "exported": $0 }; } diff --git a/test/wasm2js/emscripten.2asm.js b/test/wasm2js/emscripten.2asm.js index 52412f676..8ba8564ce 100644 --- a/test/wasm2js/emscripten.2asm.js +++ b/test/wasm2js/emscripten.2asm.js @@ -61,6 +61,10 @@ function asmFunc(imports) { exported(1 | 0) | 0; } + function other() { + main(); + } + function foo() { wasm2js_trap(); } @@ -218,7 +222,7 @@ function asmFunc(imports) { return { "main": main, - "other": main, + "other": other, "__growWasmMemory": __growWasmMemory, "exported": exported, "sub_zero": sub_zero, diff --git a/test/wasm2js/emscripten.2asm.js.opt b/test/wasm2js/emscripten.2asm.js.opt index 1faf11933..caef23896 100644 --- a/test/wasm2js/emscripten.2asm.js.opt +++ b/test/wasm2js/emscripten.2asm.js.opt @@ -70,6 +70,10 @@ function asmFunc(imports) { FUNCTION_TABLE[HEAP32[257]](); } + function other() { + main(); + } + function foo() { wasm2js_trap(); } @@ -213,7 +217,7 @@ function asmFunc(imports) { return { "main": main, - "other": main, + "other": other, "__growWasmMemory": __growWasmMemory, "exported": internal, "sub_zero": sub_zero, diff --git a/test/wasm2js/func_ptrs.2asm.js b/test/wasm2js/func_ptrs.2asm.js index ccd220152..4b7c4fd44 100644 --- a/test/wasm2js/func_ptrs.2asm.js +++ b/test/wasm2js/func_ptrs.2asm.js @@ -27,11 +27,16 @@ function asmFunc(imports) { return a - 2 | 0 | 0; } + function $6($0) { + $0 = $0 | 0; + print($0 | 0); + } + return { "one": $3, "two": $4, "three": $5, - "four": print + "four": $6 }; } |