From 3af404435b3cfa90704810370703f20921c055dd Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 7 Jun 2018 19:05:43 -0700 Subject: duplicate-function-elimination improvements (#1590) On a codebase with 370K functions, 160K were in fact duplicate (!)... and it took many many passes to figure that out, over 2 minutes in fact (!), as A and B may be identical only after we see that the functions C1, C2 that they call are identical (so there can be long "chains" here). To avoid this, limit how many passes we do. In -O1, just do one pass - that gets most duplicates. In -O2, do 10 passes - that gets almost all of it on this codebase. And in -O3 (or -Os/-Oz) do as many passes as necessary (i.e., the old behavior). This at least lets iteration builds (-O1) be nice and fast. This PR also refactors the hashing code used in that pass, moving it to nicer header files for clearer readability. Also some other minor cleanups in hashing code that helped debug this. --- src/ir/ExpressionAnalyzer.cpp | 10 +- src/ir/function-utils.h | 46 + src/ir/hashed.h | 47 + src/passes/DuplicateFunctionElimination.cpp | 72 +- src/support/hash.h | 9 +- src/tools/fuzzing.h | 3 + test/passes/duplicate-function-elimination.txt | 1065 ----------------- test/passes/duplicate-function-elimination.wast | 1221 -------------------- ...icate-function-elimination_optimize-level=1.txt | 1068 +++++++++++++++++ ...cate-function-elimination_optimize-level=1.wast | 1221 ++++++++++++++++++++ ...icate-function-elimination_optimize-level=2.txt | 1065 +++++++++++++++++ ...cate-function-elimination_optimize-level=2.wast | 1221 ++++++++++++++++++++ test/passes/remove-unused-names_code-folding.txt | 12 +- 13 files changed, 4709 insertions(+), 2351 deletions(-) create mode 100644 src/ir/function-utils.h delete mode 100644 test/passes/duplicate-function-elimination.txt delete mode 100644 test/passes/duplicate-function-elimination.wast create mode 100644 test/passes/duplicate-function-elimination_optimize-level=1.txt create mode 100644 test/passes/duplicate-function-elimination_optimize-level=1.wast create mode 100644 test/passes/duplicate-function-elimination_optimize-level=2.txt create mode 100644 test/passes/duplicate-function-elimination_optimize-level=2.wast diff --git a/src/ir/ExpressionAnalyzer.cpp b/src/ir/ExpressionAnalyzer.cpp index 5368c25f6..64b1ce24b 100644 --- a/src/ir/ExpressionAnalyzer.cpp +++ b/src/ir/ExpressionAnalyzer.cpp @@ -510,8 +510,14 @@ uint32_t ExpressionAnalyzer::hash(Expression* curr) { break; } case Expression::Id::ConstId: { - HASH(Const, value.type); - HASH64(Const, value.getBits()); + auto* c = curr->cast(); + hash(c->type); + auto bits = c->value.getBits(); + if (getTypeSize(c->type) == 4) { + hash(uint32_t(bits)); + } else { + hash64(bits); + } break; } case Expression::Id::UnaryId: { diff --git a/src/ir/function-utils.h b/src/ir/function-utils.h new file mode 100644 index 000000000..317b2f1b1 --- /dev/null +++ b/src/ir/function-utils.h @@ -0,0 +1,46 @@ +/* + * Copyright 2018 WebAssembly Community Group participants + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef wasm_ir_function_h +#define wasm_ir_function_h + +#include "wasm.h" +#include "ir/utils.h" + +namespace wasm { + +namespace FunctionUtils { + +// Checks if two functions are equal in all functional aspects, +// everything but their name (which can't be the same, in the same +// module!) - same params, vars, body, result, etc. +inline bool equal(Function* left, Function* right) { + if (left->getNumParams() != right->getNumParams()) return false; + if (left->getNumVars() != right->getNumVars()) return false; + for (Index i = 0; i < left->getNumLocals(); i++) { + if (left->getLocalType(i) != right->getLocalType(i)) return false; + } + if (left->result != right->result) return false; + if (left->type != right->type) return false; + return ExpressionAnalyzer::equal(left->body, right->body); +} + +} // namespace FunctionUtils + +} // namespace wasm + +#endif // wasm_ir_function_h + diff --git a/src/ir/hashed.h b/src/ir/hashed.h index dc4012455..0771da6ec 100644 --- a/src/ir/hashed.h +++ b/src/ir/hashed.h @@ -53,6 +53,53 @@ template class HashedExpressionMap : public std::unordered_map { }; +// A pass that hashes all functions + +struct FunctionHasher : public WalkerPass> { + bool isFunctionParallel() override { return true; } + + typedef uint32_t HashType; + + struct Map : public std::map {}; + + FunctionHasher(Map* output) : output(output) {} + + FunctionHasher* create() override { + return new FunctionHasher(output); + } + + static Map createMap(Module* module) { + Map hashes; + for (auto& func : module->functions) { + hashes[func.get()] = 0; // ensure an entry for each function - we must not modify the map shape in parallel, just the values + } + return hashes; + } + + void doWalkFunction(Function* func) { + output->at(func) = hashFunction(func); + } + + static HashType hashFunction(Function* func) { + HashType ret = 0; + ret = rehash(ret, (HashType)func->getNumParams()); + for (auto type : func->params) { + ret = rehash(ret, (HashType)type); + } + ret = rehash(ret, (HashType)func->getNumVars()); + for (auto type : func->vars) { + ret = rehash(ret, (HashType)type); + } + ret = rehash(ret, (HashType)func->result); + ret = rehash(ret, HashType(func->type.is() ? std::hash{}(func->type) : HashType(0))); + ret = rehash(ret, (HashType)ExpressionAnalyzer::hash(func->body)); + return ret; + } + +private: + Map* output; +}; + } // namespace wasm #endif // _wasm_ir_hashed_h diff --git a/src/passes/DuplicateFunctionElimination.cpp b/src/passes/DuplicateFunctionElimination.cpp index 027d16b4a..60667cdd6 100644 --- a/src/passes/DuplicateFunctionElimination.cpp +++ b/src/passes/DuplicateFunctionElimination.cpp @@ -23,43 +23,11 @@ #include "wasm.h" #include "pass.h" #include "ir/utils.h" -#include "support/hash.h" +#include "ir/function-utils.h" +#include "ir/hashed.h" namespace wasm { -struct FunctionHasher : public WalkerPass> { - bool isFunctionParallel() override { return true; } - - FunctionHasher(std::map* output) : output(output) {} - - FunctionHasher* create() override { - return new FunctionHasher(output); - } - - void doWalkFunction(Function* func) { - assert(digest == 0); - hash(func->getNumParams()); - for (auto type : func->params) hash(type); - hash(func->getNumVars()); - for (auto type : func->vars) hash(type); - hash(func->result); - hash64(func->type.is() ? uint64_t(func->type.str) : uint64_t(0)); - hash(ExpressionAnalyzer::hash(func->body)); - output->at(func) = digest; - } - -private: - std::map* output; - uint32_t digest = 0; - - void hash(uint32_t hash) { - digest = rehash(digest, hash); - } - void hash64(uint64_t hash) { - digest = rehash(rehash(digest, uint32_t(hash >> 32)), uint32_t(hash)); - }; -}; - struct FunctionReplacer : public WalkerPass> { bool isFunctionParallel() override { return true; } @@ -82,12 +50,22 @@ private: struct DuplicateFunctionElimination : public Pass { void run(PassRunner* runner, Module* module) override { - while (1) { + // Multiple iterations may be necessary: A and B may be identical only after we + // see the functions C1 and C2 that they call are in fact identical. Rarely, such + // "chains" can be very long, so we limit how many we do. + auto& options = runner->options; + Index limit; + if (options.optimizeLevel >= 3 || options.shrinkLevel >= 1) { + limit = module->functions.size(); // no limit + } else if (options.optimizeLevel >= 2) { + limit = 10; // 10 passes usually does most of the work, as this is typically logarithmic + } else { + limit = 1; + } + while (limit > 0) { + limit--; // Hash all the functions - hashes.clear(); - for (auto& func : module->functions) { - hashes[func.get()] = 0; // ensure an entry for each function - we must not modify the map shape in parallel, just the values - } + auto hashes = FunctionHasher::createMap(module); PassRunner hasherRunner(module); hasherRunner.setIsNested(true); hasherRunner.add(&hashes); @@ -113,7 +91,7 @@ struct DuplicateFunctionElimination : public Pass { for (Index j = i + 1; j < size; j++) { auto* second = group[j]; if (duplicates.count(second->name)) continue; - if (equal(first, second)) { + if (FunctionUtils::equal(first, second)) { // great, we can replace the second with the first! replacements[second->name] = first->name; duplicates.insert(second->name); @@ -162,20 +140,6 @@ struct DuplicateFunctionElimination : public Pass { } } } - -private: - std::map hashes; - - bool equal(Function* left, Function* right) { - if (left->getNumParams() != right->getNumParams()) return false; - if (left->getNumVars() != right->getNumVars()) return false; - for (Index i = 0; i < left->getNumLocals(); i++) { - if (left->getLocalType(i) != right->getLocalType(i)) return false; - } - if (left->result != right->result) return false; - if (left->type != right->type) return false; - return ExpressionAnalyzer::equal(left->body, right->body); - } }; Pass *createDuplicateFunctionEliminationPass() { diff --git a/src/support/hash.h b/src/support/hash.h index 9edbdd2c7..158f20773 100644 --- a/src/support/hash.h +++ b/src/support/hash.h @@ -22,7 +22,8 @@ namespace wasm { -inline uint32_t rehash(uint32_t x, uint32_t y) { // see http://www.cse.yorku.ca/~oz/hash.html +inline uint32_t rehash(uint32_t x, uint32_t y) { + // see http://www.cse.yorku.ca/~oz/hash.html and https://stackoverflow.com/a/2595226/1176841 uint32_t hash = 5381; while (x) { hash = ((hash << 5) + hash) ^ (x & 0xff); @@ -35,8 +36,10 @@ inline uint32_t rehash(uint32_t x, uint32_t y) { // see http://www.cse.yorku.ca/ return hash; } -inline uint64_t rehash(uint64_t x, uint64_t y) { // see boost and https://stackoverflow.com/a/2595226/1176841 - return x ^ (y + 0x9e3779b9 + (x << 6) + (x >> 2)); +inline uint64_t rehash(uint64_t x, uint64_t y) { + auto ret = rehash(uint32_t(x), uint32_t(x >> 32)); + ret = rehash(ret, uint32_t(y)); + return rehash(ret, uint32_t(y >> 32)); } } // namespace wasm diff --git a/src/tools/fuzzing.h b/src/tools/fuzzing.h index c433a81d8..062fc29a6 100644 --- a/src/tools/fuzzing.h +++ b/src/tools/fuzzing.h @@ -1438,3 +1438,6 @@ private: } // namespace wasm // XXX Switch class has a condition?! is it real? should the node type be the value type if it exists?! + +// TODO copy an existing function and replace just one node in it + diff --git a/test/passes/duplicate-function-elimination.txt b/test/passes/duplicate-function-elimination.txt deleted file mode 100644 index baf4fedf2..000000000 --- a/test/passes/duplicate-function-elimination.txt +++ /dev/null @@ -1,1065 +0,0 @@ -(module - (type $0 (func)) - (memory $0 0) - (func $erase (; 0 ;) (type $0) - (nop) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $keep2 (; 0 ;) (type $0) - (drop - (i32.const 0) - ) - ) - (func $other (; 1 ;) (type $0) - (nop) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $erase (; 0 ;) (type $0) - (drop - (i32.const 0) - ) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $keep2 (; 0 ;) (type $0) - (drop - (i32.const 0) - ) - ) - (func $other (; 1 ;) (type $0) - (drop - (i32.const 1) - ) - ) -) -(module - (type $0 (func)) - (table 3 3 anyfunc) - (elem (i32.const 0) $keep2 $keep2 $caller) - (memory $0 0) - (export "keep2" (func $keep2)) - (export "other" (func $keep2)) - (start $keep2) - (func $keep2 (; 0 ;) (type $0) - (nop) - ) - (func $caller (; 1 ;) (type $0) - (call $keep2) - (call $keep2) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $keep2-after-two-passes (; 0 ;) (type $0) - (nop) - ) - (func $keep-caller (; 1 ;) (type $0) - (call $keep2-after-two-passes) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $keep-4 (; 0 ;) (type $0) - (nop) - ) - (func $other (; 1 ;) (type $0) - (unreachable) - ) - (func $keep-caller (; 2 ;) (type $0) - (call $keep-4) - ) - (func $other-caller (; 3 ;) (type $0) - (call $other) - ) -) -(module - (type $T (func (result i32))) - (type $S (func (result i32))) - (type $2 (func)) - (type $3 (func (param i32))) - (memory $0 0) - (func $keep4-similar-but-func-sig-differs (; 0 ;) (type $2) - (drop - (i32.const 0) - ) - ) - (func $other1 (; 1 ;) (type $3) (param $i i32) - (drop - (i32.const 0) - ) - ) - (func $other2 (; 2 ;) (type $T) (result i32) - (i32.const 0) - ) - (func $other3 (; 3 ;) (type $S) (result i32) - (i32.const 0) - ) -) -(module - (type $S (func (result i32))) - (type $1 (func (param i32))) - (memory $0 0) - (func $keep2-similar-but-func-sig-differs (; 0 ;) (type $1) (param $i i32) - (drop - (i32.const 0) - ) - ) - (func $other2 (; 1 ;) (type $S) (result i32) - (i32.const 0) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $keep2 (; 0 ;) (type $0) - (nop) - ) - (func $other (; 1 ;) (type $0) - (nop) - (nop) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $erase (; 0 ;) (type $0) - (block $block0 - ) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $keep2 (; 0 ;) (type $0) - (block $block0 - ) - ) - (func $other (; 1 ;) (type $0) - (block $block0 - (nop) - ) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $erase (; 0 ;) (type $0) - (block $block0 - (nop) - ) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $keep2 (; 0 ;) (type $0) - (block $block0 - (nop) - ) - ) - (func $other (; 1 ;) (type $0) - (block $block0 - (nop) - (unreachable) - ) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $keep2 (; 0 ;) (type $0) - (block $block0 - (nop) - ) - ) - (func $other (; 1 ;) (type $0) - (block $block0 - (unreachable) - ) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $erase-since-block-names-do-not-matter (; 0 ;) (type $0) - (block $foo - ) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $erase-since-block-names-do-not-matter (; 0 ;) (type $0) - (block $foo - (br $foo) - (br_table $foo $foo - (i32.const 0) - ) - ) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $keep2 (; 0 ;) (type $0) - (block $foo - (block $block - (drop - (i32.const 0) - ) - (br $foo) - ) - ) - ) - (func $other (; 1 ;) (type $0) - (block $bar - (block $block - (drop - (i32.const 1) - ) - (br $bar) - ) - ) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $keep2 (; 0 ;) (type $0) - (block $foo - (br_if $foo - (i32.const 0) - ) - ) - ) - (func $other (; 1 ;) (type $0) - (block $bar - (br_if $bar - (i32.const 1) - ) - ) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $erase (; 0 ;) (type $0) - (block $foo - (br_if $foo - (i32.const 0) - ) - ) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $keep2 (; 0 ;) (type $0) - (block $foo - (br_table $foo $foo - (i32.const 0) - ) - ) - ) - (func $other (; 1 ;) (type $0) - (block $bar - (br_table $bar $bar - (i32.const 1) - ) - ) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $erase (; 0 ;) (type $0) - (loop $bar - (nop) - ) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $keep2 (; 0 ;) (type $0) - (drop - (block $foo (result i32) - (br_table $foo $foo - (i32.const 0) - (i32.const 0) - ) - ) - ) - ) - (func $other (; 1 ;) (type $0) - (drop - (block $bar (result i32) - (br_table $bar $bar - (i32.const 0) - (i32.const 1) - ) - ) - ) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $keep2 (; 0 ;) (type $0) - (block $foo - (block $bar - (br_table $foo $bar - (i32.const 0) - ) - ) - ) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $erase (; 0 ;) (type $0) - (block $foo - (block $bar - (br_table $foo $bar - (i32.const 0) - ) - ) - ) - ) - (func $other (; 1 ;) (type $0) - (block $bar - (block $foo - (br_table $foo $bar - (i32.const 0) - ) - ) - ) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $erase (; 0 ;) (type $0) - (call $erase) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $keep2-but-in-theory-we-could-erase (; 0 ;) (type $0) - (call $keep2-but-in-theory-we-could-erase) - ) - (func $other (; 1 ;) (type $0) - (call $other) - ) -) -(module - (type $FUNCSIG$v (func)) - (import "env" "i" (func $i)) - (import "env" "j" (func $j)) - (memory $0 0) - (func $erase (; 2 ;) (type $FUNCSIG$v) - (call $i) - ) -) -(module - (type $FUNCSIG$v (func)) - (import "env" "i" (func $i)) - (import "env" "j" (func $j)) - (memory $0 0) - (func $keep2 (; 2 ;) (type $FUNCSIG$v) - (call $i) - ) - (func $other (; 3 ;) (type $FUNCSIG$v) - (call $j) - ) -) -(module - (type $T (func)) - (table 2 2 anyfunc) - (elem (i32.const 0) $erase $erase) - (memory $0 0) - (func $erase (; 0 ;) (type $T) - (call_indirect (type $T) - (i32.const 0) - ) - ) -) -(module - (type $T (func)) - (table 2 2 anyfunc) - (elem (i32.const 0) $keep2 $other) - (memory $0 0) - (func $keep2 (; 0 ;) (type $T) - (call_indirect (type $T) - (i32.const 0) - ) - ) - (func $other (; 1 ;) (type $T) - (call_indirect (type $T) - (i32.const 1) - ) - ) -) -(module - (type $T (func)) - (type $S (func)) - (table 2 2 anyfunc) - (elem (i32.const 0) $keep2 $other) - (memory $0 0) - (func $keep2 (; 0 ;) (type $T) - (call_indirect (type $T) - (i32.const 0) - ) - ) - (func $other (; 1 ;) (type $T) - (call_indirect (type $S) - (i32.const 0) - ) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $erase-even-locals-with-different-names (; 0 ;) (type $0) - (local $i i32) - (drop - (get_local $i) - ) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $keep2 (; 0 ;) (type $0) - (local $i i32) - (drop - (get_local $i) - ) - ) - (func $other (; 1 ;) (type $0) - (local $j i64) - (drop - (get_local $j) - ) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $erase-even-locals-with-different-names (; 0 ;) (type $0) - (local $i i32) - (set_local $i - (i32.const 0) - ) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $keep2 (; 0 ;) (type $0) - (local $i i32) - (set_local $i - (i32.const 0) - ) - ) - (func $other (; 1 ;) (type $0) - (local $j i64) - (set_local $j - (i64.const 0) - ) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $keep2 (; 0 ;) (type $0) - (local $i i32) - (set_local $i - (i32.const 0) - ) - ) - (func $other (; 1 ;) (type $0) - (local $j i32) - (set_local $j - (i32.const 1) - ) - ) -) -(module - (type $0 (func)) - (memory $0 10) - (func $erase (; 0 ;) (type $0) - (drop - (i32.load - (i32.const 0) - ) - ) - (drop - (i32.load16_s offset=3 - (i32.const 0) - ) - ) - ) -) -(module - (type $0 (func)) - (memory $0 10) - (func $keep2 (; 0 ;) (type $0) - (drop - (i32.load offset=3 - (i32.const 0) - ) - ) - ) - (func $other (; 1 ;) (type $0) - (drop - (i32.load16_s offset=3 - (i32.const 0) - ) - ) - ) -) -(module - (type $0 (func)) - (memory $0 10) - (func $keep2 (; 0 ;) (type $0) - (drop - (i32.load16_s offset=3 - (i32.const 0) - ) - ) - ) - (func $other (; 1 ;) (type $0) - (drop - (i32.load16_s offset=3 align=1 - (i32.const 0) - ) - ) - ) -) -(module - (type $0 (func)) - (memory $0 10) - (func $keep2 (; 0 ;) (type $0) - (drop - (i32.load16_s - (i32.const 0) - ) - ) - ) - (func $other (; 1 ;) (type $0) - (drop - (i32.load16_s offset=3 - (i32.const 0) - ) - ) - ) -) -(module - (type $0 (func)) - (memory $0 10) - (func $keep2 (; 0 ;) (type $0) - (drop - (i32.load16_s offset=3 - (i32.const 0) - ) - ) - ) - (func $other (; 1 ;) (type $0) - (drop - (i32.load16_s offset=3 - (i32.const 1) - ) - ) - ) -) -(module - (type $0 (func)) - (memory $0 10) - (func $keep2 (; 0 ;) (type $0) - (drop - (i32.load16_u offset=3 - (i32.const 0) - ) - ) - ) - (func $other (; 1 ;) (type $0) - (drop - (i32.load16_s offset=3 - (i32.const 0) - ) - ) - ) -) -(module - (type $0 (func)) - (memory $0 10) - (func $erase (; 0 ;) (type $0) - (i32.store - (i32.const 0) - (i32.const 100) - ) - (i32.store16 offset=3 - (i32.const 0) - (i32.const 100) - ) - ) -) -(module - (type $0 (func)) - (memory $0 10) - (func $keep2 (; 0 ;) (type $0) - (i32.store offset=3 - (i32.const 0) - (i32.const 100) - ) - ) - (func $other (; 1 ;) (type $0) - (i32.store16 offset=3 - (i32.const 0) - (i32.const 100) - ) - ) -) -(module - (type $0 (func)) - (memory $0 10) - (func $keep2 (; 0 ;) (type $0) - (i32.store16 offset=3 - (i32.const 0) - (i32.const 100) - ) - ) - (func $other (; 1 ;) (type $0) - (i32.store16 offset=3 align=1 - (i32.const 0) - (i32.const 100) - ) - ) -) -(module - (type $0 (func)) - (memory $0 10) - (func $keep2 (; 0 ;) (type $0) - (i32.store16 - (i32.const 0) - (i32.const 100) - ) - ) - (func $other (; 1 ;) (type $0) - (i32.store16 offset=3 - (i32.const 0) - (i32.const 100) - ) - ) -) -(module - (type $0 (func)) - (memory $0 10) - (func $keep2 (; 0 ;) (type $0) - (i32.store16 offset=3 - (i32.const 0) - (i32.const 100) - ) - ) - (func $other (; 1 ;) (type $0) - (i32.store16 offset=3 - (i32.const 1) - (i32.const 100) - ) - ) -) -(module - (type $0 (func)) - (memory $0 10) - (func $keep2 (; 0 ;) (type $0) - (i32.store16 offset=3 - (i32.const 0) - (i32.const 100) - ) - ) - (func $other (; 1 ;) (type $0) - (i32.store16 offset=3 - (i32.const 0) - (i32.const 101) - ) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $keep2 (; 0 ;) (type $0) - (drop - (i32.const 0) - ) - ) - (func $other (; 1 ;) (type $0) - (drop - (i64.const 0) - ) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $keep2 (; 0 ;) (type $0) - (drop - (i32.const 0) - ) - ) - (func $other (; 1 ;) (type $0) - (drop - (f32.const 0) - ) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $keep2 (; 0 ;) (type $0) - (drop - (i32.const 0) - ) - ) - (func $other (; 1 ;) (type $0) - (drop - (f64.const 0) - ) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $keep2 (; 0 ;) (type $0) - (drop - (i64.const 0) - ) - ) - (func $other (; 1 ;) (type $0) - (drop - (i64.const 1) - ) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $keep2 (; 0 ;) (type $0) - (drop - (f32.const 0.10000000149011612) - ) - ) - (func $other (; 1 ;) (type $0) - (drop - (f32.const -0.10000000149011612) - ) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $keep2 (; 0 ;) (type $0) - (drop - (f64.const 0.1) - ) - ) - (func $other (; 1 ;) (type $0) - (drop - (f64.const 0.2) - ) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $erase (; 0 ;) (type $0) - (drop - (f32.abs - (f32.const 0) - ) - ) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $keep2 (; 0 ;) (type $0) - (drop - (f32.abs - (f32.const 0) - ) - ) - ) - (func $other (; 1 ;) (type $0) - (drop - (f32.abs - (f32.const 1) - ) - ) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $keep2 (; 0 ;) (type $0) - (drop - (f32.abs - (f32.const 0) - ) - ) - ) - (func $other (; 1 ;) (type $0) - (drop - (f32.neg - (f32.const 0) - ) - ) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $erase (; 0 ;) (type $0) - (drop - (f32.add - (f32.const 0) - (f32.const 0) - ) - ) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $keep2 (; 0 ;) (type $0) - (drop - (f32.add - (f32.const 0) - (f32.const 0) - ) - ) - ) - (func $other (; 1 ;) (type $0) - (drop - (f32.add - (f32.const 0) - (f32.const 1) - ) - ) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $keep2 (; 0 ;) (type $0) - (drop - (f32.add - (f32.const 0) - (f32.const 0) - ) - ) - ) - (func $other (; 1 ;) (type $0) - (drop - (f32.add - (f32.const 1) - (f32.const 0) - ) - ) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $keep2 (; 0 ;) (type $0) - (drop - (f32.add - (f32.const 0) - (f32.const 0) - ) - ) - ) - (func $other (; 1 ;) (type $0) - (drop - (f32.sub - (f32.const 0) - (f32.const 0) - ) - ) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $erase (; 0 ;) (type $0) - (drop - (select - (i32.const 0) - (i32.const 0) - (i32.const 0) - ) - ) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $keep (; 0 ;) (type $0) - (drop - (select - (i32.const 0) - (i32.const 0) - (i32.const 0) - ) - ) - ) - (func $other (; 1 ;) (type $0) - (drop - (select - (i32.const 1) - (i32.const 0) - (i32.const 0) - ) - ) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $keep (; 0 ;) (type $0) - (drop - (select - (i32.const 0) - (i32.const 0) - (i32.const 0) - ) - ) - ) - (func $other (; 1 ;) (type $0) - (drop - (select - (i32.const 0) - (i32.const 2) - (i32.const 0) - ) - ) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $keep (; 0 ;) (type $0) - (drop - (select - (i32.const 0) - (i32.const 0) - (i32.const 0) - ) - ) - ) - (func $other (; 1 ;) (type $0) - (drop - (select - (i32.const 0) - (i32.const 0) - (i32.const 3) - ) - ) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $erase (; 0 ;) (type $0) - (return) - ) -) -(module - (type $0 (func (result i32))) - (memory $0 0) - (func $erase (; 0 ;) (type $0) (result i32) - (return - (i32.const 0) - ) - ) -) -(module - (type $0 (func (result i32))) - (memory $0 0) - (func $keep (; 0 ;) (type $0) (result i32) - (return - (i32.const 0) - ) - ) - (func $other (; 1 ;) (type $0) (result i32) - (return - (i32.const 1) - ) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $erase (; 0 ;) (type $0) - (drop - (current_memory) - ) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $erase (; 0 ;) (type $0) - (drop - (grow_memory - (i32.const 10) - ) - ) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $keep (; 0 ;) (type $0) - (drop - (grow_memory - (i32.const 10) - ) - ) - ) - (func $other (; 1 ;) (type $0) - (drop - (grow_memory - (i32.const 11) - ) - ) - ) -) -(module - (type $0 (func)) - (memory $0 0) - (func $keep (; 0 ;) (type $0) - (drop - (current_memory) - ) - ) - (func $other (; 1 ;) (type $0) - (drop - (grow_memory - (i32.const 10) - ) - ) - ) -) diff --git a/test/passes/duplicate-function-elimination.wast b/test/passes/duplicate-function-elimination.wast deleted file mode 100644 index b79032155..000000000 --- a/test/passes/duplicate-function-elimination.wast +++ /dev/null @@ -1,1221 +0,0 @@ -(module - (memory 0) - (type $0 (func)) - (func $erase (type $0) - (nop) - ) - (func $other (type $0) - (nop) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $keep2 (type $0) - (drop - (i32.const 0) - ) - ) - (func $other (type $0) - (nop) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $erase (type $0) - (drop - (i32.const 0) - ) - ) - (func $other (type $0) - (drop - (i32.const 0) - ) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $keep2 (type $0) - (drop - (i32.const 0) - ) - ) - (func $other (type $0) - (drop - (i32.const 1) - ) - ) -) -(module - (memory 0) - (start $other) - (type $0 (func)) - (export "keep2" $keep2) - (export "other" $other) - (table 3 3 anyfunc) - (elem (i32.const 0) $keep2 $other $caller) - (func $keep2 (type $0) - (nop) - ) - (func $other (type $0) - (nop) - ) - (func $caller (type $0) - (call $keep2) - (call $other) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $keep2-after-two-passes (type $0) - (nop) - ) - (func $other (type $0) - (nop) - ) - (func $keep-caller (type $0) - (call $keep2-after-two-passes) - ) - (func $other-caller (type $0) - (call $other) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $keep-4 (type $0) - (nop) - ) - (func $other (type $0) - (unreachable) - ) - (func $keep-caller (type $0) - (call $keep-4) - ) - (func $other-caller (type $0) - (call $other) - ) -) -(module - (memory 0) - (type $T (func (result i32))) - (type $S (func (result i32))) - (type $2 (func)) - (type $3 (func (param i32))) - (func $keep4-similar-but-func-sig-differs (type $2) - (drop - (i32.const 0) - ) - ) - (func $other1 (type $3) (param $i i32) - (drop - (i32.const 0) - ) - ) - (func $other2 (type $T) (result i32) - (i32.const 0) - ) - (func $other3 (type $S) (result i32) - (i32.const 0) - ) -) -(module - (memory 0) - (type $S (func (result i32))) - (type $1 (func (param i32))) - (func $keep2-similar-but-func-sig-differs (type $1) (param $i i32) - (drop - (i32.const 0) - ) - ) - (func $other1 (type $1) (param $i i32) - (drop - (i32.const 0) - ) - ) - (func $other2 (type $S) (result i32) - (i32.const 0) - ) - (func $other3 (type $S) (result i32) - (i32.const 0) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $keep2 (type $0) - (nop) - ) - (func $other (type $0) - (nop) - (nop) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $erase (type $0) - (block $block0 - ) - ) - (func $other (type $0) - (block $block0 - ) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $keep2 (type $0) - (block $block0 - ) - ) - (func $other (type $0) - (block $block0 - (nop) - ) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $erase (type $0) - (block $block0 - (nop) - ) - ) - (func $other (type $0) - (block $block0 - (nop) - ) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $keep2 (type $0) - (block $block0 - (nop) - ) - ) - (func $other (type $0) - (block $block0 - (nop) - (unreachable) - ) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $keep2 (type $0) - (block $block0 - (nop) - ) - ) - (func $other (type $0) - (block $block0 - (unreachable) - ) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $erase-since-block-names-do-not-matter (type $0) - (block $foo - ) - ) - (func $other (type $0) - (block $bar - ) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $erase-since-block-names-do-not-matter (type $0) - (block $foo - (br $foo) - (br_table $foo $foo - (i32.const 0) - ) - ) - ) - (func $other (type $0) - (block $bar - (br $bar) - (br_table $bar $bar - (i32.const 0) - ) - ) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $keep2 (type $0) - (block $foo - (block - (drop - (i32.const 0) - ) - (br $foo) - ) - ) - ) - (func $other (type $0) - (block $bar - (block - (drop - (i32.const 1) - ) - (br $bar) - ) - ) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $keep2 (type $0) - (block $foo - (br_if $foo - (i32.const 0) - ) - ) - ) - (func $other (type $0) - (block $bar - (br_if $bar - (i32.const 1) - ) - ) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $erase (type $0) - (block $foo - (br_if $foo - (i32.const 0) - ) - ) - ) - (func $other (type $0) - (block $bar - (br_if $bar - (i32.const 0) - ) - ) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $keep2 (type $0) - (block $foo - (br_table $foo $foo - (i32.const 0) - ) - ) - ) - (func $other (type $0) - (block $bar - (br_table $bar $bar - (i32.const 1) - ) - ) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $erase (type $0) - (loop $bar - (nop) - ) - ) - (func $other (type $0) - (loop $sjc - (nop) - ) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $keep2 (type $0) - (drop - (block $foo (result i32) - (br_table $foo $foo - (i32.const 0) - (i32.const 0) - ) - ) - ) - ) - (func $other (type $0) - (drop - (block $bar (result i32) - (br_table $bar $bar - (i32.const 0) - (i32.const 1) - ) - ) - ) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $keep2 (type $0) - (block $foo - (block $bar - (br_table $foo $bar - (i32.const 0) - ) - ) - ) - ) - (func $other (type $0) - (block $bar - (block $foo - (br_table $bar $foo - (i32.const 0) - ) - ) - ) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $erase (type $0) - (block $foo - (block $bar - (br_table $foo $bar - (i32.const 0) - ) - ) - ) - ) - (func $other (type $0) - (block $bar - (block $foo - (br_table $foo $bar - (i32.const 0) - ) - ) - ) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $erase (type $0) - (call $erase) - ) - (func $other (type $0) - (call $erase) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $keep2-but-in-theory-we-could-erase (type $0) - (call $keep2-but-in-theory-we-could-erase) - ) - (func $other (type $0) - (call $other) - ) -) -(module - (memory 0) - (type $FUNCSIG$v (func)) - (import $i "env" "i") - (import $j "env" "j") - (func $erase (type $FUNCSIG$v) - (call $i) - ) - (func $other (type $FUNCSIG$v) - (call $i) - ) -) -(module - (memory 0) - (type $FUNCSIG$v (func)) - (import $i "env" "i") - (import $j "env" "j") - (func $keep2 (type $FUNCSIG$v) - (call $i) - ) - (func $other (type $FUNCSIG$v) - (call $j) - ) -) -(module - (memory 0) - (type $T (func)) - (table 2 2 anyfunc) - (elem (i32.const 0) $erase $other) - (func $erase (type $T) - (call_indirect (type $T) - (i32.const 0) - ) - ) - (func $other (type $T) - (call_indirect (type $T) - (i32.const 0) - ) - ) -) -(module - (memory 0) - (type $T (func)) - (table 2 2 anyfunc) - (elem (i32.const 0) $keep2 $other) - (func $keep2 (type $T) - (call_indirect (type $T) - (i32.const 0) - ) - ) - (func $other (type $T) - (call_indirect (type $T) - (i32.const 1) - ) - ) -) -(module - (memory 0) - (type $T (func)) - (type $S (func)) - (table 2 2 anyfunc) - (elem (i32.const 0) $keep2 $other) - (func $keep2 (type $T) - (call_indirect (type $T) - (i32.const 0) - ) - ) - (func $other (type $T) - (call_indirect (type $S) - (i32.const 0) - ) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $erase-even-locals-with-different-names (type $0) - (local $i i32) - (drop - (get_local $i) - ) - ) - (func $other (type $0) - (local $j i32) - (drop - (get_local $j) - ) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $keep2 (type $0) - (local $i i32) - (drop - (get_local $i) - ) - ) - (func $other (type $0) - (local $j i64) - (drop - (get_local $j) - ) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $erase-even-locals-with-different-names (type $0) - (local $i i32) - (set_local $i - (i32.const 0) - ) - ) - (func $other (type $0) - (local $j i32) - (set_local $j - (i32.const 0) - ) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $keep2 (type $0) - (local $i i32) - (set_local $i - (i32.const 0) - ) - ) - (func $other (type $0) - (local $j i64) - (set_local $j - (i64.const 0) - ) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $keep2 (type $0) - (local $i i32) - (set_local $i - (i32.const 0) - ) - ) - (func $other (type $0) - (local $j i32) - (set_local $j - (i32.const 1) - ) - ) -) -(module - (memory 10) - (type $0 (func)) - (func $erase (type $0) - (drop - (i32.load - (i32.const 0) - ) - ) - (drop - (i32.load16_s offset=3 align=2 - (i32.const 0) - ) - ) - ) - (func $other (type $0) - (drop - (i32.load - (i32.const 0) - ) - ) - (drop - (i32.load16_s offset=3 align=2 - (i32.const 0) - ) - ) - ) -) -(module - (memory 10) - (type $0 (func)) - (func $keep2 (type $0) - (drop - (i32.load offset=3 - (i32.const 0) - ) - ) - ) - (func $other (type $0) - (drop - (i32.load16_s offset=3 align=2 - (i32.const 0) - ) - ) - ) -) -(module - (memory 10) - (type $0 (func)) - (func $keep2 (type $0) - (drop - (i32.load16_s offset=3 - (i32.const 0) - ) - ) - ) - (func $other (type $0) - (drop - (i32.load16_s offset=3 align=1 - (i32.const 0) - ) - ) - ) -) -(module - (memory 10) - (type $0 (func)) - (func $keep2 (type $0) - (drop - (i32.load16_s align=2 - (i32.const 0) - ) - ) - ) - (func $other (type $0) - (drop - (i32.load16_s offset=3 align=2 - (i32.const 0) - ) - ) - ) -) -(module - (memory 10) - (type $0 (func)) - (func $keep2 (type $0) - (drop - (i32.load16_s offset=3 align=2 - (i32.const 0) - ) - ) - ) - (func $other (type $0) - (drop - (i32.load16_s offset=3 align=2 - (i32.const 1) - ) - ) - ) -) -(module - (memory 10) - (type $0 (func)) - (func $keep2 (type $0) - (drop - (i32.load16_u offset=3 align=2 - (i32.const 0) - ) - ) - ) - (func $other (type $0) - (drop - (i32.load16_s offset=3 align=2 - (i32.const 0) - ) - ) - ) -) -(module - (memory 10) - (type $0 (func)) - (func $erase (type $0) - (i32.store - (i32.const 0) - (i32.const 100) - ) - (i32.store16 offset=3 align=2 - (i32.const 0) - (i32.const 100) - ) - ) - (func $other (type $0) - (i32.store - (i32.const 0) - (i32.const 100) - ) - (i32.store16 offset=3 align=2 - (i32.const 0) - (i32.const 100) - ) - ) -) -(module - (memory 10) - (type $0 (func)) - (func $keep2 (type $0) - (i32.store32 offset=3 - (i32.const 0) - (i32.const 100) - ) - ) - (func $other (type $0) - (i32.store16 offset=3 align=2 - (i32.const 0) - (i32.const 100) - ) - ) -) -(module - (memory 10) - (type $0 (func)) - (func $keep2 (type $0) - (i32.store16 offset=3 - (i32.const 0) - (i32.const 100) - ) - ) - (func $other (type $0) - (i32.store16 offset=3 align=1 - (i32.const 0) - (i32.const 100) - ) - ) -) -(module - (memory 10) - (type $0 (func)) - (func $keep2 (type $0) - (i32.store16 align=2 - (i32.const 0) - (i32.const 100) - ) - ) - (func $other (type $0) - (i32.store16 offset=3 align=2 - (i32.const 0) - (i32.const 100) - ) - ) -) -(module - (memory 10) - (type $0 (func)) - (func $keep2 (type $0) - (i32.store16 offset=3 align=2 - (i32.const 0) - (i32.const 100) - ) - ) - (func $other (type $0) - (i32.store16 offset=3 align=2 - (i32.const 1) - (i32.const 100) - ) - ) -) -(module - (memory 10) - (type $0 (func)) - (func $keep2 (type $0) - (i32.store16 offset=3 align=2 - (i32.const 0) - (i32.const 100) - ) - ) - (func $other (type $0) - (i32.store16 offset=3 align=2 - (i32.const 0) - (i32.const 101) - ) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $keep2 (type $0) - (drop - (i32.const 0) - ) - ) - (func $other (type $0) - (drop - (i64.const 0) - ) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $keep2 (type $0) - (drop - (i32.const 0) - ) - ) - (func $other (type $0) - (drop - (f32.const 0) - ) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $keep2 (type $0) - (drop - (i32.const 0) - ) - ) - (func $other (type $0) - (drop - (f64.const 0) - ) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $keep2 (type $0) - (drop - (i64.const 0) - ) - ) - (func $other (type $0) - (drop - (i64.const 1) - ) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $keep2 (type $0) - (drop - (f32.const 0.10000000149011612) - ) - ) - (func $other (type $0) - (drop - (f32.const -0.10000000149011612) - ) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $keep2 (type $0) - (drop - (f64.const 0.1) - ) - ) - (func $other (type $0) - (drop - (f64.const 0.2) - ) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $erase (type $0) - (drop - (f32.abs - (f32.const 0) - ) - ) - ) - (func $other (type $0) - (drop - (f32.abs - (f32.const 0) - ) - ) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $keep2 (type $0) - (drop - (f32.abs - (f32.const 0) - ) - ) - ) - (func $other (type $0) - (drop - (f32.abs - (f32.const 1) - ) - ) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $keep2 (type $0) - (drop - (f32.abs - (f32.const 0) - ) - ) - ) - (func $other (type $0) - (drop - (f32.neg - (f32.const 0) - ) - ) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $erase (type $0) - (drop - (f32.add - (f32.const 0) - (f32.const 0) - ) - ) - ) - (func $other (type $0) - (drop - (f32.add - (f32.const 0) - (f32.const 0) - ) - ) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $keep2 (type $0) - (drop - (f32.add - (f32.const 0) - (f32.const 0) - ) - ) - ) - (func $other (type $0) - (drop - (f32.add - (f32.const 0) - (f32.const 1) - ) - ) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $keep2 (type $0) - (drop - (f32.add - (f32.const 0) - (f32.const 0) - ) - ) - ) - (func $other (type $0) - (drop - (f32.add - (f32.const 1) - (f32.const 0) - ) - ) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $keep2 (type $0) - (drop - (f32.add - (f32.const 0) - (f32.const 0) - ) - ) - ) - (func $other (type $0) - (drop - (f32.sub - (f32.const 0) - (f32.const 0) - ) - ) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $erase (type $0) - (drop - (select - (i32.const 0) - (i32.const 0) - (i32.const 0) - ) - ) - ) - (func $other (type $0) - (drop - (select - (i32.const 0) - (i32.const 0) - (i32.const 0) - ) - ) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $keep (type $0) - (drop - (select - (i32.const 0) - (i32.const 0) - (i32.const 0) - ) - ) - ) - (func $other (type $0) - (drop - (select - (i32.const 1) - (i32.const 0) - (i32.const 0) - ) - ) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $keep (type $0) - (drop - (select - (i32.const 0) - (i32.const 0) - (i32.const 0) - ) - ) - ) - (func $other (type $0) - (drop - (select - (i32.const 0) - (i32.const 2) - (i32.const 0) - ) - ) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $keep (type $0) - (drop - (select - (i32.const 0) - (i32.const 0) - (i32.const 0) - ) - ) - ) - (func $other (type $0) - (drop - (select - (i32.const 0) - (i32.const 0) - (i32.const 3) - ) - ) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $erase (type $0) - (return) - ) - (func $other (type $0) - (return) - ) -) -(module - (memory 0) - (type $0 (func (result i32))) - (func $erase (type $0) (result i32) - (return - (i32.const 0) - ) - ) - (func $other (type $0) (result i32) - (return - (i32.const 0) - ) - ) -) -(module - (memory 0) - (type $0 (func (result i32))) - (func $keep (type $0) (result i32) - (return - (i32.const 0) - ) - ) - (func $other (type $0) (result i32) - (return - (i32.const 1) - ) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $erase (type $0) - (drop - (current_memory) - ) - ) - (func $other (type $0) - (drop - (current_memory) - ) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $erase (type $0) - (drop - (grow_memory - (i32.const 10) - ) - ) - ) - (func $other (type $0) - (drop - (grow_memory - (i32.const 10) - ) - ) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $keep (type $0) - (drop - (grow_memory - (i32.const 10) - ) - ) - ) - (func $other (type $0) - (drop - (grow_memory - (i32.const 11) - ) - ) - ) -) -(module - (memory 0) - (type $0 (func)) - (func $keep (type $0) - (drop - (current_memory) - ) - ) - (func $other (type $0) - (drop - (grow_memory - (i32.const 10) - ) - ) - ) -) diff --git a/test/passes/duplicate-function-elimination_optimize-level=1.txt b/test/passes/duplicate-function-elimination_optimize-level=1.txt new file mode 100644 index 000000000..c44b4cc28 --- /dev/null +++ b/test/passes/duplicate-function-elimination_optimize-level=1.txt @@ -0,0 +1,1068 @@ +(module + (type $0 (func)) + (memory $0 0) + (func $erase (; 0 ;) (type $0) + (nop) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (drop + (i32.const 0) + ) + ) + (func $other (; 1 ;) (type $0) + (nop) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $erase (; 0 ;) (type $0) + (drop + (i32.const 0) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (drop + (i32.const 0) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (i32.const 1) + ) + ) +) +(module + (type $0 (func)) + (table 3 3 anyfunc) + (elem (i32.const 0) $keep2 $keep2 $caller) + (memory $0 0) + (export "keep2" (func $keep2)) + (export "other" (func $keep2)) + (start $keep2) + (func $keep2 (; 0 ;) (type $0) + (nop) + ) + (func $caller (; 1 ;) (type $0) + (call $keep2) + (call $keep2) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2-after-two-passes (; 0 ;) (type $0) + (nop) + ) + (func $keep-caller (; 1 ;) (type $0) + (call $keep2-after-two-passes) + ) + (func $other-caller (; 2 ;) (type $0) + (call $keep2-after-two-passes) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep-4 (; 0 ;) (type $0) + (nop) + ) + (func $other (; 1 ;) (type $0) + (unreachable) + ) + (func $keep-caller (; 2 ;) (type $0) + (call $keep-4) + ) + (func $other-caller (; 3 ;) (type $0) + (call $other) + ) +) +(module + (type $T (func (result i32))) + (type $S (func (result i32))) + (type $2 (func)) + (type $3 (func (param i32))) + (memory $0 0) + (func $keep4-similar-but-func-sig-differs (; 0 ;) (type $2) + (drop + (i32.const 0) + ) + ) + (func $other1 (; 1 ;) (type $3) (param $i i32) + (drop + (i32.const 0) + ) + ) + (func $other2 (; 2 ;) (type $T) (result i32) + (i32.const 0) + ) + (func $other3 (; 3 ;) (type $S) (result i32) + (i32.const 0) + ) +) +(module + (type $S (func (result i32))) + (type $1 (func (param i32))) + (memory $0 0) + (func $keep2-similar-but-func-sig-differs (; 0 ;) (type $1) (param $i i32) + (drop + (i32.const 0) + ) + ) + (func $other2 (; 1 ;) (type $S) (result i32) + (i32.const 0) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (nop) + ) + (func $other (; 1 ;) (type $0) + (nop) + (nop) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $erase (; 0 ;) (type $0) + (block $block0 + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (block $block0 + ) + ) + (func $other (; 1 ;) (type $0) + (block $block0 + (nop) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $erase (; 0 ;) (type $0) + (block $block0 + (nop) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (block $block0 + (nop) + ) + ) + (func $other (; 1 ;) (type $0) + (block $block0 + (nop) + (unreachable) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (block $block0 + (nop) + ) + ) + (func $other (; 1 ;) (type $0) + (block $block0 + (unreachable) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $erase-since-block-names-do-not-matter (; 0 ;) (type $0) + (block $foo + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $erase-since-block-names-do-not-matter (; 0 ;) (type $0) + (block $foo + (br $foo) + (br_table $foo $foo + (i32.const 0) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (block $foo + (block $block + (drop + (i32.const 0) + ) + (br $foo) + ) + ) + ) + (func $other (; 1 ;) (type $0) + (block $bar + (block $block + (drop + (i32.const 1) + ) + (br $bar) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (block $foo + (br_if $foo + (i32.const 0) + ) + ) + ) + (func $other (; 1 ;) (type $0) + (block $bar + (br_if $bar + (i32.const 1) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $erase (; 0 ;) (type $0) + (block $foo + (br_if $foo + (i32.const 0) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (block $foo + (br_table $foo $foo + (i32.const 0) + ) + ) + ) + (func $other (; 1 ;) (type $0) + (block $bar + (br_table $bar $bar + (i32.const 1) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $erase (; 0 ;) (type $0) + (loop $bar + (nop) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (drop + (block $foo (result i32) + (br_table $foo $foo + (i32.const 0) + (i32.const 0) + ) + ) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (block $bar (result i32) + (br_table $bar $bar + (i32.const 0) + (i32.const 1) + ) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (block $foo + (block $bar + (br_table $foo $bar + (i32.const 0) + ) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $erase (; 0 ;) (type $0) + (block $foo + (block $bar + (br_table $foo $bar + (i32.const 0) + ) + ) + ) + ) + (func $other (; 1 ;) (type $0) + (block $bar + (block $foo + (br_table $foo $bar + (i32.const 0) + ) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $erase (; 0 ;) (type $0) + (call $erase) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2-but-in-theory-we-could-erase (; 0 ;) (type $0) + (call $keep2-but-in-theory-we-could-erase) + ) + (func $other (; 1 ;) (type $0) + (call $other) + ) +) +(module + (type $FUNCSIG$v (func)) + (import "env" "i" (func $i)) + (import "env" "j" (func $j)) + (memory $0 0) + (func $erase (; 2 ;) (type $FUNCSIG$v) + (call $i) + ) +) +(module + (type $FUNCSIG$v (func)) + (import "env" "i" (func $i)) + (import "env" "j" (func $j)) + (memory $0 0) + (func $keep2 (; 2 ;) (type $FUNCSIG$v) + (call $i) + ) + (func $other (; 3 ;) (type $FUNCSIG$v) + (call $j) + ) +) +(module + (type $T (func)) + (table 2 2 anyfunc) + (elem (i32.const 0) $erase $erase) + (memory $0 0) + (func $erase (; 0 ;) (type $T) + (call_indirect (type $T) + (i32.const 0) + ) + ) +) +(module + (type $T (func)) + (table 2 2 anyfunc) + (elem (i32.const 0) $keep2 $other) + (memory $0 0) + (func $keep2 (; 0 ;) (type $T) + (call_indirect (type $T) + (i32.const 0) + ) + ) + (func $other (; 1 ;) (type $T) + (call_indirect (type $T) + (i32.const 1) + ) + ) +) +(module + (type $T (func)) + (type $S (func)) + (table 2 2 anyfunc) + (elem (i32.const 0) $keep2 $other) + (memory $0 0) + (func $keep2 (; 0 ;) (type $T) + (call_indirect (type $T) + (i32.const 0) + ) + ) + (func $other (; 1 ;) (type $T) + (call_indirect (type $S) + (i32.const 0) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $erase-even-locals-with-different-names (; 0 ;) (type $0) + (local $i i32) + (drop + (get_local $i) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (local $i i32) + (drop + (get_local $i) + ) + ) + (func $other (; 1 ;) (type $0) + (local $j i64) + (drop + (get_local $j) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $erase-even-locals-with-different-names (; 0 ;) (type $0) + (local $i i32) + (set_local $i + (i32.const 0) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (local $i i32) + (set_local $i + (i32.const 0) + ) + ) + (func $other (; 1 ;) (type $0) + (local $j i64) + (set_local $j + (i64.const 0) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (local $i i32) + (set_local $i + (i32.const 0) + ) + ) + (func $other (; 1 ;) (type $0) + (local $j i32) + (set_local $j + (i32.const 1) + ) + ) +) +(module + (type $0 (func)) + (memory $0 10) + (func $erase (; 0 ;) (type $0) + (drop + (i32.load + (i32.const 0) + ) + ) + (drop + (i32.load16_s offset=3 + (i32.const 0) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 10) + (func $keep2 (; 0 ;) (type $0) + (drop + (i32.load offset=3 + (i32.const 0) + ) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (i32.load16_s offset=3 + (i32.const 0) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 10) + (func $keep2 (; 0 ;) (type $0) + (drop + (i32.load16_s offset=3 + (i32.const 0) + ) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (i32.load16_s offset=3 align=1 + (i32.const 0) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 10) + (func $keep2 (; 0 ;) (type $0) + (drop + (i32.load16_s + (i32.const 0) + ) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (i32.load16_s offset=3 + (i32.const 0) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 10) + (func $keep2 (; 0 ;) (type $0) + (drop + (i32.load16_s offset=3 + (i32.const 0) + ) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (i32.load16_s offset=3 + (i32.const 1) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 10) + (func $keep2 (; 0 ;) (type $0) + (drop + (i32.load16_u offset=3 + (i32.const 0) + ) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (i32.load16_s offset=3 + (i32.const 0) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 10) + (func $erase (; 0 ;) (type $0) + (i32.store + (i32.const 0) + (i32.const 100) + ) + (i32.store16 offset=3 + (i32.const 0) + (i32.const 100) + ) + ) +) +(module + (type $0 (func)) + (memory $0 10) + (func $keep2 (; 0 ;) (type $0) + (i32.store offset=3 + (i32.const 0) + (i32.const 100) + ) + ) + (func $other (; 1 ;) (type $0) + (i32.store16 offset=3 + (i32.const 0) + (i32.const 100) + ) + ) +) +(module + (type $0 (func)) + (memory $0 10) + (func $keep2 (; 0 ;) (type $0) + (i32.store16 offset=3 + (i32.const 0) + (i32.const 100) + ) + ) + (func $other (; 1 ;) (type $0) + (i32.store16 offset=3 align=1 + (i32.const 0) + (i32.const 100) + ) + ) +) +(module + (type $0 (func)) + (memory $0 10) + (func $keep2 (; 0 ;) (type $0) + (i32.store16 + (i32.const 0) + (i32.const 100) + ) + ) + (func $other (; 1 ;) (type $0) + (i32.store16 offset=3 + (i32.const 0) + (i32.const 100) + ) + ) +) +(module + (type $0 (func)) + (memory $0 10) + (func $keep2 (; 0 ;) (type $0) + (i32.store16 offset=3 + (i32.const 0) + (i32.const 100) + ) + ) + (func $other (; 1 ;) (type $0) + (i32.store16 offset=3 + (i32.const 1) + (i32.const 100) + ) + ) +) +(module + (type $0 (func)) + (memory $0 10) + (func $keep2 (; 0 ;) (type $0) + (i32.store16 offset=3 + (i32.const 0) + (i32.const 100) + ) + ) + (func $other (; 1 ;) (type $0) + (i32.store16 offset=3 + (i32.const 0) + (i32.const 101) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (drop + (i32.const 0) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (i64.const 0) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (drop + (i32.const 0) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (f32.const 0) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (drop + (i32.const 0) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (f64.const 0) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (drop + (i64.const 0) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (i64.const 1) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (drop + (f32.const 0.10000000149011612) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (f32.const -0.10000000149011612) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (drop + (f64.const 0.1) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (f64.const 0.2) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $erase (; 0 ;) (type $0) + (drop + (f32.abs + (f32.const 0) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (drop + (f32.abs + (f32.const 0) + ) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (f32.abs + (f32.const 1) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (drop + (f32.abs + (f32.const 0) + ) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (f32.neg + (f32.const 0) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $erase (; 0 ;) (type $0) + (drop + (f32.add + (f32.const 0) + (f32.const 0) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (drop + (f32.add + (f32.const 0) + (f32.const 0) + ) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (f32.add + (f32.const 0) + (f32.const 1) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (drop + (f32.add + (f32.const 0) + (f32.const 0) + ) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (f32.add + (f32.const 1) + (f32.const 0) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (drop + (f32.add + (f32.const 0) + (f32.const 0) + ) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (f32.sub + (f32.const 0) + (f32.const 0) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $erase (; 0 ;) (type $0) + (drop + (select + (i32.const 0) + (i32.const 0) + (i32.const 0) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep (; 0 ;) (type $0) + (drop + (select + (i32.const 0) + (i32.const 0) + (i32.const 0) + ) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (select + (i32.const 1) + (i32.const 0) + (i32.const 0) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep (; 0 ;) (type $0) + (drop + (select + (i32.const 0) + (i32.const 0) + (i32.const 0) + ) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (select + (i32.const 0) + (i32.const 2) + (i32.const 0) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep (; 0 ;) (type $0) + (drop + (select + (i32.const 0) + (i32.const 0) + (i32.const 0) + ) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (select + (i32.const 0) + (i32.const 0) + (i32.const 3) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $erase (; 0 ;) (type $0) + (return) + ) +) +(module + (type $0 (func (result i32))) + (memory $0 0) + (func $erase (; 0 ;) (type $0) (result i32) + (return + (i32.const 0) + ) + ) +) +(module + (type $0 (func (result i32))) + (memory $0 0) + (func $keep (; 0 ;) (type $0) (result i32) + (return + (i32.const 0) + ) + ) + (func $other (; 1 ;) (type $0) (result i32) + (return + (i32.const 1) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $erase (; 0 ;) (type $0) + (drop + (current_memory) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $erase (; 0 ;) (type $0) + (drop + (grow_memory + (i32.const 10) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep (; 0 ;) (type $0) + (drop + (grow_memory + (i32.const 10) + ) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (grow_memory + (i32.const 11) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep (; 0 ;) (type $0) + (drop + (current_memory) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (grow_memory + (i32.const 10) + ) + ) + ) +) diff --git a/test/passes/duplicate-function-elimination_optimize-level=1.wast b/test/passes/duplicate-function-elimination_optimize-level=1.wast new file mode 100644 index 000000000..b79032155 --- /dev/null +++ b/test/passes/duplicate-function-elimination_optimize-level=1.wast @@ -0,0 +1,1221 @@ +(module + (memory 0) + (type $0 (func)) + (func $erase (type $0) + (nop) + ) + (func $other (type $0) + (nop) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (i32.const 0) + ) + ) + (func $other (type $0) + (nop) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $erase (type $0) + (drop + (i32.const 0) + ) + ) + (func $other (type $0) + (drop + (i32.const 0) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (i32.const 0) + ) + ) + (func $other (type $0) + (drop + (i32.const 1) + ) + ) +) +(module + (memory 0) + (start $other) + (type $0 (func)) + (export "keep2" $keep2) + (export "other" $other) + (table 3 3 anyfunc) + (elem (i32.const 0) $keep2 $other $caller) + (func $keep2 (type $0) + (nop) + ) + (func $other (type $0) + (nop) + ) + (func $caller (type $0) + (call $keep2) + (call $other) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2-after-two-passes (type $0) + (nop) + ) + (func $other (type $0) + (nop) + ) + (func $keep-caller (type $0) + (call $keep2-after-two-passes) + ) + (func $other-caller (type $0) + (call $other) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep-4 (type $0) + (nop) + ) + (func $other (type $0) + (unreachable) + ) + (func $keep-caller (type $0) + (call $keep-4) + ) + (func $other-caller (type $0) + (call $other) + ) +) +(module + (memory 0) + (type $T (func (result i32))) + (type $S (func (result i32))) + (type $2 (func)) + (type $3 (func (param i32))) + (func $keep4-similar-but-func-sig-differs (type $2) + (drop + (i32.const 0) + ) + ) + (func $other1 (type $3) (param $i i32) + (drop + (i32.const 0) + ) + ) + (func $other2 (type $T) (result i32) + (i32.const 0) + ) + (func $other3 (type $S) (result i32) + (i32.const 0) + ) +) +(module + (memory 0) + (type $S (func (result i32))) + (type $1 (func (param i32))) + (func $keep2-similar-but-func-sig-differs (type $1) (param $i i32) + (drop + (i32.const 0) + ) + ) + (func $other1 (type $1) (param $i i32) + (drop + (i32.const 0) + ) + ) + (func $other2 (type $S) (result i32) + (i32.const 0) + ) + (func $other3 (type $S) (result i32) + (i32.const 0) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (nop) + ) + (func $other (type $0) + (nop) + (nop) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $erase (type $0) + (block $block0 + ) + ) + (func $other (type $0) + (block $block0 + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (block $block0 + ) + ) + (func $other (type $0) + (block $block0 + (nop) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $erase (type $0) + (block $block0 + (nop) + ) + ) + (func $other (type $0) + (block $block0 + (nop) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (block $block0 + (nop) + ) + ) + (func $other (type $0) + (block $block0 + (nop) + (unreachable) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (block $block0 + (nop) + ) + ) + (func $other (type $0) + (block $block0 + (unreachable) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $erase-since-block-names-do-not-matter (type $0) + (block $foo + ) + ) + (func $other (type $0) + (block $bar + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $erase-since-block-names-do-not-matter (type $0) + (block $foo + (br $foo) + (br_table $foo $foo + (i32.const 0) + ) + ) + ) + (func $other (type $0) + (block $bar + (br $bar) + (br_table $bar $bar + (i32.const 0) + ) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (block $foo + (block + (drop + (i32.const 0) + ) + (br $foo) + ) + ) + ) + (func $other (type $0) + (block $bar + (block + (drop + (i32.const 1) + ) + (br $bar) + ) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (block $foo + (br_if $foo + (i32.const 0) + ) + ) + ) + (func $other (type $0) + (block $bar + (br_if $bar + (i32.const 1) + ) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $erase (type $0) + (block $foo + (br_if $foo + (i32.const 0) + ) + ) + ) + (func $other (type $0) + (block $bar + (br_if $bar + (i32.const 0) + ) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (block $foo + (br_table $foo $foo + (i32.const 0) + ) + ) + ) + (func $other (type $0) + (block $bar + (br_table $bar $bar + (i32.const 1) + ) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $erase (type $0) + (loop $bar + (nop) + ) + ) + (func $other (type $0) + (loop $sjc + (nop) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (block $foo (result i32) + (br_table $foo $foo + (i32.const 0) + (i32.const 0) + ) + ) + ) + ) + (func $other (type $0) + (drop + (block $bar (result i32) + (br_table $bar $bar + (i32.const 0) + (i32.const 1) + ) + ) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (block $foo + (block $bar + (br_table $foo $bar + (i32.const 0) + ) + ) + ) + ) + (func $other (type $0) + (block $bar + (block $foo + (br_table $bar $foo + (i32.const 0) + ) + ) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $erase (type $0) + (block $foo + (block $bar + (br_table $foo $bar + (i32.const 0) + ) + ) + ) + ) + (func $other (type $0) + (block $bar + (block $foo + (br_table $foo $bar + (i32.const 0) + ) + ) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $erase (type $0) + (call $erase) + ) + (func $other (type $0) + (call $erase) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2-but-in-theory-we-could-erase (type $0) + (call $keep2-but-in-theory-we-could-erase) + ) + (func $other (type $0) + (call $other) + ) +) +(module + (memory 0) + (type $FUNCSIG$v (func)) + (import $i "env" "i") + (import $j "env" "j") + (func $erase (type $FUNCSIG$v) + (call $i) + ) + (func $other (type $FUNCSIG$v) + (call $i) + ) +) +(module + (memory 0) + (type $FUNCSIG$v (func)) + (import $i "env" "i") + (import $j "env" "j") + (func $keep2 (type $FUNCSIG$v) + (call $i) + ) + (func $other (type $FUNCSIG$v) + (call $j) + ) +) +(module + (memory 0) + (type $T (func)) + (table 2 2 anyfunc) + (elem (i32.const 0) $erase $other) + (func $erase (type $T) + (call_indirect (type $T) + (i32.const 0) + ) + ) + (func $other (type $T) + (call_indirect (type $T) + (i32.const 0) + ) + ) +) +(module + (memory 0) + (type $T (func)) + (table 2 2 anyfunc) + (elem (i32.const 0) $keep2 $other) + (func $keep2 (type $T) + (call_indirect (type $T) + (i32.const 0) + ) + ) + (func $other (type $T) + (call_indirect (type $T) + (i32.const 1) + ) + ) +) +(module + (memory 0) + (type $T (func)) + (type $S (func)) + (table 2 2 anyfunc) + (elem (i32.const 0) $keep2 $other) + (func $keep2 (type $T) + (call_indirect (type $T) + (i32.const 0) + ) + ) + (func $other (type $T) + (call_indirect (type $S) + (i32.const 0) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $erase-even-locals-with-different-names (type $0) + (local $i i32) + (drop + (get_local $i) + ) + ) + (func $other (type $0) + (local $j i32) + (drop + (get_local $j) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (local $i i32) + (drop + (get_local $i) + ) + ) + (func $other (type $0) + (local $j i64) + (drop + (get_local $j) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $erase-even-locals-with-different-names (type $0) + (local $i i32) + (set_local $i + (i32.const 0) + ) + ) + (func $other (type $0) + (local $j i32) + (set_local $j + (i32.const 0) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (local $i i32) + (set_local $i + (i32.const 0) + ) + ) + (func $other (type $0) + (local $j i64) + (set_local $j + (i64.const 0) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (local $i i32) + (set_local $i + (i32.const 0) + ) + ) + (func $other (type $0) + (local $j i32) + (set_local $j + (i32.const 1) + ) + ) +) +(module + (memory 10) + (type $0 (func)) + (func $erase (type $0) + (drop + (i32.load + (i32.const 0) + ) + ) + (drop + (i32.load16_s offset=3 align=2 + (i32.const 0) + ) + ) + ) + (func $other (type $0) + (drop + (i32.load + (i32.const 0) + ) + ) + (drop + (i32.load16_s offset=3 align=2 + (i32.const 0) + ) + ) + ) +) +(module + (memory 10) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (i32.load offset=3 + (i32.const 0) + ) + ) + ) + (func $other (type $0) + (drop + (i32.load16_s offset=3 align=2 + (i32.const 0) + ) + ) + ) +) +(module + (memory 10) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (i32.load16_s offset=3 + (i32.const 0) + ) + ) + ) + (func $other (type $0) + (drop + (i32.load16_s offset=3 align=1 + (i32.const 0) + ) + ) + ) +) +(module + (memory 10) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (i32.load16_s align=2 + (i32.const 0) + ) + ) + ) + (func $other (type $0) + (drop + (i32.load16_s offset=3 align=2 + (i32.const 0) + ) + ) + ) +) +(module + (memory 10) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (i32.load16_s offset=3 align=2 + (i32.const 0) + ) + ) + ) + (func $other (type $0) + (drop + (i32.load16_s offset=3 align=2 + (i32.const 1) + ) + ) + ) +) +(module + (memory 10) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (i32.load16_u offset=3 align=2 + (i32.const 0) + ) + ) + ) + (func $other (type $0) + (drop + (i32.load16_s offset=3 align=2 + (i32.const 0) + ) + ) + ) +) +(module + (memory 10) + (type $0 (func)) + (func $erase (type $0) + (i32.store + (i32.const 0) + (i32.const 100) + ) + (i32.store16 offset=3 align=2 + (i32.const 0) + (i32.const 100) + ) + ) + (func $other (type $0) + (i32.store + (i32.const 0) + (i32.const 100) + ) + (i32.store16 offset=3 align=2 + (i32.const 0) + (i32.const 100) + ) + ) +) +(module + (memory 10) + (type $0 (func)) + (func $keep2 (type $0) + (i32.store32 offset=3 + (i32.const 0) + (i32.const 100) + ) + ) + (func $other (type $0) + (i32.store16 offset=3 align=2 + (i32.const 0) + (i32.const 100) + ) + ) +) +(module + (memory 10) + (type $0 (func)) + (func $keep2 (type $0) + (i32.store16 offset=3 + (i32.const 0) + (i32.const 100) + ) + ) + (func $other (type $0) + (i32.store16 offset=3 align=1 + (i32.const 0) + (i32.const 100) + ) + ) +) +(module + (memory 10) + (type $0 (func)) + (func $keep2 (type $0) + (i32.store16 align=2 + (i32.const 0) + (i32.const 100) + ) + ) + (func $other (type $0) + (i32.store16 offset=3 align=2 + (i32.const 0) + (i32.const 100) + ) + ) +) +(module + (memory 10) + (type $0 (func)) + (func $keep2 (type $0) + (i32.store16 offset=3 align=2 + (i32.const 0) + (i32.const 100) + ) + ) + (func $other (type $0) + (i32.store16 offset=3 align=2 + (i32.const 1) + (i32.const 100) + ) + ) +) +(module + (memory 10) + (type $0 (func)) + (func $keep2 (type $0) + (i32.store16 offset=3 align=2 + (i32.const 0) + (i32.const 100) + ) + ) + (func $other (type $0) + (i32.store16 offset=3 align=2 + (i32.const 0) + (i32.const 101) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (i32.const 0) + ) + ) + (func $other (type $0) + (drop + (i64.const 0) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (i32.const 0) + ) + ) + (func $other (type $0) + (drop + (f32.const 0) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (i32.const 0) + ) + ) + (func $other (type $0) + (drop + (f64.const 0) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (i64.const 0) + ) + ) + (func $other (type $0) + (drop + (i64.const 1) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (f32.const 0.10000000149011612) + ) + ) + (func $other (type $0) + (drop + (f32.const -0.10000000149011612) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (f64.const 0.1) + ) + ) + (func $other (type $0) + (drop + (f64.const 0.2) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $erase (type $0) + (drop + (f32.abs + (f32.const 0) + ) + ) + ) + (func $other (type $0) + (drop + (f32.abs + (f32.const 0) + ) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (f32.abs + (f32.const 0) + ) + ) + ) + (func $other (type $0) + (drop + (f32.abs + (f32.const 1) + ) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (f32.abs + (f32.const 0) + ) + ) + ) + (func $other (type $0) + (drop + (f32.neg + (f32.const 0) + ) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $erase (type $0) + (drop + (f32.add + (f32.const 0) + (f32.const 0) + ) + ) + ) + (func $other (type $0) + (drop + (f32.add + (f32.const 0) + (f32.const 0) + ) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (f32.add + (f32.const 0) + (f32.const 0) + ) + ) + ) + (func $other (type $0) + (drop + (f32.add + (f32.const 0) + (f32.const 1) + ) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (f32.add + (f32.const 0) + (f32.const 0) + ) + ) + ) + (func $other (type $0) + (drop + (f32.add + (f32.const 1) + (f32.const 0) + ) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (f32.add + (f32.const 0) + (f32.const 0) + ) + ) + ) + (func $other (type $0) + (drop + (f32.sub + (f32.const 0) + (f32.const 0) + ) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $erase (type $0) + (drop + (select + (i32.const 0) + (i32.const 0) + (i32.const 0) + ) + ) + ) + (func $other (type $0) + (drop + (select + (i32.const 0) + (i32.const 0) + (i32.const 0) + ) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep (type $0) + (drop + (select + (i32.const 0) + (i32.const 0) + (i32.const 0) + ) + ) + ) + (func $other (type $0) + (drop + (select + (i32.const 1) + (i32.const 0) + (i32.const 0) + ) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep (type $0) + (drop + (select + (i32.const 0) + (i32.const 0) + (i32.const 0) + ) + ) + ) + (func $other (type $0) + (drop + (select + (i32.const 0) + (i32.const 2) + (i32.const 0) + ) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep (type $0) + (drop + (select + (i32.const 0) + (i32.const 0) + (i32.const 0) + ) + ) + ) + (func $other (type $0) + (drop + (select + (i32.const 0) + (i32.const 0) + (i32.const 3) + ) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $erase (type $0) + (return) + ) + (func $other (type $0) + (return) + ) +) +(module + (memory 0) + (type $0 (func (result i32))) + (func $erase (type $0) (result i32) + (return + (i32.const 0) + ) + ) + (func $other (type $0) (result i32) + (return + (i32.const 0) + ) + ) +) +(module + (memory 0) + (type $0 (func (result i32))) + (func $keep (type $0) (result i32) + (return + (i32.const 0) + ) + ) + (func $other (type $0) (result i32) + (return + (i32.const 1) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $erase (type $0) + (drop + (current_memory) + ) + ) + (func $other (type $0) + (drop + (current_memory) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $erase (type $0) + (drop + (grow_memory + (i32.const 10) + ) + ) + ) + (func $other (type $0) + (drop + (grow_memory + (i32.const 10) + ) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep (type $0) + (drop + (grow_memory + (i32.const 10) + ) + ) + ) + (func $other (type $0) + (drop + (grow_memory + (i32.const 11) + ) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep (type $0) + (drop + (current_memory) + ) + ) + (func $other (type $0) + (drop + (grow_memory + (i32.const 10) + ) + ) + ) +) diff --git a/test/passes/duplicate-function-elimination_optimize-level=2.txt b/test/passes/duplicate-function-elimination_optimize-level=2.txt new file mode 100644 index 000000000..baf4fedf2 --- /dev/null +++ b/test/passes/duplicate-function-elimination_optimize-level=2.txt @@ -0,0 +1,1065 @@ +(module + (type $0 (func)) + (memory $0 0) + (func $erase (; 0 ;) (type $0) + (nop) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (drop + (i32.const 0) + ) + ) + (func $other (; 1 ;) (type $0) + (nop) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $erase (; 0 ;) (type $0) + (drop + (i32.const 0) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (drop + (i32.const 0) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (i32.const 1) + ) + ) +) +(module + (type $0 (func)) + (table 3 3 anyfunc) + (elem (i32.const 0) $keep2 $keep2 $caller) + (memory $0 0) + (export "keep2" (func $keep2)) + (export "other" (func $keep2)) + (start $keep2) + (func $keep2 (; 0 ;) (type $0) + (nop) + ) + (func $caller (; 1 ;) (type $0) + (call $keep2) + (call $keep2) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2-after-two-passes (; 0 ;) (type $0) + (nop) + ) + (func $keep-caller (; 1 ;) (type $0) + (call $keep2-after-two-passes) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep-4 (; 0 ;) (type $0) + (nop) + ) + (func $other (; 1 ;) (type $0) + (unreachable) + ) + (func $keep-caller (; 2 ;) (type $0) + (call $keep-4) + ) + (func $other-caller (; 3 ;) (type $0) + (call $other) + ) +) +(module + (type $T (func (result i32))) + (type $S (func (result i32))) + (type $2 (func)) + (type $3 (func (param i32))) + (memory $0 0) + (func $keep4-similar-but-func-sig-differs (; 0 ;) (type $2) + (drop + (i32.const 0) + ) + ) + (func $other1 (; 1 ;) (type $3) (param $i i32) + (drop + (i32.const 0) + ) + ) + (func $other2 (; 2 ;) (type $T) (result i32) + (i32.const 0) + ) + (func $other3 (; 3 ;) (type $S) (result i32) + (i32.const 0) + ) +) +(module + (type $S (func (result i32))) + (type $1 (func (param i32))) + (memory $0 0) + (func $keep2-similar-but-func-sig-differs (; 0 ;) (type $1) (param $i i32) + (drop + (i32.const 0) + ) + ) + (func $other2 (; 1 ;) (type $S) (result i32) + (i32.const 0) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (nop) + ) + (func $other (; 1 ;) (type $0) + (nop) + (nop) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $erase (; 0 ;) (type $0) + (block $block0 + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (block $block0 + ) + ) + (func $other (; 1 ;) (type $0) + (block $block0 + (nop) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $erase (; 0 ;) (type $0) + (block $block0 + (nop) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (block $block0 + (nop) + ) + ) + (func $other (; 1 ;) (type $0) + (block $block0 + (nop) + (unreachable) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (block $block0 + (nop) + ) + ) + (func $other (; 1 ;) (type $0) + (block $block0 + (unreachable) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $erase-since-block-names-do-not-matter (; 0 ;) (type $0) + (block $foo + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $erase-since-block-names-do-not-matter (; 0 ;) (type $0) + (block $foo + (br $foo) + (br_table $foo $foo + (i32.const 0) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (block $foo + (block $block + (drop + (i32.const 0) + ) + (br $foo) + ) + ) + ) + (func $other (; 1 ;) (type $0) + (block $bar + (block $block + (drop + (i32.const 1) + ) + (br $bar) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (block $foo + (br_if $foo + (i32.const 0) + ) + ) + ) + (func $other (; 1 ;) (type $0) + (block $bar + (br_if $bar + (i32.const 1) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $erase (; 0 ;) (type $0) + (block $foo + (br_if $foo + (i32.const 0) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (block $foo + (br_table $foo $foo + (i32.const 0) + ) + ) + ) + (func $other (; 1 ;) (type $0) + (block $bar + (br_table $bar $bar + (i32.const 1) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $erase (; 0 ;) (type $0) + (loop $bar + (nop) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (drop + (block $foo (result i32) + (br_table $foo $foo + (i32.const 0) + (i32.const 0) + ) + ) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (block $bar (result i32) + (br_table $bar $bar + (i32.const 0) + (i32.const 1) + ) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (block $foo + (block $bar + (br_table $foo $bar + (i32.const 0) + ) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $erase (; 0 ;) (type $0) + (block $foo + (block $bar + (br_table $foo $bar + (i32.const 0) + ) + ) + ) + ) + (func $other (; 1 ;) (type $0) + (block $bar + (block $foo + (br_table $foo $bar + (i32.const 0) + ) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $erase (; 0 ;) (type $0) + (call $erase) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2-but-in-theory-we-could-erase (; 0 ;) (type $0) + (call $keep2-but-in-theory-we-could-erase) + ) + (func $other (; 1 ;) (type $0) + (call $other) + ) +) +(module + (type $FUNCSIG$v (func)) + (import "env" "i" (func $i)) + (import "env" "j" (func $j)) + (memory $0 0) + (func $erase (; 2 ;) (type $FUNCSIG$v) + (call $i) + ) +) +(module + (type $FUNCSIG$v (func)) + (import "env" "i" (func $i)) + (import "env" "j" (func $j)) + (memory $0 0) + (func $keep2 (; 2 ;) (type $FUNCSIG$v) + (call $i) + ) + (func $other (; 3 ;) (type $FUNCSIG$v) + (call $j) + ) +) +(module + (type $T (func)) + (table 2 2 anyfunc) + (elem (i32.const 0) $erase $erase) + (memory $0 0) + (func $erase (; 0 ;) (type $T) + (call_indirect (type $T) + (i32.const 0) + ) + ) +) +(module + (type $T (func)) + (table 2 2 anyfunc) + (elem (i32.const 0) $keep2 $other) + (memory $0 0) + (func $keep2 (; 0 ;) (type $T) + (call_indirect (type $T) + (i32.const 0) + ) + ) + (func $other (; 1 ;) (type $T) + (call_indirect (type $T) + (i32.const 1) + ) + ) +) +(module + (type $T (func)) + (type $S (func)) + (table 2 2 anyfunc) + (elem (i32.const 0) $keep2 $other) + (memory $0 0) + (func $keep2 (; 0 ;) (type $T) + (call_indirect (type $T) + (i32.const 0) + ) + ) + (func $other (; 1 ;) (type $T) + (call_indirect (type $S) + (i32.const 0) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $erase-even-locals-with-different-names (; 0 ;) (type $0) + (local $i i32) + (drop + (get_local $i) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (local $i i32) + (drop + (get_local $i) + ) + ) + (func $other (; 1 ;) (type $0) + (local $j i64) + (drop + (get_local $j) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $erase-even-locals-with-different-names (; 0 ;) (type $0) + (local $i i32) + (set_local $i + (i32.const 0) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (local $i i32) + (set_local $i + (i32.const 0) + ) + ) + (func $other (; 1 ;) (type $0) + (local $j i64) + (set_local $j + (i64.const 0) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (local $i i32) + (set_local $i + (i32.const 0) + ) + ) + (func $other (; 1 ;) (type $0) + (local $j i32) + (set_local $j + (i32.const 1) + ) + ) +) +(module + (type $0 (func)) + (memory $0 10) + (func $erase (; 0 ;) (type $0) + (drop + (i32.load + (i32.const 0) + ) + ) + (drop + (i32.load16_s offset=3 + (i32.const 0) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 10) + (func $keep2 (; 0 ;) (type $0) + (drop + (i32.load offset=3 + (i32.const 0) + ) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (i32.load16_s offset=3 + (i32.const 0) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 10) + (func $keep2 (; 0 ;) (type $0) + (drop + (i32.load16_s offset=3 + (i32.const 0) + ) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (i32.load16_s offset=3 align=1 + (i32.const 0) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 10) + (func $keep2 (; 0 ;) (type $0) + (drop + (i32.load16_s + (i32.const 0) + ) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (i32.load16_s offset=3 + (i32.const 0) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 10) + (func $keep2 (; 0 ;) (type $0) + (drop + (i32.load16_s offset=3 + (i32.const 0) + ) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (i32.load16_s offset=3 + (i32.const 1) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 10) + (func $keep2 (; 0 ;) (type $0) + (drop + (i32.load16_u offset=3 + (i32.const 0) + ) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (i32.load16_s offset=3 + (i32.const 0) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 10) + (func $erase (; 0 ;) (type $0) + (i32.store + (i32.const 0) + (i32.const 100) + ) + (i32.store16 offset=3 + (i32.const 0) + (i32.const 100) + ) + ) +) +(module + (type $0 (func)) + (memory $0 10) + (func $keep2 (; 0 ;) (type $0) + (i32.store offset=3 + (i32.const 0) + (i32.const 100) + ) + ) + (func $other (; 1 ;) (type $0) + (i32.store16 offset=3 + (i32.const 0) + (i32.const 100) + ) + ) +) +(module + (type $0 (func)) + (memory $0 10) + (func $keep2 (; 0 ;) (type $0) + (i32.store16 offset=3 + (i32.const 0) + (i32.const 100) + ) + ) + (func $other (; 1 ;) (type $0) + (i32.store16 offset=3 align=1 + (i32.const 0) + (i32.const 100) + ) + ) +) +(module + (type $0 (func)) + (memory $0 10) + (func $keep2 (; 0 ;) (type $0) + (i32.store16 + (i32.const 0) + (i32.const 100) + ) + ) + (func $other (; 1 ;) (type $0) + (i32.store16 offset=3 + (i32.const 0) + (i32.const 100) + ) + ) +) +(module + (type $0 (func)) + (memory $0 10) + (func $keep2 (; 0 ;) (type $0) + (i32.store16 offset=3 + (i32.const 0) + (i32.const 100) + ) + ) + (func $other (; 1 ;) (type $0) + (i32.store16 offset=3 + (i32.const 1) + (i32.const 100) + ) + ) +) +(module + (type $0 (func)) + (memory $0 10) + (func $keep2 (; 0 ;) (type $0) + (i32.store16 offset=3 + (i32.const 0) + (i32.const 100) + ) + ) + (func $other (; 1 ;) (type $0) + (i32.store16 offset=3 + (i32.const 0) + (i32.const 101) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (drop + (i32.const 0) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (i64.const 0) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (drop + (i32.const 0) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (f32.const 0) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (drop + (i32.const 0) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (f64.const 0) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (drop + (i64.const 0) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (i64.const 1) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (drop + (f32.const 0.10000000149011612) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (f32.const -0.10000000149011612) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (drop + (f64.const 0.1) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (f64.const 0.2) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $erase (; 0 ;) (type $0) + (drop + (f32.abs + (f32.const 0) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (drop + (f32.abs + (f32.const 0) + ) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (f32.abs + (f32.const 1) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (drop + (f32.abs + (f32.const 0) + ) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (f32.neg + (f32.const 0) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $erase (; 0 ;) (type $0) + (drop + (f32.add + (f32.const 0) + (f32.const 0) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (drop + (f32.add + (f32.const 0) + (f32.const 0) + ) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (f32.add + (f32.const 0) + (f32.const 1) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (drop + (f32.add + (f32.const 0) + (f32.const 0) + ) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (f32.add + (f32.const 1) + (f32.const 0) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep2 (; 0 ;) (type $0) + (drop + (f32.add + (f32.const 0) + (f32.const 0) + ) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (f32.sub + (f32.const 0) + (f32.const 0) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $erase (; 0 ;) (type $0) + (drop + (select + (i32.const 0) + (i32.const 0) + (i32.const 0) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep (; 0 ;) (type $0) + (drop + (select + (i32.const 0) + (i32.const 0) + (i32.const 0) + ) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (select + (i32.const 1) + (i32.const 0) + (i32.const 0) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep (; 0 ;) (type $0) + (drop + (select + (i32.const 0) + (i32.const 0) + (i32.const 0) + ) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (select + (i32.const 0) + (i32.const 2) + (i32.const 0) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep (; 0 ;) (type $0) + (drop + (select + (i32.const 0) + (i32.const 0) + (i32.const 0) + ) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (select + (i32.const 0) + (i32.const 0) + (i32.const 3) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $erase (; 0 ;) (type $0) + (return) + ) +) +(module + (type $0 (func (result i32))) + (memory $0 0) + (func $erase (; 0 ;) (type $0) (result i32) + (return + (i32.const 0) + ) + ) +) +(module + (type $0 (func (result i32))) + (memory $0 0) + (func $keep (; 0 ;) (type $0) (result i32) + (return + (i32.const 0) + ) + ) + (func $other (; 1 ;) (type $0) (result i32) + (return + (i32.const 1) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $erase (; 0 ;) (type $0) + (drop + (current_memory) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $erase (; 0 ;) (type $0) + (drop + (grow_memory + (i32.const 10) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep (; 0 ;) (type $0) + (drop + (grow_memory + (i32.const 10) + ) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (grow_memory + (i32.const 11) + ) + ) + ) +) +(module + (type $0 (func)) + (memory $0 0) + (func $keep (; 0 ;) (type $0) + (drop + (current_memory) + ) + ) + (func $other (; 1 ;) (type $0) + (drop + (grow_memory + (i32.const 10) + ) + ) + ) +) diff --git a/test/passes/duplicate-function-elimination_optimize-level=2.wast b/test/passes/duplicate-function-elimination_optimize-level=2.wast new file mode 100644 index 000000000..b79032155 --- /dev/null +++ b/test/passes/duplicate-function-elimination_optimize-level=2.wast @@ -0,0 +1,1221 @@ +(module + (memory 0) + (type $0 (func)) + (func $erase (type $0) + (nop) + ) + (func $other (type $0) + (nop) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (i32.const 0) + ) + ) + (func $other (type $0) + (nop) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $erase (type $0) + (drop + (i32.const 0) + ) + ) + (func $other (type $0) + (drop + (i32.const 0) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (i32.const 0) + ) + ) + (func $other (type $0) + (drop + (i32.const 1) + ) + ) +) +(module + (memory 0) + (start $other) + (type $0 (func)) + (export "keep2" $keep2) + (export "other" $other) + (table 3 3 anyfunc) + (elem (i32.const 0) $keep2 $other $caller) + (func $keep2 (type $0) + (nop) + ) + (func $other (type $0) + (nop) + ) + (func $caller (type $0) + (call $keep2) + (call $other) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2-after-two-passes (type $0) + (nop) + ) + (func $other (type $0) + (nop) + ) + (func $keep-caller (type $0) + (call $keep2-after-two-passes) + ) + (func $other-caller (type $0) + (call $other) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep-4 (type $0) + (nop) + ) + (func $other (type $0) + (unreachable) + ) + (func $keep-caller (type $0) + (call $keep-4) + ) + (func $other-caller (type $0) + (call $other) + ) +) +(module + (memory 0) + (type $T (func (result i32))) + (type $S (func (result i32))) + (type $2 (func)) + (type $3 (func (param i32))) + (func $keep4-similar-but-func-sig-differs (type $2) + (drop + (i32.const 0) + ) + ) + (func $other1 (type $3) (param $i i32) + (drop + (i32.const 0) + ) + ) + (func $other2 (type $T) (result i32) + (i32.const 0) + ) + (func $other3 (type $S) (result i32) + (i32.const 0) + ) +) +(module + (memory 0) + (type $S (func (result i32))) + (type $1 (func (param i32))) + (func $keep2-similar-but-func-sig-differs (type $1) (param $i i32) + (drop + (i32.const 0) + ) + ) + (func $other1 (type $1) (param $i i32) + (drop + (i32.const 0) + ) + ) + (func $other2 (type $S) (result i32) + (i32.const 0) + ) + (func $other3 (type $S) (result i32) + (i32.const 0) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (nop) + ) + (func $other (type $0) + (nop) + (nop) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $erase (type $0) + (block $block0 + ) + ) + (func $other (type $0) + (block $block0 + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (block $block0 + ) + ) + (func $other (type $0) + (block $block0 + (nop) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $erase (type $0) + (block $block0 + (nop) + ) + ) + (func $other (type $0) + (block $block0 + (nop) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (block $block0 + (nop) + ) + ) + (func $other (type $0) + (block $block0 + (nop) + (unreachable) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (block $block0 + (nop) + ) + ) + (func $other (type $0) + (block $block0 + (unreachable) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $erase-since-block-names-do-not-matter (type $0) + (block $foo + ) + ) + (func $other (type $0) + (block $bar + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $erase-since-block-names-do-not-matter (type $0) + (block $foo + (br $foo) + (br_table $foo $foo + (i32.const 0) + ) + ) + ) + (func $other (type $0) + (block $bar + (br $bar) + (br_table $bar $bar + (i32.const 0) + ) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (block $foo + (block + (drop + (i32.const 0) + ) + (br $foo) + ) + ) + ) + (func $other (type $0) + (block $bar + (block + (drop + (i32.const 1) + ) + (br $bar) + ) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (block $foo + (br_if $foo + (i32.const 0) + ) + ) + ) + (func $other (type $0) + (block $bar + (br_if $bar + (i32.const 1) + ) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $erase (type $0) + (block $foo + (br_if $foo + (i32.const 0) + ) + ) + ) + (func $other (type $0) + (block $bar + (br_if $bar + (i32.const 0) + ) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (block $foo + (br_table $foo $foo + (i32.const 0) + ) + ) + ) + (func $other (type $0) + (block $bar + (br_table $bar $bar + (i32.const 1) + ) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $erase (type $0) + (loop $bar + (nop) + ) + ) + (func $other (type $0) + (loop $sjc + (nop) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (block $foo (result i32) + (br_table $foo $foo + (i32.const 0) + (i32.const 0) + ) + ) + ) + ) + (func $other (type $0) + (drop + (block $bar (result i32) + (br_table $bar $bar + (i32.const 0) + (i32.const 1) + ) + ) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (block $foo + (block $bar + (br_table $foo $bar + (i32.const 0) + ) + ) + ) + ) + (func $other (type $0) + (block $bar + (block $foo + (br_table $bar $foo + (i32.const 0) + ) + ) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $erase (type $0) + (block $foo + (block $bar + (br_table $foo $bar + (i32.const 0) + ) + ) + ) + ) + (func $other (type $0) + (block $bar + (block $foo + (br_table $foo $bar + (i32.const 0) + ) + ) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $erase (type $0) + (call $erase) + ) + (func $other (type $0) + (call $erase) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2-but-in-theory-we-could-erase (type $0) + (call $keep2-but-in-theory-we-could-erase) + ) + (func $other (type $0) + (call $other) + ) +) +(module + (memory 0) + (type $FUNCSIG$v (func)) + (import $i "env" "i") + (import $j "env" "j") + (func $erase (type $FUNCSIG$v) + (call $i) + ) + (func $other (type $FUNCSIG$v) + (call $i) + ) +) +(module + (memory 0) + (type $FUNCSIG$v (func)) + (import $i "env" "i") + (import $j "env" "j") + (func $keep2 (type $FUNCSIG$v) + (call $i) + ) + (func $other (type $FUNCSIG$v) + (call $j) + ) +) +(module + (memory 0) + (type $T (func)) + (table 2 2 anyfunc) + (elem (i32.const 0) $erase $other) + (func $erase (type $T) + (call_indirect (type $T) + (i32.const 0) + ) + ) + (func $other (type $T) + (call_indirect (type $T) + (i32.const 0) + ) + ) +) +(module + (memory 0) + (type $T (func)) + (table 2 2 anyfunc) + (elem (i32.const 0) $keep2 $other) + (func $keep2 (type $T) + (call_indirect (type $T) + (i32.const 0) + ) + ) + (func $other (type $T) + (call_indirect (type $T) + (i32.const 1) + ) + ) +) +(module + (memory 0) + (type $T (func)) + (type $S (func)) + (table 2 2 anyfunc) + (elem (i32.const 0) $keep2 $other) + (func $keep2 (type $T) + (call_indirect (type $T) + (i32.const 0) + ) + ) + (func $other (type $T) + (call_indirect (type $S) + (i32.const 0) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $erase-even-locals-with-different-names (type $0) + (local $i i32) + (drop + (get_local $i) + ) + ) + (func $other (type $0) + (local $j i32) + (drop + (get_local $j) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (local $i i32) + (drop + (get_local $i) + ) + ) + (func $other (type $0) + (local $j i64) + (drop + (get_local $j) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $erase-even-locals-with-different-names (type $0) + (local $i i32) + (set_local $i + (i32.const 0) + ) + ) + (func $other (type $0) + (local $j i32) + (set_local $j + (i32.const 0) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (local $i i32) + (set_local $i + (i32.const 0) + ) + ) + (func $other (type $0) + (local $j i64) + (set_local $j + (i64.const 0) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (local $i i32) + (set_local $i + (i32.const 0) + ) + ) + (func $other (type $0) + (local $j i32) + (set_local $j + (i32.const 1) + ) + ) +) +(module + (memory 10) + (type $0 (func)) + (func $erase (type $0) + (drop + (i32.load + (i32.const 0) + ) + ) + (drop + (i32.load16_s offset=3 align=2 + (i32.const 0) + ) + ) + ) + (func $other (type $0) + (drop + (i32.load + (i32.const 0) + ) + ) + (drop + (i32.load16_s offset=3 align=2 + (i32.const 0) + ) + ) + ) +) +(module + (memory 10) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (i32.load offset=3 + (i32.const 0) + ) + ) + ) + (func $other (type $0) + (drop + (i32.load16_s offset=3 align=2 + (i32.const 0) + ) + ) + ) +) +(module + (memory 10) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (i32.load16_s offset=3 + (i32.const 0) + ) + ) + ) + (func $other (type $0) + (drop + (i32.load16_s offset=3 align=1 + (i32.const 0) + ) + ) + ) +) +(module + (memory 10) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (i32.load16_s align=2 + (i32.const 0) + ) + ) + ) + (func $other (type $0) + (drop + (i32.load16_s offset=3 align=2 + (i32.const 0) + ) + ) + ) +) +(module + (memory 10) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (i32.load16_s offset=3 align=2 + (i32.const 0) + ) + ) + ) + (func $other (type $0) + (drop + (i32.load16_s offset=3 align=2 + (i32.const 1) + ) + ) + ) +) +(module + (memory 10) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (i32.load16_u offset=3 align=2 + (i32.const 0) + ) + ) + ) + (func $other (type $0) + (drop + (i32.load16_s offset=3 align=2 + (i32.const 0) + ) + ) + ) +) +(module + (memory 10) + (type $0 (func)) + (func $erase (type $0) + (i32.store + (i32.const 0) + (i32.const 100) + ) + (i32.store16 offset=3 align=2 + (i32.const 0) + (i32.const 100) + ) + ) + (func $other (type $0) + (i32.store + (i32.const 0) + (i32.const 100) + ) + (i32.store16 offset=3 align=2 + (i32.const 0) + (i32.const 100) + ) + ) +) +(module + (memory 10) + (type $0 (func)) + (func $keep2 (type $0) + (i32.store32 offset=3 + (i32.const 0) + (i32.const 100) + ) + ) + (func $other (type $0) + (i32.store16 offset=3 align=2 + (i32.const 0) + (i32.const 100) + ) + ) +) +(module + (memory 10) + (type $0 (func)) + (func $keep2 (type $0) + (i32.store16 offset=3 + (i32.const 0) + (i32.const 100) + ) + ) + (func $other (type $0) + (i32.store16 offset=3 align=1 + (i32.const 0) + (i32.const 100) + ) + ) +) +(module + (memory 10) + (type $0 (func)) + (func $keep2 (type $0) + (i32.store16 align=2 + (i32.const 0) + (i32.const 100) + ) + ) + (func $other (type $0) + (i32.store16 offset=3 align=2 + (i32.const 0) + (i32.const 100) + ) + ) +) +(module + (memory 10) + (type $0 (func)) + (func $keep2 (type $0) + (i32.store16 offset=3 align=2 + (i32.const 0) + (i32.const 100) + ) + ) + (func $other (type $0) + (i32.store16 offset=3 align=2 + (i32.const 1) + (i32.const 100) + ) + ) +) +(module + (memory 10) + (type $0 (func)) + (func $keep2 (type $0) + (i32.store16 offset=3 align=2 + (i32.const 0) + (i32.const 100) + ) + ) + (func $other (type $0) + (i32.store16 offset=3 align=2 + (i32.const 0) + (i32.const 101) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (i32.const 0) + ) + ) + (func $other (type $0) + (drop + (i64.const 0) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (i32.const 0) + ) + ) + (func $other (type $0) + (drop + (f32.const 0) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (i32.const 0) + ) + ) + (func $other (type $0) + (drop + (f64.const 0) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (i64.const 0) + ) + ) + (func $other (type $0) + (drop + (i64.const 1) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (f32.const 0.10000000149011612) + ) + ) + (func $other (type $0) + (drop + (f32.const -0.10000000149011612) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (f64.const 0.1) + ) + ) + (func $other (type $0) + (drop + (f64.const 0.2) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $erase (type $0) + (drop + (f32.abs + (f32.const 0) + ) + ) + ) + (func $other (type $0) + (drop + (f32.abs + (f32.const 0) + ) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (f32.abs + (f32.const 0) + ) + ) + ) + (func $other (type $0) + (drop + (f32.abs + (f32.const 1) + ) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (f32.abs + (f32.const 0) + ) + ) + ) + (func $other (type $0) + (drop + (f32.neg + (f32.const 0) + ) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $erase (type $0) + (drop + (f32.add + (f32.const 0) + (f32.const 0) + ) + ) + ) + (func $other (type $0) + (drop + (f32.add + (f32.const 0) + (f32.const 0) + ) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (f32.add + (f32.const 0) + (f32.const 0) + ) + ) + ) + (func $other (type $0) + (drop + (f32.add + (f32.const 0) + (f32.const 1) + ) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (f32.add + (f32.const 0) + (f32.const 0) + ) + ) + ) + (func $other (type $0) + (drop + (f32.add + (f32.const 1) + (f32.const 0) + ) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (f32.add + (f32.const 0) + (f32.const 0) + ) + ) + ) + (func $other (type $0) + (drop + (f32.sub + (f32.const 0) + (f32.const 0) + ) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $erase (type $0) + (drop + (select + (i32.const 0) + (i32.const 0) + (i32.const 0) + ) + ) + ) + (func $other (type $0) + (drop + (select + (i32.const 0) + (i32.const 0) + (i32.const 0) + ) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep (type $0) + (drop + (select + (i32.const 0) + (i32.const 0) + (i32.const 0) + ) + ) + ) + (func $other (type $0) + (drop + (select + (i32.const 1) + (i32.const 0) + (i32.const 0) + ) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep (type $0) + (drop + (select + (i32.const 0) + (i32.const 0) + (i32.const 0) + ) + ) + ) + (func $other (type $0) + (drop + (select + (i32.const 0) + (i32.const 2) + (i32.const 0) + ) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep (type $0) + (drop + (select + (i32.const 0) + (i32.const 0) + (i32.const 0) + ) + ) + ) + (func $other (type $0) + (drop + (select + (i32.const 0) + (i32.const 0) + (i32.const 3) + ) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $erase (type $0) + (return) + ) + (func $other (type $0) + (return) + ) +) +(module + (memory 0) + (type $0 (func (result i32))) + (func $erase (type $0) (result i32) + (return + (i32.const 0) + ) + ) + (func $other (type $0) (result i32) + (return + (i32.const 0) + ) + ) +) +(module + (memory 0) + (type $0 (func (result i32))) + (func $keep (type $0) (result i32) + (return + (i32.const 0) + ) + ) + (func $other (type $0) (result i32) + (return + (i32.const 1) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $erase (type $0) + (drop + (current_memory) + ) + ) + (func $other (type $0) + (drop + (current_memory) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $erase (type $0) + (drop + (grow_memory + (i32.const 10) + ) + ) + ) + (func $other (type $0) + (drop + (grow_memory + (i32.const 10) + ) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep (type $0) + (drop + (grow_memory + (i32.const 10) + ) + ) + ) + (func $other (type $0) + (drop + (grow_memory + (i32.const 11) + ) + ) + ) +) +(module + (memory 0) + (type $0 (func)) + (func $keep (type $0) + (drop + (current_memory) + ) + ) + (func $other (type $0) + (drop + (grow_memory + (i32.const 10) + ) + ) + ) +) diff --git a/test/passes/remove-unused-names_code-folding.txt b/test/passes/remove-unused-names_code-folding.txt index a37cbefbd..69c687862 100644 --- a/test/passes/remove-unused-names_code-folding.txt +++ b/test/passes/remove-unused-names_code-folding.txt @@ -1069,19 +1069,19 @@ (block (if (i32.const 1) - (br $folding-inner0) + (br $folding-inner1) ) (if (i32.const 1) - (br $folding-inner0) + (br $folding-inner1) ) (if (i32.const 1) - (br $folding-inner1) + (br $folding-inner0) ) (if (i32.const 1) - (br $folding-inner1) + (br $folding-inner0) ) ) (return) @@ -1098,7 +1098,7 @@ (nop) (nop) (drop - (i32.const 1) + (i32.const 2) ) (unreachable) ) @@ -1115,7 +1115,7 @@ (nop) (nop) (drop - (i32.const 2) + (i32.const 1) ) (unreachable) ) -- cgit v1.2.3