diff options
30 files changed, 1706 insertions, 1738 deletions
diff --git a/build-js.sh b/build-js.sh index f4a2157b5..487c8a9c1 100755 --- a/build-js.sh +++ b/build-js.sh @@ -90,6 +90,7 @@ echo "building shared bitcode" $BINARYEN_SRC/ir/LocalGraph.cpp \ $BINARYEN_SRC/passes/pass.cpp \ $BINARYEN_SRC/passes/CoalesceLocals.cpp \ + $BINARYEN_SRC/passes/DeadArgumentElimination.cpp \ $BINARYEN_SRC/passes/CodeFolding.cpp \ $BINARYEN_SRC/passes/CodePushing.cpp \ $BINARYEN_SRC/passes/ConstHoisting.cpp \ diff --git a/src/mixed_arena.h b/src/mixed_arena.h index a1c51b5eb..90203842e 100644 --- a/src/mixed_arena.h +++ b/src/mixed_arena.h @@ -223,6 +223,10 @@ public: usedElements -= size; } + void erase(Iterator it) { + erase(it, it + 1); + } + void clear() { usedElements = 0; } diff --git a/src/passes/CMakeLists.txt b/src/passes/CMakeLists.txt index 87b7661aa..984b85e63 100644 --- a/src/passes/CMakeLists.txt +++ b/src/passes/CMakeLists.txt @@ -10,6 +10,7 @@ SET(passes_SOURCES CodeFolding.cpp ConstHoisting.cpp DataFlowOpts.cpp + DeadArgumentElimination.cpp DeadCodeElimination.cpp DuplicateFunctionElimination.cpp ExtractFunction.cpp diff --git a/src/passes/DeadArgumentElimination.cpp b/src/passes/DeadArgumentElimination.cpp new file mode 100644 index 000000000..b1a1008f4 --- /dev/null +++ b/src/passes/DeadArgumentElimination.cpp @@ -0,0 +1,367 @@ +/* + * 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. + */ + +// +// Optimizes call arguments in a whole-program manner, removing ones +// that are not used (dead). +// +// Specifically, this does these things: +// +// * Find functions for whom an argument is always passed the same +// constant. If so, we can just set that local to that constant +// in the function. +// * Find functions that don't use the value passed to an argument. +// If so, we can avoid even sending and receiving it. (Note how if +// the previous point was true for an argument, then the second +// must as well.) +// +// This pass does not depend on flattening, but it may be more effective, +// as then call arguments never have side effects (which we need to +// watch for here). +// + +#include <unordered_map> +#include <unordered_set> + +#include <wasm.h> +#include <pass.h> +#include <wasm-builder.h> +#include <cfg/cfg-traversal.h> +#include <ir/effects.h> +#include <passes/opt-utils.h> +#include <support/sorted_vector.h> + +namespace wasm { + +// Information for a function +struct DAEFunctionInfo { + // The unused parameters, if any. + SortedVector unusedParams; + // Maps a function name to the calls going to it. + std::unordered_map<Name, std::vector<Call*>> calls; + // Whether the function can be called from places that + // affect what we can do. For now, any call we don't + // see inhibits our optimizations, but TODO: an export + // could be worked around by exporting a thunk that + // adds the parameter. + bool hasUnseenCalls = false; +}; + +typedef std::unordered_map<Name, DAEFunctionInfo> DAEFunctionInfoMap; + +// Information in a basic block +struct DAEBlockInfo { + // A local may be read, written, or not accessed in this block. + // If it is both read and written, we just care about the first + // action (if it is read first, that's all the info we are + // looking for; if it is written first, it can't be read later). + enum LocalUse { + Read, + Written + }; + std::unordered_map<Index, LocalUse> localUses; +}; + +struct DAEScanner : public WalkerPass<CFGWalker<DAEScanner, Visitor<DAEScanner>, DAEBlockInfo>> { + bool isFunctionParallel() override { return true; } + + Pass* create() override { return new DAEScanner(infoMap); } + + DAEScanner(DAEFunctionInfoMap* infoMap) : infoMap(infoMap) {} + + DAEFunctionInfoMap* infoMap; + DAEFunctionInfo* info; + + Index numParams; + + // cfg traversal work + + void visitGetLocal(GetLocal* curr) { + if (currBasicBlock) { + auto& localUses = currBasicBlock->contents.localUses; + auto index = curr->index; + if (localUses.count(index) == 0) { + localUses[index] = DAEBlockInfo::Read; + } + } + } + + void visitSetLocal(SetLocal* curr) { + if (currBasicBlock) { + auto& localUses = currBasicBlock->contents.localUses; + auto index = curr->index; + if (localUses.count(index) == 0) { + localUses[index] = DAEBlockInfo::Written; + } + } + } + + void visitCall(Call* curr) { + info->calls[curr->target].push_back(curr); + } + + // main entry point + + void doWalkFunction(Function* func) { + numParams = func->getNumParams(); + info = &((*infoMap)[func->name]); + CFGWalker<DAEScanner, Visitor<DAEScanner>, DAEBlockInfo>::doWalkFunction(func); + // If there are relevant params, check if they are used. (If + // we can't optimize the function anyhow, there's no point.) + if (numParams > 0 && !info->hasUnseenCalls) { + findUnusedParams(func); + } + } + + void findUnusedParams(Function* func) { + // Flow the incoming parameter values, see if they reach a read. + // Once we've seen a parameter at a block, we need never consider it there + // again. + std::unordered_map<BasicBlock*, SortedVector> seenBlockIndexes; + // Start with all the incoming parameters. + SortedVector initial; + for (Index i = 0; i < numParams; i++) { + initial.push_back(i); + } + // The used params, which we now compute. + std::unordered_set<Index> usedParams; + // An item of work is a block plus the values arriving there. + typedef std::pair<BasicBlock*, SortedVector> Item; + std::vector<Item> work; + work.emplace_back(entry, initial); + while (!work.empty()) { + auto item = std::move(work.back()); + work.pop_back(); + auto* block = item.first; + auto& indexes = item.second; + // Ignore things we've already seen, or we've already seen to be used. + auto& seenIndexes = seenBlockIndexes[block]; + indexes.filter([&](const Index i) { + if (seenIndexes.has(i) || usedParams.count(i)) { + return false; + } else { + seenIndexes.insert(i); + return true; + } + }); + if (indexes.empty()) { + continue; // nothing more to flow + } + auto& localUses = block->contents.localUses; + SortedVector remainingIndexes; + for (auto i : indexes) { + auto iter = localUses.find(i); + if (iter != localUses.end()) { + auto use = iter->second; + if (use == DAEBlockInfo::Read) { + usedParams.insert(i); + } + // Whether it was a read or a write, we can stop looking at that local here. + } else { + remainingIndexes.insert(i); + } + } + // If there are remaining indexes, flow them forward. + if (!remainingIndexes.empty()) { + for (auto* next : block->out) { + work.emplace_back(next, remainingIndexes); + } + } + } + // We can now compute the unused params. + for (Index i = 0; i < numParams; i++) { + if (usedParams.count(i) == 0) { + info->unusedParams.insert(i); + } + } + } +}; + +struct DAE : public Pass { + bool optimize = false; + + void run(PassRunner* runner, Module* module) override { + DAEFunctionInfoMap infoMap; + // Ensure they all exist so the parallel threads don't modify the data structure. + for (auto& func : module->functions) { + infoMap[func->name]; + } + // Check the influence of the table and exports. + for (auto& curr : module->exports) { + if (curr->kind == ExternalKind::Function) { + infoMap[curr->value].hasUnseenCalls = true; + } + } + for (auto& segment : module->table.segments) { + for (auto name : segment.data) { + infoMap[name].hasUnseenCalls = true; + } + } + // Scan all the functions. + { + PassRunner runner(module); + runner.setIsNested(true); + runner.add<DAEScanner>(&infoMap); + runner.run(); + } + // Combine all the info. + std::unordered_map<Name, std::vector<Call*>> allCalls; + for (auto& pair : infoMap) { + auto& info = pair.second; + for (auto& pair : info.calls) { + auto name = pair.first; + auto& calls = pair.second; + auto& allCallsToName = allCalls[name]; + allCallsToName.insert(allCallsToName.end(), calls.begin(), calls.end()); + } + } + // We now have a mapping of all call sites for each function. Check which + // are always passed the same constant for a particular argument. + for (auto& pair : allCalls) { + auto name = pair.first; + // We can only optimize if we see all the calls and can modify + // them. + if (infoMap[name].hasUnseenCalls) continue; + auto& calls = pair.second; + auto* func = module->getFunction(name); + auto numParams = func->getNumParams(); + for (Index i = 0; i < numParams; i++) { + Literal value; + for (auto* call : calls) { + assert(call->target == name); + assert(call->operands.size() == numParams); + auto* operand = call->operands[i]; + if (auto* c = operand->dynCast<Const>()) { + if (value.type == none) { + // This is the first value seen. + value = c->value; + } else if (value != c->value) { + // Not identical, give up + value.type = none; + break; + } + } else { + // Not a constant, give up + value.type = none; + break; + } + } + if (value.type != none) { + // Success! We can just apply the constant in the function, which makes + // the parameter value unused, which lets us remove it later. + Builder builder(*module); + func->body = builder.makeSequence( + builder.makeSetLocal(i, builder.makeConst(value)), + func->body + ); + // Mark it as unused, which we know it now is (no point to + // re-scan just for that). + infoMap[name].unusedParams.insert(i); + } + } + } + // Track which functions we changed, and optimize them later if necessary. + std::unordered_set<Function*> changed; + // We now know which parameters are unused, and can potentially remove them. + for (auto& pair : allCalls) { + auto name = pair.first; + auto& calls = pair.second; + auto* func = module->getFunction(name); + auto numParams = func->getNumParams(); + if (numParams == 0) continue; + // Iterate downwards, as we may remove more than one. + Index i = numParams - 1; + while (1) { + if (infoMap[name].unusedParams.has(i)) { + // Great, it's not used. Check if none of the calls has a param with side + // effects, as that would prevent us removing them (flattening should + // have been done earlier). + bool canRemove = true; + for (auto* call : calls) { + auto* operand = call->operands[i]; + if (EffectAnalyzer(runner->options, operand).hasSideEffects()) { + canRemove = false; + break; + } + } + if (canRemove) { + // Wonderful, nothing stands in our way! Do it. + // TODO: parallelize this? + removeParameter(func, i, calls); + changed.insert(func); + } + } + if (i == 0) break; + i--; + } + } + if (optimize && changed.size() > 0) { + OptUtils::optimizeAfterInlining(changed, module, runner); + } + } + +private: + void removeParameter(Function* func, Index i, std::vector<Call*> calls) { + // Clear the type, which is no longer accurate. + func->type = Name(); + // It's cumbersome to adjust local names - TODO don't clear them? + Builder::clearLocalNames(func); + // Remove the parameter from the function. We must add a new local + // for uses of the parameter, but cannot make it use the same index + // (in general). + auto type = func->getLocalType(i); + func->params.erase(func->params.begin() + i); + Index newIndex = Builder::addVar(func, type); + // Update local operations. + struct LocalUpdater : public PostWalker<LocalUpdater> { + Index removedIndex; + Index newIndex; + LocalUpdater(Function* func, Index removedIndex, Index newIndex) : removedIndex(removedIndex), newIndex(newIndex) { + walk(func->body); + } + void visitGetLocal(GetLocal* curr) { + updateIndex(curr->index); + } + void visitSetLocal(SetLocal* curr) { + updateIndex(curr->index); + } + void updateIndex(Index& index) { + if (index == removedIndex) { + index = newIndex; + } else if (index > removedIndex) { + index--; + } + } + } localUpdater(func, i, newIndex); + // Remove the arguments from the calls. + for (auto* call : calls) { + call->operands.erase(call->operands.begin() + i); + } + } +}; + +Pass *createDAEPass() { + return new DAE(); +} + +Pass *createDAEOptimizingPass() { + auto* ret = new DAE(); + ret->optimize = true; + return ret; +} + +} // namespace wasm + diff --git a/src/passes/Inlining.cpp b/src/passes/Inlining.cpp index 5de214338..67613fa47 100644 --- a/src/passes/Inlining.cpp +++ b/src/passes/Inlining.cpp @@ -38,6 +38,7 @@ #include <ir/utils.h> #include <ir/literal-utils.h> #include <parsing.h> +#include <passes/opt-utils.h> namespace wasm { @@ -332,7 +333,7 @@ struct Inlining : public Pass { wasm::UniqueNameMapper::uniquify(func->body); } if (optimize && inlinedInto.size() > 0) { - doOptimize(inlinedInto, module, runner); + OptUtils::optimizeAfterInlining(inlinedInto, module, runner); } // remove functions that we no longer need after inlining auto& funcs = module->functions; @@ -348,30 +349,6 @@ struct Inlining : public Pass { // return whether we did any work return inlinedUses.size() > 0; } - - // Run useful optimizations after inlining, things like removing - // unnecessary new blocks, sharing variables, etc. - void doOptimize(std::unordered_set<Function*>& funcs, Module* module, PassRunner* parentRunner) { - // save the full list of functions on the side - std::vector<std::unique_ptr<Function>> all; - all.swap(module->functions); - module->updateMaps(); - for (auto& func : funcs) { - module->addFunction(func); - } - PassRunner runner(module, parentRunner->options); - runner.setIsNested(true); - runner.setValidateGlobally(false); // not a full valid module - runner.add("precompute-propagate"); // this is especially useful after inlining - runner.addDefaultFunctionOptimizationPasses(); // do all the usual stuff - runner.run(); - // restore all the funcs - for (auto& func : module->functions) { - func.release(); - } - all.swap(module->functions); - module->updateMaps(); - } }; Pass *createInliningPass() { diff --git a/src/passes/opt-utils.h b/src/passes/opt-utils.h new file mode 100644 index 000000000..a880e2623 --- /dev/null +++ b/src/passes/opt-utils.h @@ -0,0 +1,56 @@ +/* + * 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_passes_opt_utils_h +#define wasm_passes_opt_utils_h + +#include <unordered_set> + +#include <wasm.h> +#include <pass.h> + +namespace wasm { + +namespace OptUtils { + +// Run useful optimizations after inlining new code into a set +// of functions. +inline void optimizeAfterInlining(std::unordered_set<Function*>& funcs, Module* module, PassRunner* parentRunner) { + // save the full list of functions on the side + std::vector<std::unique_ptr<Function>> all; + all.swap(module->functions); + module->updateMaps(); + for (auto& func : funcs) { + module->addFunction(func); + } + PassRunner runner(module, parentRunner->options); + runner.setIsNested(true); + runner.setValidateGlobally(false); // not a full valid module + runner.add("precompute-propagate"); // this is especially useful after inlining + runner.addDefaultFunctionOptimizationPasses(); // do all the usual stuff + runner.run(); + // restore all the funcs + for (auto& func : module->functions) { + func.release(); + } + all.swap(module->functions); + module->updateMaps(); +} + +} // namespace OptUtils +} // namespace wasm + +#endif // wasm_passes_opt_utils_h diff --git a/src/passes/pass.cpp b/src/passes/pass.cpp index aa3ed8eb3..9215341e3 100644 --- a/src/passes/pass.cpp +++ b/src/passes/pass.cpp @@ -66,6 +66,8 @@ std::string PassRegistry::getPassDescription(std::string name) { // PassRunner void PassRegistry::registerPasses() { + registerPass("dae", "removes arguments to calls in an lto-like manner", createDAEPass); + registerPass("dae-optimizing", "removes arguments to calls in an lto-like manner, and optimizes where we removed", createDAEOptimizingPass); registerPass("coalesce-locals", "reduce # of locals by coalescing", createCoalesceLocalsPass); registerPass("coalesce-locals-learning", "reduce # of locals by coalescing and learning", createCoalesceLocalsWithLearningPass); registerPass("code-pushing", "push code forward, potentially making it not always execute", createCodePushingPass); @@ -200,6 +202,9 @@ void PassRunner::addDefaultGlobalOptimizationPrePasses() { } void PassRunner::addDefaultGlobalOptimizationPostPasses() { + if (options.optimizeLevel >= 2 || options.shrinkLevel >= 1) { + add("dae-optimizing"); + } // inline when working hard, and when not preserving debug info // (inlining+optimizing can remove the annotations) if ((options.optimizeLevel >= 2 || options.shrinkLevel >= 2) && diff --git a/src/passes/passes.h b/src/passes/passes.h index be0849075..b4cc56898 100644 --- a/src/passes/passes.h +++ b/src/passes/passes.h @@ -27,6 +27,8 @@ Pass* createCoalesceLocalsWithLearningPass(); Pass* createCodeFoldingPass(); Pass* createCodePushingPass(); Pass* createConstHoistingPass(); +Pass* createDAEPass(); +Pass* createDAEOptimizingPass(); Pass* createDataFlowOptsPass(); Pass* createDeadCodeEliminationPass(); Pass* createDuplicateFunctionEliminationPass(); diff --git a/src/support/sorted_vector.h b/src/support/sorted_vector.h index bb157f590..8f33de03a 100644 --- a/src/support/sorted_vector.h +++ b/src/support/sorted_vector.h @@ -25,7 +25,7 @@ namespace wasm { -struct SortedVector : std::vector<Index> { +struct SortedVector : public std::vector<Index> { SortedVector() {} SortedVector merge(const SortedVector& other) const { @@ -85,6 +85,20 @@ struct SortedVector : std::vector<Index> { return it != end() && *it == x; } + template<typename T> + SortedVector& filter(T keep) { + size_t skip = 0; + for (size_t i = 0; i < size(); i++) { + if (keep((*this)[i])) { + (*this)[i - skip] = (*this)[i]; + } else { + skip++; + } + } + resize(size() - skip); + return *this; + } + void verify() const { for (Index i = 1; i < size(); i++) { assert((*this)[i - 1] < (*this)[i]); diff --git a/src/wasm-builder.h b/src/wasm-builder.h index b8de8ce25..4032eb10a 100644 --- a/src/wasm-builder.h +++ b/src/wasm-builder.h @@ -389,11 +389,15 @@ public: return addVar(func, Name(), type); } + static void clearLocalNames(Function* func) { + func->localNames.clear(); + func->localIndices.clear(); + } + static void clearLocals(Function* func) { func->params.clear(); func->vars.clear(); - func->localNames.clear(); - func->localIndices.clear(); + clearLocalNames(func); } // ensure a node is a block, if it isn't already, and optionally append to the block diff --git a/src/wasm-module-building.h b/src/wasm-module-building.h index d03eef7c8..e92436952 100644 --- a/src/wasm-module-building.h +++ b/src/wasm-module-building.h @@ -37,7 +37,10 @@ static std::mutex debug; // starts optimizing using worker threads *while you are still adding*. // It runs function optimization passes at that time. This does not // run global optimization after that by default, but you can do that -// to by calling optimizeGlobally(). +// to by calling optimizeGlobally(), which runs the the global post-passes +// (we can't run the pre-passes, as they must be run before function +// passes, and no such time is possible here given that we receive +// functions one by one and optimize them). // // This might also be faster than normal module optimization since it // runs all passes on each function, then goes on to the next function diff --git a/test/emcc_O2_hello_world.fromasm b/test/emcc_O2_hello_world.fromasm index 0566193d0..5bc940d9f 100644 --- a/test/emcc_O2_hello_world.fromasm +++ b/test/emcc_O2_hello_world.fromasm @@ -8488,7 +8488,8 @@ (get_local $3) ) ) - (func $___overflow (; 21 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) + (func $___overflow (; 21 ;) (; has Stack IR ;) (param $0 i32) (result i32) + (local $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -8496,9 +8497,7 @@ (local $6 i32) (local $7 i32) (local $8 i32) - (local $9 i32) - (local $10 i32) - (set_local $5 + (set_local $4 (get_global $STACKTOP) ) (set_global $STACKTOP @@ -8508,20 +8507,15 @@ ) ) (i32.store8 - (tee_local $6 - (get_local $5) - ) - (tee_local $9 - (i32.and - (get_local $1) - (i32.const 255) - ) + (tee_local $5 + (get_local $4) ) + (i32.const 10) ) (if - (tee_local $3 + (tee_local $2 (i32.load - (tee_local $2 + (tee_local $1 (i32.add (get_local $0) (i32.const 16) @@ -8530,10 +8524,10 @@ ) ) (block - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $2) ) - (set_local $8 + (set_local $7 (i32.const 4) ) ) @@ -8541,16 +8535,16 @@ (call $___towrite (get_local $0) ) - (set_local $4 + (set_local $3 (i32.const -1) ) (block - (set_local $7 + (set_local $6 (i32.load - (get_local $2) + (get_local $1) ) ) - (set_local $8 + (set_local $7 (i32.const 4) ) ) @@ -8559,16 +8553,16 @@ (block $do-once (if (i32.eq - (get_local $8) + (get_local $7) (i32.const 4) ) (block (if (if (result i32) (i32.lt_u - (tee_local $2 + (tee_local $1 (i32.load - (tee_local $3 + (tee_local $2 (i32.add (get_local $0) (i32.const 20) @@ -8576,14 +8570,11 @@ ) ) ) - (get_local $7) + (get_local $6) ) (i32.ne - (tee_local $10 - (i32.and - (get_local $1) - (i32.const 255) - ) + (tee_local $8 + (i32.const 10) ) (i32.load8_s offset=75 (get_local $0) @@ -8593,28 +8584,28 @@ ) (block (i32.store - (get_local $3) + (get_local $2) (i32.add - (get_local $2) + (get_local $1) (i32.const 1) ) ) (i32.store8 - (get_local $2) - (get_local $9) + (get_local $1) + (i32.const 10) ) - (set_local $4 - (get_local $10) + (set_local $3 + (get_local $8) ) (br $do-once) ) ) - (set_local $4 + (set_local $3 (if (result i32) (i32.eq (call_indirect (type $FUNCSIG$iiii) (get_local $0) - (get_local $6) + (get_local $5) (i32.const 1) (i32.add (i32.and @@ -8629,7 +8620,7 @@ (i32.const 1) ) (i32.load8_u - (get_local $6) + (get_local $5) ) (i32.const -1) ) @@ -8638,9 +8629,9 @@ ) ) (set_global $STACKTOP - (get_local $5) + (get_local $4) ) - (get_local $4) + (get_local $3) ) (func $___fflush_unlocked (; 22 ;) (; has Stack IR ;) (param $0 i32) (result i32) (local $1 i32) @@ -9053,13 +9044,13 @@ (get_local $2) ) ) - (func $_puts (; 26 ;) (; has Stack IR ;) (param $0 i32) (result i32) + (func $_puts (; 26 ;) (; has Stack IR ;) (result i32) + (local $0 i32) (local $1 i32) (local $2 i32) - (local $3 i32) (drop (i32.load offset=76 - (tee_local $1 + (tee_local $0 (i32.load (i32.const 52) ) @@ -9074,12 +9065,11 @@ (i32.lt_s (i32.add (call $_fwrite - (get_local $0) + (i32.const 672) (call $_strlen - (get_local $0) + (i32.const 672) ) - (i32.const 1) - (get_local $1) + (get_local $0) ) (i32.const -1) ) @@ -9091,37 +9081,37 @@ (if (result i32) (i32.ne (i32.load8_s offset=75 - (get_local $1) + (get_local $0) ) (i32.const 10) ) (i32.lt_u - (tee_local $2 + (tee_local $1 (i32.load - (tee_local $3 + (tee_local $2 (i32.add - (get_local $1) + (get_local $0) (i32.const 20) ) ) ) ) (i32.load offset=16 - (get_local $1) + (get_local $0) ) ) (i32.const 0) ) (block (i32.store - (get_local $3) + (get_local $2) (i32.add - (get_local $2) + (get_local $1) (i32.const 1) ) ) (i32.store8 - (get_local $2) + (get_local $1) (i32.const 10) ) (br $do-once @@ -9131,8 +9121,7 @@ ) (i32.lt_s (call $___overflow - (get_local $1) - (i32.const 10) + (get_local $0) ) (i32.const 0) ) @@ -9292,33 +9281,34 @@ ) ) ) - (func $_fwrite (; 29 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) + (func $_fwrite (; 29 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (local $3 i32) (local $4 i32) (set_local $4 - (i32.mul - (get_local $2) - (get_local $1) - ) + (i32.const 1) + ) + (set_local $3 + (get_local $1) ) (if (block (result i32) (drop (i32.load offset=76 - (get_local $3) + (get_local $2) ) ) (i32.ne (tee_local $0 (call $___fwritex (get_local $0) - (get_local $4) (get_local $3) + (get_local $2) ) ) - (get_local $4) + (get_local $3) ) ) - (set_local $2 + (set_local $4 (if (result i32) (get_local $1) (i32.div_u @@ -9329,7 +9319,7 @@ ) ) ) - (get_local $2) + (get_local $4) ) (func $___stdout_write (; 30 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) @@ -9574,9 +9564,7 @@ ) (func $_main (; 46 ;) (; has Stack IR ;) (result i32) (drop - (call $_puts - (i32.const 672) - ) + (call $_puts) ) (i32.const 0) ) diff --git a/test/emcc_O2_hello_world.fromasm.clamp b/test/emcc_O2_hello_world.fromasm.clamp index 0566193d0..5bc940d9f 100644 --- a/test/emcc_O2_hello_world.fromasm.clamp +++ b/test/emcc_O2_hello_world.fromasm.clamp @@ -8488,7 +8488,8 @@ (get_local $3) ) ) - (func $___overflow (; 21 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) + (func $___overflow (; 21 ;) (; has Stack IR ;) (param $0 i32) (result i32) + (local $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -8496,9 +8497,7 @@ (local $6 i32) (local $7 i32) (local $8 i32) - (local $9 i32) - (local $10 i32) - (set_local $5 + (set_local $4 (get_global $STACKTOP) ) (set_global $STACKTOP @@ -8508,20 +8507,15 @@ ) ) (i32.store8 - (tee_local $6 - (get_local $5) - ) - (tee_local $9 - (i32.and - (get_local $1) - (i32.const 255) - ) + (tee_local $5 + (get_local $4) ) + (i32.const 10) ) (if - (tee_local $3 + (tee_local $2 (i32.load - (tee_local $2 + (tee_local $1 (i32.add (get_local $0) (i32.const 16) @@ -8530,10 +8524,10 @@ ) ) (block - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $2) ) - (set_local $8 + (set_local $7 (i32.const 4) ) ) @@ -8541,16 +8535,16 @@ (call $___towrite (get_local $0) ) - (set_local $4 + (set_local $3 (i32.const -1) ) (block - (set_local $7 + (set_local $6 (i32.load - (get_local $2) + (get_local $1) ) ) - (set_local $8 + (set_local $7 (i32.const 4) ) ) @@ -8559,16 +8553,16 @@ (block $do-once (if (i32.eq - (get_local $8) + (get_local $7) (i32.const 4) ) (block (if (if (result i32) (i32.lt_u - (tee_local $2 + (tee_local $1 (i32.load - (tee_local $3 + (tee_local $2 (i32.add (get_local $0) (i32.const 20) @@ -8576,14 +8570,11 @@ ) ) ) - (get_local $7) + (get_local $6) ) (i32.ne - (tee_local $10 - (i32.and - (get_local $1) - (i32.const 255) - ) + (tee_local $8 + (i32.const 10) ) (i32.load8_s offset=75 (get_local $0) @@ -8593,28 +8584,28 @@ ) (block (i32.store - (get_local $3) + (get_local $2) (i32.add - (get_local $2) + (get_local $1) (i32.const 1) ) ) (i32.store8 - (get_local $2) - (get_local $9) + (get_local $1) + (i32.const 10) ) - (set_local $4 - (get_local $10) + (set_local $3 + (get_local $8) ) (br $do-once) ) ) - (set_local $4 + (set_local $3 (if (result i32) (i32.eq (call_indirect (type $FUNCSIG$iiii) (get_local $0) - (get_local $6) + (get_local $5) (i32.const 1) (i32.add (i32.and @@ -8629,7 +8620,7 @@ (i32.const 1) ) (i32.load8_u - (get_local $6) + (get_local $5) ) (i32.const -1) ) @@ -8638,9 +8629,9 @@ ) ) (set_global $STACKTOP - (get_local $5) + (get_local $4) ) - (get_local $4) + (get_local $3) ) (func $___fflush_unlocked (; 22 ;) (; has Stack IR ;) (param $0 i32) (result i32) (local $1 i32) @@ -9053,13 +9044,13 @@ (get_local $2) ) ) - (func $_puts (; 26 ;) (; has Stack IR ;) (param $0 i32) (result i32) + (func $_puts (; 26 ;) (; has Stack IR ;) (result i32) + (local $0 i32) (local $1 i32) (local $2 i32) - (local $3 i32) (drop (i32.load offset=76 - (tee_local $1 + (tee_local $0 (i32.load (i32.const 52) ) @@ -9074,12 +9065,11 @@ (i32.lt_s (i32.add (call $_fwrite - (get_local $0) + (i32.const 672) (call $_strlen - (get_local $0) + (i32.const 672) ) - (i32.const 1) - (get_local $1) + (get_local $0) ) (i32.const -1) ) @@ -9091,37 +9081,37 @@ (if (result i32) (i32.ne (i32.load8_s offset=75 - (get_local $1) + (get_local $0) ) (i32.const 10) ) (i32.lt_u - (tee_local $2 + (tee_local $1 (i32.load - (tee_local $3 + (tee_local $2 (i32.add - (get_local $1) + (get_local $0) (i32.const 20) ) ) ) ) (i32.load offset=16 - (get_local $1) + (get_local $0) ) ) (i32.const 0) ) (block (i32.store - (get_local $3) + (get_local $2) (i32.add - (get_local $2) + (get_local $1) (i32.const 1) ) ) (i32.store8 - (get_local $2) + (get_local $1) (i32.const 10) ) (br $do-once @@ -9131,8 +9121,7 @@ ) (i32.lt_s (call $___overflow - (get_local $1) - (i32.const 10) + (get_local $0) ) (i32.const 0) ) @@ -9292,33 +9281,34 @@ ) ) ) - (func $_fwrite (; 29 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) + (func $_fwrite (; 29 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (local $3 i32) (local $4 i32) (set_local $4 - (i32.mul - (get_local $2) - (get_local $1) - ) + (i32.const 1) + ) + (set_local $3 + (get_local $1) ) (if (block (result i32) (drop (i32.load offset=76 - (get_local $3) + (get_local $2) ) ) (i32.ne (tee_local $0 (call $___fwritex (get_local $0) - (get_local $4) (get_local $3) + (get_local $2) ) ) - (get_local $4) + (get_local $3) ) ) - (set_local $2 + (set_local $4 (if (result i32) (get_local $1) (i32.div_u @@ -9329,7 +9319,7 @@ ) ) ) - (get_local $2) + (get_local $4) ) (func $___stdout_write (; 30 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) @@ -9574,9 +9564,7 @@ ) (func $_main (; 46 ;) (; has Stack IR ;) (result i32) (drop - (call $_puts - (i32.const 672) - ) + (call $_puts) ) (i32.const 0) ) diff --git a/test/emcc_O2_hello_world.fromasm.imprecise b/test/emcc_O2_hello_world.fromasm.imprecise index d34cf8655..bbc3b3373 100644 --- a/test/emcc_O2_hello_world.fromasm.imprecise +++ b/test/emcc_O2_hello_world.fromasm.imprecise @@ -8482,7 +8482,8 @@ (get_local $3) ) ) - (func $___overflow (; 21 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) + (func $___overflow (; 21 ;) (; has Stack IR ;) (param $0 i32) (result i32) + (local $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -8490,9 +8491,7 @@ (local $6 i32) (local $7 i32) (local $8 i32) - (local $9 i32) - (local $10 i32) - (set_local $5 + (set_local $4 (get_global $STACKTOP) ) (set_global $STACKTOP @@ -8502,20 +8501,15 @@ ) ) (i32.store8 - (tee_local $6 - (get_local $5) - ) - (tee_local $9 - (i32.and - (get_local $1) - (i32.const 255) - ) + (tee_local $5 + (get_local $4) ) + (i32.const 10) ) (if - (tee_local $3 + (tee_local $2 (i32.load - (tee_local $2 + (tee_local $1 (i32.add (get_local $0) (i32.const 16) @@ -8524,10 +8518,10 @@ ) ) (block - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $2) ) - (set_local $8 + (set_local $7 (i32.const 4) ) ) @@ -8535,16 +8529,16 @@ (call $___towrite (get_local $0) ) - (set_local $4 + (set_local $3 (i32.const -1) ) (block - (set_local $7 + (set_local $6 (i32.load - (get_local $2) + (get_local $1) ) ) - (set_local $8 + (set_local $7 (i32.const 4) ) ) @@ -8553,16 +8547,16 @@ (block $do-once (if (i32.eq - (get_local $8) + (get_local $7) (i32.const 4) ) (block (if (if (result i32) (i32.lt_u - (tee_local $2 + (tee_local $1 (i32.load - (tee_local $3 + (tee_local $2 (i32.add (get_local $0) (i32.const 20) @@ -8570,14 +8564,11 @@ ) ) ) - (get_local $7) + (get_local $6) ) (i32.ne - (tee_local $10 - (i32.and - (get_local $1) - (i32.const 255) - ) + (tee_local $8 + (i32.const 10) ) (i32.load8_s offset=75 (get_local $0) @@ -8587,28 +8578,28 @@ ) (block (i32.store - (get_local $3) + (get_local $2) (i32.add - (get_local $2) + (get_local $1) (i32.const 1) ) ) (i32.store8 - (get_local $2) - (get_local $9) + (get_local $1) + (i32.const 10) ) - (set_local $4 - (get_local $10) + (set_local $3 + (get_local $8) ) (br $do-once) ) ) - (set_local $4 + (set_local $3 (if (result i32) (i32.eq (call_indirect (type $FUNCSIG$iiii) (get_local $0) - (get_local $6) + (get_local $5) (i32.const 1) (i32.add (i32.and @@ -8623,7 +8614,7 @@ (i32.const 1) ) (i32.load8_u - (get_local $6) + (get_local $5) ) (i32.const -1) ) @@ -8632,9 +8623,9 @@ ) ) (set_global $STACKTOP - (get_local $5) + (get_local $4) ) - (get_local $4) + (get_local $3) ) (func $___fflush_unlocked (; 22 ;) (; has Stack IR ;) (param $0 i32) (result i32) (local $1 i32) @@ -9047,13 +9038,13 @@ (get_local $2) ) ) - (func $_puts (; 26 ;) (; has Stack IR ;) (param $0 i32) (result i32) + (func $_puts (; 26 ;) (; has Stack IR ;) (result i32) + (local $0 i32) (local $1 i32) (local $2 i32) - (local $3 i32) (drop (i32.load offset=76 - (tee_local $1 + (tee_local $0 (i32.load (i32.const 52) ) @@ -9068,12 +9059,11 @@ (i32.lt_s (i32.add (call $_fwrite - (get_local $0) + (i32.const 672) (call $_strlen - (get_local $0) + (i32.const 672) ) - (i32.const 1) - (get_local $1) + (get_local $0) ) (i32.const -1) ) @@ -9085,37 +9075,37 @@ (if (result i32) (i32.ne (i32.load8_s offset=75 - (get_local $1) + (get_local $0) ) (i32.const 10) ) (i32.lt_u - (tee_local $2 + (tee_local $1 (i32.load - (tee_local $3 + (tee_local $2 (i32.add - (get_local $1) + (get_local $0) (i32.const 20) ) ) ) ) (i32.load offset=16 - (get_local $1) + (get_local $0) ) ) (i32.const 0) ) (block (i32.store - (get_local $3) + (get_local $2) (i32.add - (get_local $2) + (get_local $1) (i32.const 1) ) ) (i32.store8 - (get_local $2) + (get_local $1) (i32.const 10) ) (br $do-once @@ -9125,8 +9115,7 @@ ) (i32.lt_s (call $___overflow - (get_local $1) - (i32.const 10) + (get_local $0) ) (i32.const 0) ) @@ -9286,33 +9275,34 @@ ) ) ) - (func $_fwrite (; 29 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) + (func $_fwrite (; 29 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (local $3 i32) (local $4 i32) (set_local $4 - (i32.mul - (get_local $2) - (get_local $1) - ) + (i32.const 1) + ) + (set_local $3 + (get_local $1) ) (if (i32.ne (tee_local $0 (call $___fwritex (get_local $0) - (get_local $4) (get_local $3) + (get_local $2) ) ) - (get_local $4) + (get_local $3) ) - (set_local $2 + (set_local $4 (i32.div_u (get_local $0) (get_local $1) ) ) ) - (get_local $2) + (get_local $4) ) (func $___stdout_write (; 30 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) @@ -9553,9 +9543,7 @@ ) (func $_main (; 46 ;) (; has Stack IR ;) (result i32) (drop - (call $_puts - (i32.const 672) - ) + (call $_puts) ) (i32.const 0) ) diff --git a/test/emcc_hello_world.fromasm b/test/emcc_hello_world.fromasm index 6811213dc..cffc2ad79 100644 --- a/test/emcc_hello_world.fromasm +++ b/test/emcc_hello_world.fromasm @@ -151,7 +151,6 @@ ) (drop (call $_printf - (i32.const 672) (get_local $0) ) ) @@ -571,10 +570,8 @@ ) ) (set_local $0 - (tee_local $1 - (call $___fflush_unlocked - (get_local $0) - ) + (call $___fflush_unlocked + (get_local $0) ) ) ) @@ -642,9 +639,9 @@ ) (get_local $0) ) - (func $_printf (; 34 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - (set_local $2 + (func $_printf (; 34 ;) (; has Stack IR ;) (param $0 i32) (result i32) + (local $1 i32) + (set_local $1 (get_global $STACKTOP) ) (set_global $STACKTOP @@ -661,20 +658,20 @@ (call $abort) ) (i32.store - (get_local $2) (get_local $1) + (get_local $0) ) (set_local $0 (call $_vfprintf (i32.load (i32.const 8) ) - (get_local $0) - (get_local $2) + (i32.const 672) + (get_local $1) ) ) (set_global $STACKTOP - (get_local $2) + (get_local $1) ) (get_local $0) ) @@ -1564,7 +1561,7 @@ ) ) ) - (func $_wcrtomb (; 39 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $_wcrtomb (; 39 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) (block $do-once (result i32) (if (result i32) (get_local $0) @@ -1744,28 +1741,20 @@ (call $_wcrtomb (get_local $0) (get_local $1) - (i32.const 0) ) (i32.const 0) ) ) - (func $_memchr (; 41 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $_memchr (; 41 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) (local $3 i32) - (local $4 i32) - (local $5 i32) - (set_local $5 - (i32.and - (get_local $1) - (i32.const 255) - ) - ) (block $label$break$L8 (block $__rjti$2 (if (i32.and - (tee_local $4 + (tee_local $3 (i32.ne - (get_local $2) + (get_local $1) (i32.const 0) ) ) @@ -1778,27 +1767,17 @@ ) ) (block - (set_local $4 - (i32.and - (get_local $1) - (i32.const 255) - ) - ) - (set_local $3 - (get_local $2) - ) (set_local $2 + (get_local $1) + ) + (set_local $1 (get_local $0) ) (loop $while-in (br_if $__rjti$2 - (i32.eq + (i32.eqz (i32.load8_u - (get_local $2) - ) - (i32.and - (get_local $4) - (i32.const 255) + (get_local $1) ) ) ) @@ -1806,9 +1785,9 @@ (i32.and (tee_local $0 (i32.ne - (tee_local $3 + (tee_local $2 (i32.add - (get_local $3) + (get_local $2) (i32.const -1) ) ) @@ -1817,9 +1796,9 @@ ) (i32.ne (i32.and - (tee_local $2 + (tee_local $1 (i32.add - (get_local $2) + (get_local $1) (i32.const 1) ) ) @@ -1832,14 +1811,14 @@ ) ) (block - (set_local $3 - (get_local $2) - ) (set_local $2 + (get_local $1) + ) + (set_local $1 (get_local $0) ) (set_local $0 - (get_local $4) + (get_local $3) ) ) ) @@ -1852,27 +1831,13 @@ (br $label$break$L8) ) (set_local $0 - (get_local $3) + (get_local $2) ) (if - (i32.ne - (i32.load8_u - (get_local $2) - ) - (tee_local $1 - (i32.and - (get_local $1) - (i32.const 255) - ) - ) + (i32.load8_u + (get_local $1) ) (block - (set_local $3 - (i32.mul - (get_local $5) - (i32.const 16843009) - ) - ) (block $__rjto$0 (block $__rjti$0 (br_if $__rjti$0 @@ -1887,12 +1852,9 @@ (i32.and (i32.xor (i32.and - (tee_local $4 - (i32.xor - (i32.load - (get_local $2) - ) - (get_local $3) + (tee_local $3 + (i32.load + (get_local $1) ) ) (i32.const -2139062144) @@ -1900,15 +1862,15 @@ (i32.const -2139062144) ) (i32.add - (get_local $4) + (get_local $3) (i32.const -16843009) ) ) ) (block - (set_local $2 + (set_local $1 (i32.add - (get_local $2) + (get_local $1) (i32.const 4) ) ) @@ -1943,19 +1905,15 @@ ) (loop $while-in5 (br_if $label$break$L8 - (i32.eq + (i32.eqz (i32.load8_u - (get_local $2) - ) - (i32.and (get_local $1) - (i32.const 255) ) ) ) - (set_local $2 + (set_local $1 (i32.add - (get_local $2) + (get_local $1) (i32.const 1) ) ) @@ -1975,7 +1933,7 @@ ) ) (select - (get_local $2) + (get_local $1) (i32.const 0) (get_local $0) ) @@ -4539,7 +4497,6 @@ (get_global $tempRet0) ) (i32.const 1000000000) - (i32.const 0) ) ) (set_local $12 @@ -4547,7 +4504,6 @@ (get_local $12) (get_local $18) (i32.const 1000000000) - (i32.const 0) ) ) (br_if $while-in66 @@ -6482,7 +6438,6 @@ (tee_local $13 (call $_memchr (get_local $7) - (i32.const 0) (get_local $6) ) ) @@ -7424,7 +7379,6 @@ (get_local $0) (get_local $1) (i32.const 10) - (i32.const 0) ) ) (i32.const 48) @@ -7435,7 +7389,6 @@ (get_local $0) (get_local $1) (i32.const 10) - (i32.const 0) ) ) (set_local $4 @@ -15310,18 +15263,18 @@ ) (get_local $3) ) - (func $___udivdi3 (; 61 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) + (func $___udivdi3 (; 61 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (call $___udivmoddi4 (get_local $0) (get_local $1) (get_local $2) - (get_local $3) + (i32.const 0) (i32.const 0) ) ) - (func $___uremdi3 (; 62 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) - (local $4 i32) - (set_local $4 + (func $___uremdi3 (; 62 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (local $3 i32) + (set_local $3 (get_global $STACKTOP) ) (set_global $STACKTOP @@ -15335,20 +15288,20 @@ (get_local $0) (get_local $1) (get_local $2) + (i32.const 0) (get_local $3) - (get_local $4) ) ) (set_global $STACKTOP - (get_local $4) + (get_local $3) ) (set_global $tempRet0 (i32.load offset=4 - (get_local $4) + (get_local $3) ) ) (i32.load - (get_local $4) + (get_local $3) ) ) (func $___udivmoddi4 (; 63 ;) (; has Stack IR ;) (param $xl i32) (param $xh i32) (param $yl i32) (param $yh i32) (param $r i32) (result i32) diff --git a/test/emcc_hello_world.fromasm.clamp b/test/emcc_hello_world.fromasm.clamp index ea687d264..17c1a9336 100644 --- a/test/emcc_hello_world.fromasm.clamp +++ b/test/emcc_hello_world.fromasm.clamp @@ -149,7 +149,6 @@ ) (drop (call $_printf - (i32.const 672) (get_local $0) ) ) @@ -569,10 +568,8 @@ ) ) (set_local $0 - (tee_local $1 - (call $___fflush_unlocked - (get_local $0) - ) + (call $___fflush_unlocked + (get_local $0) ) ) ) @@ -640,9 +637,9 @@ ) (get_local $0) ) - (func $_printf (; 33 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - (set_local $2 + (func $_printf (; 33 ;) (; has Stack IR ;) (param $0 i32) (result i32) + (local $1 i32) + (set_local $1 (get_global $STACKTOP) ) (set_global $STACKTOP @@ -659,20 +656,20 @@ (call $abort) ) (i32.store - (get_local $2) (get_local $1) + (get_local $0) ) (set_local $0 (call $_vfprintf (i32.load (i32.const 8) ) - (get_local $0) - (get_local $2) + (i32.const 672) + (get_local $1) ) ) (set_global $STACKTOP - (get_local $2) + (get_local $1) ) (get_local $0) ) @@ -1562,7 +1559,7 @@ ) ) ) - (func $_wcrtomb (; 38 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $_wcrtomb (; 38 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) (block $do-once (result i32) (if (result i32) (get_local $0) @@ -1742,28 +1739,20 @@ (call $_wcrtomb (get_local $0) (get_local $1) - (i32.const 0) ) (i32.const 0) ) ) - (func $_memchr (; 40 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $_memchr (; 40 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) (local $3 i32) - (local $4 i32) - (local $5 i32) - (set_local $5 - (i32.and - (get_local $1) - (i32.const 255) - ) - ) (block $label$break$L8 (block $__rjti$2 (if (i32.and - (tee_local $4 + (tee_local $3 (i32.ne - (get_local $2) + (get_local $1) (i32.const 0) ) ) @@ -1776,27 +1765,17 @@ ) ) (block - (set_local $4 - (i32.and - (get_local $1) - (i32.const 255) - ) - ) - (set_local $3 - (get_local $2) - ) (set_local $2 + (get_local $1) + ) + (set_local $1 (get_local $0) ) (loop $while-in (br_if $__rjti$2 - (i32.eq + (i32.eqz (i32.load8_u - (get_local $2) - ) - (i32.and - (get_local $4) - (i32.const 255) + (get_local $1) ) ) ) @@ -1804,9 +1783,9 @@ (i32.and (tee_local $0 (i32.ne - (tee_local $3 + (tee_local $2 (i32.add - (get_local $3) + (get_local $2) (i32.const -1) ) ) @@ -1815,9 +1794,9 @@ ) (i32.ne (i32.and - (tee_local $2 + (tee_local $1 (i32.add - (get_local $2) + (get_local $1) (i32.const 1) ) ) @@ -1830,14 +1809,14 @@ ) ) (block - (set_local $3 - (get_local $2) - ) (set_local $2 + (get_local $1) + ) + (set_local $1 (get_local $0) ) (set_local $0 - (get_local $4) + (get_local $3) ) ) ) @@ -1850,27 +1829,13 @@ (br $label$break$L8) ) (set_local $0 - (get_local $3) + (get_local $2) ) (if - (i32.ne - (i32.load8_u - (get_local $2) - ) - (tee_local $1 - (i32.and - (get_local $1) - (i32.const 255) - ) - ) + (i32.load8_u + (get_local $1) ) (block - (set_local $3 - (i32.mul - (get_local $5) - (i32.const 16843009) - ) - ) (block $__rjto$0 (block $__rjti$0 (br_if $__rjti$0 @@ -1885,12 +1850,9 @@ (i32.and (i32.xor (i32.and - (tee_local $4 - (i32.xor - (i32.load - (get_local $2) - ) - (get_local $3) + (tee_local $3 + (i32.load + (get_local $1) ) ) (i32.const -2139062144) @@ -1898,15 +1860,15 @@ (i32.const -2139062144) ) (i32.add - (get_local $4) + (get_local $3) (i32.const -16843009) ) ) ) (block - (set_local $2 + (set_local $1 (i32.add - (get_local $2) + (get_local $1) (i32.const 4) ) ) @@ -1941,19 +1903,15 @@ ) (loop $while-in5 (br_if $label$break$L8 - (i32.eq + (i32.eqz (i32.load8_u - (get_local $2) - ) - (i32.and (get_local $1) - (i32.const 255) ) ) ) - (set_local $2 + (set_local $1 (i32.add - (get_local $2) + (get_local $1) (i32.const 1) ) ) @@ -1973,7 +1931,7 @@ ) ) (select - (get_local $2) + (get_local $1) (i32.const 0) (get_local $0) ) @@ -4589,7 +4547,6 @@ (get_global $tempRet0) ) (i32.const 1000000000) - (i32.const 0) ) ) (set_local $12 @@ -4597,7 +4554,6 @@ (get_local $12) (get_local $18) (i32.const 1000000000) - (i32.const 0) ) ) (br_if $while-in66 @@ -6532,7 +6488,6 @@ (tee_local $13 (call $_memchr (get_local $7) - (i32.const 0) (get_local $6) ) ) @@ -7474,7 +7429,6 @@ (get_local $0) (get_local $1) (i32.const 10) - (i32.const 0) ) ) (i32.const 48) @@ -7485,7 +7439,6 @@ (get_local $0) (get_local $1) (i32.const 10) - (i32.const 0) ) ) (set_local $4 @@ -15360,18 +15313,18 @@ ) (get_local $3) ) - (func $___udivdi3 (; 62 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) + (func $___udivdi3 (; 62 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (call $___udivmoddi4 (get_local $0) (get_local $1) (get_local $2) - (get_local $3) + (i32.const 0) (i32.const 0) ) ) - (func $___uremdi3 (; 63 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) - (local $4 i32) - (set_local $4 + (func $___uremdi3 (; 63 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (local $3 i32) + (set_local $3 (get_global $STACKTOP) ) (set_global $STACKTOP @@ -15385,20 +15338,20 @@ (get_local $0) (get_local $1) (get_local $2) + (i32.const 0) (get_local $3) - (get_local $4) ) ) (set_global $STACKTOP - (get_local $4) + (get_local $3) ) (set_global $tempRet0 (i32.load offset=4 - (get_local $4) + (get_local $3) ) ) (i32.load - (get_local $4) + (get_local $3) ) ) (func $___udivmoddi4 (; 64 ;) (; has Stack IR ;) (param $xl i32) (param $xh i32) (param $yl i32) (param $yh i32) (param $r i32) (result i32) diff --git a/test/emcc_hello_world.fromasm.imprecise b/test/emcc_hello_world.fromasm.imprecise index 25ca0c3da..46a1c48c4 100644 --- a/test/emcc_hello_world.fromasm.imprecise +++ b/test/emcc_hello_world.fromasm.imprecise @@ -148,7 +148,6 @@ ) (drop (call $_printf - (i32.const 672) (get_local $0) ) ) @@ -568,10 +567,8 @@ ) ) (set_local $0 - (tee_local $1 - (call $___fflush_unlocked - (get_local $0) - ) + (call $___fflush_unlocked + (get_local $0) ) ) ) @@ -634,9 +631,9 @@ ) (get_local $0) ) - (func $_printf (; 33 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - (set_local $2 + (func $_printf (; 33 ;) (; has Stack IR ;) (param $0 i32) (result i32) + (local $1 i32) + (set_local $1 (get_global $STACKTOP) ) (set_global $STACKTOP @@ -653,20 +650,20 @@ (call $abort) ) (i32.store - (get_local $2) (get_local $1) + (get_local $0) ) (set_local $0 (call $_vfprintf (i32.load (i32.const 8) ) - (get_local $0) - (get_local $2) + (i32.const 672) + (get_local $1) ) ) (set_global $STACKTOP - (get_local $2) + (get_local $1) ) (get_local $0) ) @@ -1027,7 +1024,6 @@ (local $11 i32) (local $12 i32) (local $13 i32) - (local $14 i32) (set_local $4 (get_global $STACKTOP) ) @@ -1551,7 +1547,7 @@ ) ) ) - (func $_wcrtomb (; 38 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $_wcrtomb (; 38 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) (block $do-once (result i32) (if (result i32) (get_local $0) @@ -1731,28 +1727,20 @@ (call $_wcrtomb (get_local $0) (get_local $1) - (i32.const 0) ) (i32.const 0) ) ) - (func $_memchr (; 40 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $_memchr (; 40 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) (local $3 i32) - (local $4 i32) - (local $5 i32) - (set_local $5 - (i32.and - (get_local $1) - (i32.const 255) - ) - ) (block $label$break$L8 (block $__rjti$2 (if (i32.and - (tee_local $4 + (tee_local $3 (i32.ne - (get_local $2) + (get_local $1) (i32.const 0) ) ) @@ -1765,27 +1753,17 @@ ) ) (block - (set_local $4 - (i32.and - (get_local $1) - (i32.const 255) - ) - ) - (set_local $3 - (get_local $2) - ) (set_local $2 + (get_local $1) + ) + (set_local $1 (get_local $0) ) (loop $while-in (br_if $__rjti$2 - (i32.eq + (i32.eqz (i32.load8_u - (get_local $2) - ) - (i32.and - (get_local $4) - (i32.const 255) + (get_local $1) ) ) ) @@ -1793,9 +1771,9 @@ (i32.and (tee_local $0 (i32.ne - (tee_local $3 + (tee_local $2 (i32.add - (get_local $3) + (get_local $2) (i32.const -1) ) ) @@ -1804,9 +1782,9 @@ ) (i32.ne (i32.and - (tee_local $2 + (tee_local $1 (i32.add - (get_local $2) + (get_local $1) (i32.const 1) ) ) @@ -1819,14 +1797,14 @@ ) ) (block - (set_local $3 - (get_local $2) - ) (set_local $2 + (get_local $1) + ) + (set_local $1 (get_local $0) ) (set_local $0 - (get_local $4) + (get_local $3) ) ) ) @@ -1839,27 +1817,13 @@ (br $label$break$L8) ) (set_local $0 - (get_local $3) + (get_local $2) ) (if - (i32.ne - (i32.load8_u - (get_local $2) - ) - (tee_local $1 - (i32.and - (get_local $1) - (i32.const 255) - ) - ) + (i32.load8_u + (get_local $1) ) (block - (set_local $3 - (i32.mul - (get_local $5) - (i32.const 16843009) - ) - ) (block $__rjto$0 (block $__rjti$0 (br_if $__rjti$0 @@ -1874,12 +1838,9 @@ (i32.and (i32.xor (i32.and - (tee_local $4 - (i32.xor - (i32.load - (get_local $2) - ) - (get_local $3) + (tee_local $3 + (i32.load + (get_local $1) ) ) (i32.const -2139062144) @@ -1887,15 +1848,15 @@ (i32.const -2139062144) ) (i32.add - (get_local $4) + (get_local $3) (i32.const -16843009) ) ) ) (block - (set_local $2 + (set_local $1 (i32.add - (get_local $2) + (get_local $1) (i32.const 4) ) ) @@ -1930,19 +1891,15 @@ ) (loop $while-in5 (br_if $label$break$L8 - (i32.eq + (i32.eqz (i32.load8_u - (get_local $2) - ) - (i32.and (get_local $1) - (i32.const 255) ) ) ) - (set_local $2 + (set_local $1 (i32.add - (get_local $2) + (get_local $1) (i32.const 1) ) ) @@ -1962,7 +1919,7 @@ ) ) (select - (get_local $2) + (get_local $1) (i32.const 0) (get_local $0) ) @@ -4460,7 +4417,6 @@ (get_global $tempRet0) ) (i32.const 1000000000) - (i32.const 0) ) ) (set_local $12 @@ -4468,7 +4424,6 @@ (get_local $12) (get_local $18) (i32.const 1000000000) - (i32.const 0) ) ) (br_if $while-in66 @@ -6397,7 +6352,6 @@ (tee_local $13 (call $_memchr (get_local $7) - (i32.const 0) (get_local $6) ) ) @@ -7339,7 +7293,6 @@ (get_local $0) (get_local $1) (i32.const 10) - (i32.const 0) ) ) (i32.const 48) @@ -7350,7 +7303,6 @@ (get_local $0) (get_local $1) (i32.const 10) - (i32.const 0) ) ) (set_local $4 @@ -15224,18 +15176,18 @@ ) (get_local $3) ) - (func $___udivdi3 (; 57 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) + (func $___udivdi3 (; 57 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (call $___udivmoddi4 (get_local $0) (get_local $1) (get_local $2) - (get_local $3) + (i32.const 0) (i32.const 0) ) ) - (func $___uremdi3 (; 58 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) - (local $4 i32) - (set_local $4 + (func $___uremdi3 (; 58 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (local $3 i32) + (set_local $3 (get_global $STACKTOP) ) (set_global $STACKTOP @@ -15249,20 +15201,20 @@ (get_local $0) (get_local $1) (get_local $2) + (i32.const 0) (get_local $3) - (get_local $4) ) ) (set_global $STACKTOP - (get_local $4) + (get_local $3) ) (set_global $tempRet0 (i32.load offset=4 - (get_local $4) + (get_local $3) ) ) (i32.load - (get_local $4) + (get_local $3) ) ) (func $___udivmoddi4 (; 59 ;) (; has Stack IR ;) (param $xl i32) (param $xh i32) (param $yl i32) (param $yh i32) (param $r i32) (result i32) diff --git a/test/memorygrowth.fromasm b/test/memorygrowth.fromasm index 5afec926b..8c400ab68 100644 --- a/test/memorygrowth.fromasm +++ b/test/memorygrowth.fromasm @@ -8532,16 +8532,15 @@ ) ) ) - (func $ab (; 19 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) + (func $ab (; 19 ;) (; has Stack IR ;) (param $0 i32) (result i32) + (local $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) (local $6 i32) (local $7 i32) - (local $8 i32) - (local $9 i32) - (set_local $5 + (set_local $4 (get_global $r) ) (set_global $r @@ -8551,20 +8550,15 @@ ) ) (i32.store8 - (tee_local $6 - (get_local $5) - ) - (tee_local $9 - (i32.and - (get_local $1) - (i32.const 255) - ) + (tee_local $5 + (get_local $4) ) + (i32.const 10) ) (if - (tee_local $3 + (tee_local $2 (i32.load - (tee_local $2 + (tee_local $1 (i32.add (get_local $0) (i32.const 16) @@ -8573,10 +8567,10 @@ ) ) (block - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $2) ) - (set_local $8 + (set_local $7 (i32.const 4) ) ) @@ -8584,16 +8578,16 @@ (call $Xa (get_local $0) ) - (set_local $4 + (set_local $3 (i32.const -1) ) (block - (set_local $7 + (set_local $6 (i32.load - (get_local $2) + (get_local $1) ) ) - (set_local $8 + (set_local $7 (i32.const 4) ) ) @@ -8602,15 +8596,15 @@ (block $do-once (if (i32.eq - (get_local $8) + (get_local $7) (i32.const 4) ) (block (if (i32.lt_u - (tee_local $2 + (tee_local $1 (i32.load - (tee_local $3 + (tee_local $2 (i32.add (get_local $0) (i32.const 20) @@ -8618,15 +8612,12 @@ ) ) ) - (get_local $7) + (get_local $6) ) (if (i32.ne - (tee_local $4 - (i32.and - (get_local $1) - (i32.const 255) - ) + (tee_local $3 + (i32.const 10) ) (i32.load8_s offset=75 (get_local $0) @@ -8634,26 +8625,26 @@ ) (block (i32.store - (get_local $3) + (get_local $2) (i32.add - (get_local $2) + (get_local $1) (i32.const 1) ) ) (i32.store8 - (get_local $2) - (get_local $9) + (get_local $1) + (i32.const 10) ) (br $do-once) ) ) ) - (set_local $4 + (set_local $3 (if (result i32) (i32.eq (call_indirect (type $FUNCSIG$iiii) (get_local $0) - (get_local $6) + (get_local $5) (i32.const 1) (i32.add (i32.and @@ -8668,7 +8659,7 @@ (i32.const 1) ) (i32.load8_u - (get_local $6) + (get_local $5) ) (i32.const -1) ) @@ -8677,9 +8668,9 @@ ) ) (set_global $r - (get_local $5) + (get_local $4) ) - (get_local $4) + (get_local $3) ) (func $$a (; 20 ;) (; has Stack IR ;) (param $0 i32) (result i32) (local $1 i32) @@ -9104,12 +9095,13 @@ (get_local $2) ) ) - (func $db (; 24 ;) (; has Stack IR ;) (param $0 i32) (result i32) + (func $db (; 24 ;) (; has Stack IR ;) (result i32) + (local $0 i32) (local $1 i32) (local $2 i32) (drop (i32.load offset=76 - (tee_local $1 + (tee_local $0 (i32.load (i32.const 1024) ) @@ -9118,18 +9110,17 @@ ) (i32.shr_s (i32.shl - (tee_local $0 + (tee_local $1 (block $do-once (result i32) (if (result i32) (i32.lt_s (i32.add (call $bb - (get_local $0) + (i32.const 1144) (call $Za - (get_local $0) + (i32.const 1144) ) - (i32.const 1) - (get_local $1) + (get_local $0) ) (i32.const -1) ) @@ -9140,36 +9131,36 @@ (if (i32.ne (i32.load8_s offset=75 - (get_local $1) + (get_local $0) ) (i32.const 10) ) (if (i32.lt_u - (tee_local $0 + (tee_local $1 (i32.load (tee_local $2 (i32.add - (get_local $1) + (get_local $0) (i32.const 20) ) ) ) ) (i32.load offset=16 - (get_local $1) + (get_local $0) ) ) (block (i32.store (get_local $2) (i32.add - (get_local $0) + (get_local $1) (i32.const 1) ) ) (i32.store8 - (get_local $0) + (get_local $1) (i32.const 10) ) (br $do-once @@ -9180,8 +9171,7 @@ ) (i32.lt_s (call $ab - (get_local $1) - (i32.const 10) + (get_local $0) ) (i32.const 0) ) @@ -9272,33 +9262,34 @@ ) ) ) - (func $bb (; 26 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) + (func $bb (; 26 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (local $3 i32) (local $4 i32) (set_local $4 - (i32.mul - (get_local $2) - (get_local $1) - ) + (i32.const 1) + ) + (set_local $3 + (get_local $1) ) (if (block (result i32) (drop (i32.load offset=76 - (get_local $3) + (get_local $2) ) ) (i32.ne (tee_local $0 (call $Wa (get_local $0) - (get_local $4) (get_local $3) + (get_local $2) ) ) - (get_local $4) + (get_local $3) ) ) - (set_local $2 + (set_local $4 (if (result i32) (get_local $1) (i32.div_u @@ -9309,7 +9300,7 @@ ) ) ) - (get_local $2) + (get_local $4) ) (func $Ua (; 27 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) @@ -9611,9 +9602,7 @@ ) (func $Na (; 41 ;) (; has Stack IR ;) (result i32) (drop - (call $db - (i32.const 1144) - ) + (call $db) ) (i32.const 0) ) diff --git a/test/memorygrowth.fromasm.clamp b/test/memorygrowth.fromasm.clamp index 5afec926b..8c400ab68 100644 --- a/test/memorygrowth.fromasm.clamp +++ b/test/memorygrowth.fromasm.clamp @@ -8532,16 +8532,15 @@ ) ) ) - (func $ab (; 19 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) + (func $ab (; 19 ;) (; has Stack IR ;) (param $0 i32) (result i32) + (local $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) (local $6 i32) (local $7 i32) - (local $8 i32) - (local $9 i32) - (set_local $5 + (set_local $4 (get_global $r) ) (set_global $r @@ -8551,20 +8550,15 @@ ) ) (i32.store8 - (tee_local $6 - (get_local $5) - ) - (tee_local $9 - (i32.and - (get_local $1) - (i32.const 255) - ) + (tee_local $5 + (get_local $4) ) + (i32.const 10) ) (if - (tee_local $3 + (tee_local $2 (i32.load - (tee_local $2 + (tee_local $1 (i32.add (get_local $0) (i32.const 16) @@ -8573,10 +8567,10 @@ ) ) (block - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $2) ) - (set_local $8 + (set_local $7 (i32.const 4) ) ) @@ -8584,16 +8578,16 @@ (call $Xa (get_local $0) ) - (set_local $4 + (set_local $3 (i32.const -1) ) (block - (set_local $7 + (set_local $6 (i32.load - (get_local $2) + (get_local $1) ) ) - (set_local $8 + (set_local $7 (i32.const 4) ) ) @@ -8602,15 +8596,15 @@ (block $do-once (if (i32.eq - (get_local $8) + (get_local $7) (i32.const 4) ) (block (if (i32.lt_u - (tee_local $2 + (tee_local $1 (i32.load - (tee_local $3 + (tee_local $2 (i32.add (get_local $0) (i32.const 20) @@ -8618,15 +8612,12 @@ ) ) ) - (get_local $7) + (get_local $6) ) (if (i32.ne - (tee_local $4 - (i32.and - (get_local $1) - (i32.const 255) - ) + (tee_local $3 + (i32.const 10) ) (i32.load8_s offset=75 (get_local $0) @@ -8634,26 +8625,26 @@ ) (block (i32.store - (get_local $3) + (get_local $2) (i32.add - (get_local $2) + (get_local $1) (i32.const 1) ) ) (i32.store8 - (get_local $2) - (get_local $9) + (get_local $1) + (i32.const 10) ) (br $do-once) ) ) ) - (set_local $4 + (set_local $3 (if (result i32) (i32.eq (call_indirect (type $FUNCSIG$iiii) (get_local $0) - (get_local $6) + (get_local $5) (i32.const 1) (i32.add (i32.and @@ -8668,7 +8659,7 @@ (i32.const 1) ) (i32.load8_u - (get_local $6) + (get_local $5) ) (i32.const -1) ) @@ -8677,9 +8668,9 @@ ) ) (set_global $r - (get_local $5) + (get_local $4) ) - (get_local $4) + (get_local $3) ) (func $$a (; 20 ;) (; has Stack IR ;) (param $0 i32) (result i32) (local $1 i32) @@ -9104,12 +9095,13 @@ (get_local $2) ) ) - (func $db (; 24 ;) (; has Stack IR ;) (param $0 i32) (result i32) + (func $db (; 24 ;) (; has Stack IR ;) (result i32) + (local $0 i32) (local $1 i32) (local $2 i32) (drop (i32.load offset=76 - (tee_local $1 + (tee_local $0 (i32.load (i32.const 1024) ) @@ -9118,18 +9110,17 @@ ) (i32.shr_s (i32.shl - (tee_local $0 + (tee_local $1 (block $do-once (result i32) (if (result i32) (i32.lt_s (i32.add (call $bb - (get_local $0) + (i32.const 1144) (call $Za - (get_local $0) + (i32.const 1144) ) - (i32.const 1) - (get_local $1) + (get_local $0) ) (i32.const -1) ) @@ -9140,36 +9131,36 @@ (if (i32.ne (i32.load8_s offset=75 - (get_local $1) + (get_local $0) ) (i32.const 10) ) (if (i32.lt_u - (tee_local $0 + (tee_local $1 (i32.load (tee_local $2 (i32.add - (get_local $1) + (get_local $0) (i32.const 20) ) ) ) ) (i32.load offset=16 - (get_local $1) + (get_local $0) ) ) (block (i32.store (get_local $2) (i32.add - (get_local $0) + (get_local $1) (i32.const 1) ) ) (i32.store8 - (get_local $0) + (get_local $1) (i32.const 10) ) (br $do-once @@ -9180,8 +9171,7 @@ ) (i32.lt_s (call $ab - (get_local $1) - (i32.const 10) + (get_local $0) ) (i32.const 0) ) @@ -9272,33 +9262,34 @@ ) ) ) - (func $bb (; 26 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) + (func $bb (; 26 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (local $3 i32) (local $4 i32) (set_local $4 - (i32.mul - (get_local $2) - (get_local $1) - ) + (i32.const 1) + ) + (set_local $3 + (get_local $1) ) (if (block (result i32) (drop (i32.load offset=76 - (get_local $3) + (get_local $2) ) ) (i32.ne (tee_local $0 (call $Wa (get_local $0) - (get_local $4) (get_local $3) + (get_local $2) ) ) - (get_local $4) + (get_local $3) ) ) - (set_local $2 + (set_local $4 (if (result i32) (get_local $1) (i32.div_u @@ -9309,7 +9300,7 @@ ) ) ) - (get_local $2) + (get_local $4) ) (func $Ua (; 27 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) @@ -9611,9 +9602,7 @@ ) (func $Na (; 41 ;) (; has Stack IR ;) (result i32) (drop - (call $db - (i32.const 1144) - ) + (call $db) ) (i32.const 0) ) diff --git a/test/memorygrowth.fromasm.imprecise b/test/memorygrowth.fromasm.imprecise index c71b3b697..4f52c23de 100644 --- a/test/memorygrowth.fromasm.imprecise +++ b/test/memorygrowth.fromasm.imprecise @@ -8429,7 +8429,7 @@ (func $_a (; 18 ;) (; has Stack IR ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) - (tee_local $1 + (tee_local $2 (block $do-once (result i32) (if (result i32) (get_local $0) @@ -8469,16 +8469,16 @@ (i32.const 1188) ) (if - (tee_local $2 + (tee_local $1 (i32.load (i32.const 1184) ) ) (block - (set_local $1 - (get_local $2) - ) (set_local $2 + (get_local $1) + ) + (set_local $1 (get_local $0) ) (loop $while-in @@ -8488,53 +8488,52 @@ (if (i32.gt_u (i32.load offset=20 - (get_local $1) + (get_local $2) ) (i32.load offset=28 - (get_local $1) + (get_local $2) ) ) - (set_local $2 + (set_local $1 (i32.or (call $$a - (get_local $1) + (get_local $2) ) - (get_local $2) + (get_local $1) ) ) ) (br_if $while-in - (tee_local $1 + (tee_local $2 (i32.load offset=56 - (get_local $1) + (get_local $2) ) ) ) ) ) - (set_local $2 + (set_local $1 (get_local $0) ) ) (call $xa (i32.const 1188) ) - (get_local $2) + (get_local $1) ) ) ) ) ) - (func $ab (; 19 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) + (func $ab (; 19 ;) (; has Stack IR ;) (param $0 i32) (result i32) + (local $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) (local $6 i32) (local $7 i32) - (local $8 i32) - (local $9 i32) - (set_local $5 + (set_local $4 (get_global $r) ) (set_global $r @@ -8544,20 +8543,15 @@ ) ) (i32.store8 - (tee_local $6 - (get_local $5) - ) - (tee_local $9 - (i32.and - (get_local $1) - (i32.const 255) - ) + (tee_local $5 + (get_local $4) ) + (i32.const 10) ) (if - (tee_local $3 + (tee_local $2 (i32.load - (tee_local $2 + (tee_local $1 (i32.add (get_local $0) (i32.const 16) @@ -8566,10 +8560,10 @@ ) ) (block - (set_local $7 - (get_local $3) + (set_local $6 + (get_local $2) ) - (set_local $8 + (set_local $7 (i32.const 4) ) ) @@ -8577,16 +8571,16 @@ (call $Xa (get_local $0) ) - (set_local $4 + (set_local $3 (i32.const -1) ) (block - (set_local $7 + (set_local $6 (i32.load - (get_local $2) + (get_local $1) ) ) - (set_local $8 + (set_local $7 (i32.const 4) ) ) @@ -8595,15 +8589,15 @@ (block $do-once (if (i32.eq - (get_local $8) + (get_local $7) (i32.const 4) ) (block (if (i32.lt_u - (tee_local $2 + (tee_local $1 (i32.load - (tee_local $3 + (tee_local $2 (i32.add (get_local $0) (i32.const 20) @@ -8611,15 +8605,12 @@ ) ) ) - (get_local $7) + (get_local $6) ) (if (i32.ne - (tee_local $4 - (i32.and - (get_local $1) - (i32.const 255) - ) + (tee_local $3 + (i32.const 10) ) (i32.load8_s offset=75 (get_local $0) @@ -8627,26 +8618,26 @@ ) (block (i32.store - (get_local $3) + (get_local $2) (i32.add - (get_local $2) + (get_local $1) (i32.const 1) ) ) (i32.store8 - (get_local $2) - (get_local $9) + (get_local $1) + (i32.const 10) ) (br $do-once) ) ) ) - (set_local $4 + (set_local $3 (if (result i32) (i32.eq (call_indirect (type $FUNCSIG$iiii) (get_local $0) - (get_local $6) + (get_local $5) (i32.const 1) (i32.add (i32.and @@ -8661,7 +8652,7 @@ (i32.const 1) ) (i32.load8_u - (get_local $6) + (get_local $5) ) (i32.const -1) ) @@ -8670,9 +8661,9 @@ ) ) (set_global $r - (get_local $5) + (get_local $4) ) - (get_local $4) + (get_local $3) ) (func $$a (; 20 ;) (; has Stack IR ;) (param $0 i32) (result i32) (local $1 i32) @@ -9097,12 +9088,13 @@ (get_local $2) ) ) - (func $db (; 24 ;) (; has Stack IR ;) (param $0 i32) (result i32) + (func $db (; 24 ;) (; has Stack IR ;) (result i32) + (local $0 i32) (local $1 i32) (local $2 i32) (drop (i32.load offset=76 - (tee_local $1 + (tee_local $0 (i32.load (i32.const 1024) ) @@ -9111,18 +9103,17 @@ ) (i32.shr_s (i32.shl - (tee_local $0 + (tee_local $1 (block $do-once (result i32) (if (result i32) (i32.lt_s (i32.add (call $bb - (get_local $0) + (i32.const 1144) (call $Za - (get_local $0) + (i32.const 1144) ) - (i32.const 1) - (get_local $1) + (get_local $0) ) (i32.const -1) ) @@ -9133,36 +9124,36 @@ (if (i32.ne (i32.load8_s offset=75 - (get_local $1) + (get_local $0) ) (i32.const 10) ) (if (i32.lt_u - (tee_local $0 + (tee_local $1 (i32.load (tee_local $2 (i32.add - (get_local $1) + (get_local $0) (i32.const 20) ) ) ) ) (i32.load offset=16 - (get_local $1) + (get_local $0) ) ) (block (i32.store (get_local $2) (i32.add - (get_local $0) + (get_local $1) (i32.const 1) ) ) (i32.store8 - (get_local $0) + (get_local $1) (i32.const 10) ) (br $do-once @@ -9173,8 +9164,7 @@ ) (i32.lt_s (call $ab - (get_local $1) - (i32.const 10) + (get_local $0) ) (i32.const 0) ) @@ -9265,33 +9255,34 @@ ) ) ) - (func $bb (; 26 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) + (func $bb (; 26 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (local $3 i32) (local $4 i32) (set_local $4 - (i32.mul - (get_local $2) - (get_local $1) - ) + (i32.const 1) + ) + (set_local $3 + (get_local $1) ) (if (i32.ne (tee_local $0 (call $Wa (get_local $0) - (get_local $4) (get_local $3) + (get_local $2) ) ) - (get_local $4) + (get_local $3) ) - (set_local $2 + (set_local $4 (i32.div_u (get_local $0) (get_local $1) ) ) ) - (get_local $2) + (get_local $4) ) (func $Ua (; 27 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) @@ -9589,9 +9580,7 @@ ) (func $Na (; 41 ;) (; has Stack IR ;) (result i32) (drop - (call $db - (i32.const 1144) - ) + (call $db) ) (i32.const 0) ) diff --git a/test/passes/converge_O3_metrics.bin.txt b/test/passes/converge_O3_metrics.bin.txt index a272a6288..637a9522f 100644 --- a/test/passes/converge_O3_metrics.bin.txt +++ b/test/passes/converge_O3_metrics.bin.txt @@ -1,30 +1,29 @@ total - [funcs] : 9 + [funcs] : 8 [memory-data] : 28 [table-data] : 429 - [total] : 136 + [total] : 132 [vars] : 4 binary : 12 - block : 9 + block : 8 break : 3 - call : 3 + call : 2 call_import : 1 call_indirect : 4 - const : 48 + const : 47 drop : 3 get_global : 1 - get_local : 20 + get_local : 18 if : 3 load : 16 loop : 1 set_global : 1 - set_local : 6 + set_local : 7 store : 5 (module (type $0 (func (param i32 i32) (result i32))) (type $1 (func (param i32 i32 i32) (result i32))) (type $2 (func (param i32) (result i32))) - (type $3 (func (param i32))) (type $6 (func (param i32 i32 i32 i32 i32 i32 i32) (result i32))) (type $7 (func (result i32))) (import "env" "memory" (memory $0 256 256)) @@ -48,30 +47,30 @@ total (func $_malloc (; 2 ;) (; has Stack IR ;) (type $2) (param $0 i32) (result i32) (i32.const 0) ) - (func $___stdio_write (; 3 ;) (; has Stack IR ;) (type $1) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $___stdio_write (; 3 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) (i32.store (i32.const 8) - (get_local $1) + (get_local $0) ) (i32.store (i32.const 12) - (get_local $2) + (get_local $1) ) (i32.store - (tee_local $1 + (tee_local $0 (get_global $global$0) ) (i32.const 1) ) (i32.store offset=8 - (get_local $1) + (get_local $0) (i32.const 2) ) (drop (if (result i32) (call $import$0 (i32.const 146) - (get_local $1) + (get_local $0) ) (i32.const -1) (i32.const 0) @@ -81,45 +80,6 @@ total ) (func $_main (; 4 ;) (; has Stack IR ;) (type $7) (result i32) (local $0 i32) - (call $__ZNSt3__224__put_character_sequenceIcNS_11char_traitsIcEEEERNS_13basic_ostreamIT_T0_EES7_PKS4_j - (block (result i32) - (set_local $0 - (i32.const 10888) - ) - (loop $label$3 - (br_if $label$3 - (i32.load8_s - (tee_local $0 - (i32.add - (get_local $0) - (i32.const 1) - ) - ) - ) - ) - ) - (i32.sub - (get_local $0) - (i32.const 10888) - ) - ) - ) - (call $__ZNSt3__213basic_ostreamIcNS_11char_traitsIcEEE3putEc - (i32.const 10) - ) - (i32.const 0) - ) - (func $___stdout_write (; 5 ;) (; has Stack IR ;) (type $1) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) - (set_global $global$0 - (i32.const 32) - ) - (call $___stdio_write - (i32.const 1) - (get_local $1) - (get_local $2) - ) - ) - (func $__ZNSt3__224__put_character_sequenceIcNS_11char_traitsIcEEEERNS_13basic_ostreamIT_T0_EES7_PKS4_j (; 6 ;) (; has Stack IR ;) (type $3) (param $0 i32) (local $1 i32) (set_local $1 (i32.load offset=24 @@ -138,7 +98,29 @@ total ) (block $label$2 (if - (get_local $0) + (block (result i32) + (set_local $0 + (i32.const 10888) + ) + (loop $label$3 + (br_if $label$3 + (i32.load8_s + (tee_local $0 + (i32.add + (get_local $0) + (i32.const 1) + ) + ) + ) + ) + ) + (tee_local $0 + (i32.sub + (get_local $0) + (i32.const 10888) + ) + ) + ) (br_if $label$2 (call_indirect (type $1) (get_local $1) @@ -156,17 +138,28 @@ total ) ) ) + (call $__ZNSt3__213basic_ostreamIcNS_11char_traitsIcEEE3putEc) + (i32.const 0) + ) + (func $___stdout_write (; 5 ;) (; has Stack IR ;) (type $1) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (set_global $global$0 + (i32.const 32) + ) + (call $___stdio_write + (get_local $1) + (get_local $2) + ) ) - (func $__ZNSt3__213basic_ostreamIcNS_11char_traitsIcEEE3putEc (; 7 ;) (; has Stack IR ;) (type $3) (param $0 i32) + (func $__ZNSt3__213basic_ostreamIcNS_11char_traitsIcEEE3putEc (; 6 ;) (; has Stack IR ;) + (local $0 i32) (local $1 i32) - (local $2 i32) (block $label$1 (br_if $label$1 (if (result i32) (i32.load (i32.add - (tee_local $2 - (tee_local $1 + (tee_local $1 + (tee_local $0 (i32.load (i32.add (i32.load @@ -187,12 +180,12 @@ total ) (i32.const 0) (call_indirect (type $0) - (get_local $2) - (get_local $0) + (get_local $1) + (i32.const 10) (i32.add (i32.load offset=52 (i32.load - (get_local $1) + (get_local $0) ) ) (i32.const 422) @@ -202,7 +195,7 @@ total ) ) ) - (func $__ZNSt3__211__stdoutbufIcE8overflowEi (; 8 ;) (; has Stack IR ;) (type $0) (param $0 i32) (param $1 i32) (result i32) + (func $__ZNSt3__211__stdoutbufIcE8overflowEi (; 7 ;) (; has Stack IR ;) (type $0) (param $0 i32) (param $1 i32) (result i32) (i32.store8 (i32.const 0) (get_local $1) @@ -227,7 +220,7 @@ total ) (i32.const 0) ) - (func $__ZNSt3__211__stdoutbufIcE6xsputnEPKci (; 9 ;) (; has Stack IR ;) (type $1) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $__ZNSt3__211__stdoutbufIcE6xsputnEPKci (; 8 ;) (; has Stack IR ;) (type $1) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (drop (call_indirect (type $1) (i32.const 0) @@ -247,34 +240,34 @@ total ) ) total - [funcs] : 9 + [funcs] : 8 [memory-data] : 28 [table-data] : 429 - [total] : 136 + [total] : 132 [vars] : 4 binary : 12 - block : 9 + block : 8 break : 3 - call : 3 + call : 2 call_import : 1 call_indirect : 4 - const : 48 + const : 47 drop : 3 get_global : 1 - get_local : 20 + get_local : 18 if : 3 load : 16 loop : 1 set_global : 1 - set_local : 6 + set_local : 7 store : 5 (module (type $0 (func (param i32 i32) (result i32))) (type $1 (func (param i32 i32 i32) (result i32))) (type $2 (func (param i32) (result i32))) - (type $3 (func (param i32))) (type $6 (func (param i32 i32 i32 i32 i32 i32 i32) (result i32))) (type $7 (func (result i32))) + (type $FUNCSIG$v (func)) (import "env" "memory" (memory $0 256 256)) (import "env" "table" (table 478 478 anyfunc)) (import "env" "___syscall146" (func $import$0 (param i32 i32) (result i32))) @@ -296,30 +289,30 @@ total (func $_malloc (; 2 ;) (; has Stack IR ;) (type $2) (param $0 i32) (result i32) (i32.const 0) ) - (func $___stdio_write (; 3 ;) (; has Stack IR ;) (type $1) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $___stdio_write (; 3 ;) (; has Stack IR ;) (type $0) (param $0 i32) (param $1 i32) (result i32) (i32.store (i32.const 8) - (get_local $1) + (get_local $0) ) (i32.store (i32.const 12) - (get_local $2) + (get_local $1) ) (i32.store - (tee_local $1 + (tee_local $0 (get_global $global$0) ) (i32.const 1) ) (i32.store offset=8 - (get_local $1) + (get_local $0) (i32.const 2) ) (drop (if (result i32) (call $import$0 (i32.const 146) - (get_local $1) + (get_local $0) ) (i32.const -1) (i32.const 0) @@ -329,32 +322,65 @@ total ) (func $_main (; 4 ;) (; has Stack IR ;) (type $7) (result i32) (local $0 i32) - (call $__ZNSt3__224__put_character_sequenceIcNS_11char_traitsIcEEEERNS_13basic_ostreamIT_T0_EES7_PKS4_j - (block (result i32) - (set_local $0 - (i32.const 10888) + (local $1 i32) + (set_local $1 + (i32.load offset=24 + (i32.add + (i32.load + (i32.add + (i32.load + (i32.const 18100) + ) + (i32.const -12) + ) + ) + (i32.const 18100) ) - (loop $label$3 - (br_if $label$3 - (i32.load8_s - (tee_local $0 - (i32.add - (get_local $0) - (i32.const 1) + ) + ) + (block $label$2 + (if + (block (result i32) + (set_local $0 + (i32.const 10888) + ) + (loop $label$3 + (br_if $label$3 + (i32.load8_s + (tee_local $0 + (i32.add + (get_local $0) + (i32.const 1) + ) ) ) ) ) + (tee_local $0 + (i32.sub + (get_local $0) + (i32.const 10888) + ) + ) ) - (i32.sub - (get_local $0) - (i32.const 10888) + (br_if $label$2 + (call_indirect (type $1) + (get_local $1) + (i32.const 10888) + (get_local $0) + (i32.add + (i32.load offset=48 + (i32.load + (get_local $1) + ) + ) + (i32.const 8) + ) + ) ) ) ) - (call $__ZNSt3__213basic_ostreamIcNS_11char_traitsIcEEE3putEc - (i32.const 10) - ) + (call $__ZNSt3__213basic_ostreamIcNS_11char_traitsIcEEE3putEc) (i32.const 0) ) (func $___stdout_write (; 5 ;) (; has Stack IR ;) (type $1) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) @@ -362,12 +388,182 @@ total (i32.const 32) ) (call $___stdio_write - (i32.const 1) (get_local $1) (get_local $2) ) ) - (func $__ZNSt3__224__put_character_sequenceIcNS_11char_traitsIcEEEERNS_13basic_ostreamIT_T0_EES7_PKS4_j (; 6 ;) (; has Stack IR ;) (type $3) (param $0 i32) + (func $__ZNSt3__213basic_ostreamIcNS_11char_traitsIcEEE3putEc (; 6 ;) (; has Stack IR ;) (type $FUNCSIG$v) + (local $0 i32) + (local $1 i32) + (block $label$1 + (br_if $label$1 + (if (result i32) + (i32.load + (i32.add + (tee_local $1 + (tee_local $0 + (i32.load + (i32.add + (i32.load + (i32.add + (i32.load + (i32.const 18100) + ) + (i32.const -12) + ) + ) + (i32.const 18124) + ) + ) + ) + ) + (i32.const 24) + ) + ) + (i32.const 0) + (call_indirect (type $0) + (get_local $1) + (i32.const 10) + (i32.add + (i32.load offset=52 + (i32.load + (get_local $0) + ) + ) + (i32.const 422) + ) + ) + ) + ) + ) + ) + (func $__ZNSt3__211__stdoutbufIcE8overflowEi (; 7 ;) (; has Stack IR ;) (type $0) (param $0 i32) (param $1 i32) (result i32) + (i32.store8 + (i32.const 0) + (get_local $1) + ) + (drop + (call_indirect (type $1) + (i32.const 0) + (i32.const 0) + (i32.const 1) + (i32.add + (i32.load offset=36 + (i32.load + (i32.add + (get_local $0) + (i32.const 32) + ) + ) + ) + (i32.const 8) + ) + ) + ) + (i32.const 0) + ) + (func $__ZNSt3__211__stdoutbufIcE6xsputnEPKci (; 8 ;) (; has Stack IR ;) (type $1) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (drop + (call_indirect (type $1) + (i32.const 0) + (get_local $1) + (get_local $2) + (i32.add + (i32.load offset=36 + (i32.load offset=32 + (get_local $0) + ) + ) + (i32.const 8) + ) + ) + ) + (i32.const 0) + ) +) +total + [funcs] : 8 + [memory-data] : 28 + [table-data] : 429 + [total] : 132 + [vars] : 4 + binary : 12 + block : 8 + break : 3 + call : 2 + call_import : 1 + call_indirect : 4 + const : 47 + drop : 3 + get_global : 1 + get_local : 18 + if : 3 + load : 16 + loop : 1 + set_global : 1 + set_local : 7 + store : 5 +(module + (type $0 (func (param i32 i32) (result i32))) + (type $1 (func (param i32 i32 i32) (result i32))) + (type $2 (func (param i32) (result i32))) + (type $6 (func (param i32 i32 i32 i32 i32 i32 i32) (result i32))) + (type $7 (func (result i32))) + (type $FUNCSIG$v (func)) + (import "env" "memory" (memory $0 256 256)) + (import "env" "table" (table 478 478 anyfunc)) + (import "env" "___syscall146" (func $import$0 (param i32 i32) (result i32))) + (global $global$0 (mut i32) (i32.const 1)) + (elem (i32.const 0) $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $___stdout_write $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $__ZNSt3__211__stdoutbufIcE6xsputnEPKci $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $b0 $__ZNSt3__211__stdoutbufIcE8overflowEi) + (data (i32.const 2948) "\03") + (data (i32.const 6828) "\04") + (data (i32.const 7028) "\0d\00\00\00\06") + (data (i32.const 10888) "hello, world!") + (data (i32.const 18100) "\b8\1a") + (data (i32.const 18128) ",I") + (data (i32.const 18732) "D\1b") + (data (i32.const 18764) "`\0b") + (export "_main" (func $_main)) + (export "_malloc" (func $_malloc)) + (func $b0 (; 1 ;) (; has Stack IR ;) (type $6) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (param $4 i32) (param $5 i32) (param $6 i32) (result i32) + (i32.const 0) + ) + (func $_malloc (; 2 ;) (; has Stack IR ;) (type $2) (param $0 i32) (result i32) + (i32.const 0) + ) + (func $___stdio_write (; 3 ;) (; has Stack IR ;) (type $0) (param $0 i32) (param $1 i32) (result i32) + (i32.store + (i32.const 8) + (get_local $0) + ) + (i32.store + (i32.const 12) + (get_local $1) + ) + (i32.store + (tee_local $0 + (get_global $global$0) + ) + (i32.const 1) + ) + (i32.store offset=8 + (get_local $0) + (i32.const 2) + ) + (drop + (if (result i32) + (call $import$0 + (i32.const 146) + (get_local $0) + ) + (i32.const -1) + (i32.const 0) + ) + ) + (i32.const 1) + ) + (func $_main (; 4 ;) (; has Stack IR ;) (type $7) (result i32) + (local $0 i32) (local $1 i32) (set_local $1 (i32.load offset=24 @@ -386,7 +582,29 @@ total ) (block $label$2 (if - (get_local $0) + (block (result i32) + (set_local $0 + (i32.const 10888) + ) + (loop $label$3 + (br_if $label$3 + (i32.load8_s + (tee_local $0 + (i32.add + (get_local $0) + (i32.const 1) + ) + ) + ) + ) + ) + (tee_local $0 + (i32.sub + (get_local $0) + (i32.const 10888) + ) + ) + ) (br_if $label$2 (call_indirect (type $1) (get_local $1) @@ -404,17 +622,28 @@ total ) ) ) + (call $__ZNSt3__213basic_ostreamIcNS_11char_traitsIcEEE3putEc) + (i32.const 0) ) - (func $__ZNSt3__213basic_ostreamIcNS_11char_traitsIcEEE3putEc (; 7 ;) (; has Stack IR ;) (type $3) (param $0 i32) + (func $___stdout_write (; 5 ;) (; has Stack IR ;) (type $1) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (set_global $global$0 + (i32.const 32) + ) + (call $___stdio_write + (get_local $1) + (get_local $2) + ) + ) + (func $__ZNSt3__213basic_ostreamIcNS_11char_traitsIcEEE3putEc (; 6 ;) (; has Stack IR ;) (type $FUNCSIG$v) + (local $0 i32) (local $1 i32) - (local $2 i32) (block $label$1 (br_if $label$1 (if (result i32) (i32.load (i32.add - (tee_local $2 - (tee_local $1 + (tee_local $1 + (tee_local $0 (i32.load (i32.add (i32.load @@ -435,12 +664,12 @@ total ) (i32.const 0) (call_indirect (type $0) - (get_local $2) - (get_local $0) + (get_local $1) + (i32.const 10) (i32.add (i32.load offset=52 (i32.load - (get_local $1) + (get_local $0) ) ) (i32.const 422) @@ -450,7 +679,7 @@ total ) ) ) - (func $__ZNSt3__211__stdoutbufIcE8overflowEi (; 8 ;) (; has Stack IR ;) (type $0) (param $0 i32) (param $1 i32) (result i32) + (func $__ZNSt3__211__stdoutbufIcE8overflowEi (; 7 ;) (; has Stack IR ;) (type $0) (param $0 i32) (param $1 i32) (result i32) (i32.store8 (i32.const 0) (get_local $1) @@ -475,7 +704,7 @@ total ) (i32.const 0) ) - (func $__ZNSt3__211__stdoutbufIcE6xsputnEPKci (; 9 ;) (; has Stack IR ;) (type $1) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $__ZNSt3__211__stdoutbufIcE6xsputnEPKci (; 8 ;) (; has Stack IR ;) (type $1) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (drop (call_indirect (type $1) (i32.const 0) diff --git a/test/passes/dae.txt b/test/passes/dae.txt new file mode 100644 index 000000000..e62f03f5b --- /dev/null +++ b/test/passes/dae.txt @@ -0,0 +1,174 @@ +(module + (type $0 (func (param i32))) + (type $1 (func)) + (type $2 (func (param i32 f64))) + (table 1 1 anyfunc) + (elem (i32.const 0) $a9) + (export "a8" (func $a8)) + (func $a (; 0 ;) + (local $0 i32) + (set_local $0 + (i32.const 1) + ) + (nop) + ) + (func $b (; 1 ;) (type $1) + (call $a) + ) + (func $a1 (; 2 ;) + (local $0 i32) + (set_local $0 + (i32.const 2) + ) + (unreachable) + ) + (func $b1 (; 3 ;) (type $1) + (call $a1) + ) + (func $b11 (; 4 ;) (type $1) + (call $a1) + ) + (func $a2 (; 5 ;) (type $0) (param $x i32) + (drop + (get_local $x) + ) + ) + (func $b2 (; 6 ;) (type $1) + (call $a2 + (i32.const 3) + ) + ) + (func $b22 (; 7 ;) (type $1) + (call $a2 + (i32.const 4) + ) + ) + (func $a3 (; 8 ;) + (local $0 i32) + (drop + (i32.const -1) + ) + ) + (func $b3 (; 9 ;) (type $1) + (call $a3) + ) + (func $b33 (; 10 ;) (type $1) + (call $a3) + ) + (func $a4 (; 11 ;) (type $0) (param $x i32) + (nop) + ) + (func $b4 (; 12 ;) (type $1) + (call $a4 + (unreachable) + ) + ) + (func $b43 (; 13 ;) (type $1) + (call $a4 + (i32.const 4) + ) + ) + (func $a5 (; 14 ;) + (local $0 f64) + (local $1 i32) + (set_local $0 + (f64.const 3.14159) + ) + (block + (set_local $1 + (i32.const 1) + ) + (block + (drop + (get_local $1) + ) + (drop + (get_local $0) + ) + ) + ) + ) + (func $b5 (; 15 ;) (type $1) + (call $a5) + ) + (func $a6 (; 16 ;) (param $0 i32) + (local $1 f64) + (set_local $1 + (f64.const 3.14159) + ) + (block + (drop + (get_local $0) + ) + (drop + (get_local $1) + ) + ) + ) + (func $b6 (; 17 ;) (type $1) + (call $a6 + (unreachable) + ) + ) + (func $a7 (; 18 ;) (param $0 f64) + (local $1 i32) + (set_local $1 + (i32.const 1) + ) + (block + (drop + (get_local $1) + ) + (drop + (get_local $0) + ) + ) + ) + (func $b7 (; 19 ;) (type $1) + (call $a7 + (unreachable) + ) + ) + (func $a8 (; 20 ;) (type $0) (param $x i32) + (nop) + ) + (func $b8 (; 21 ;) (type $1) + (call $a8 + (i32.const 1) + ) + ) + (func $a9 (; 22 ;) (type $0) (param $x i32) + (nop) + ) + (func $b9 (; 23 ;) (type $1) + (call $a9 + (i32.const 1) + ) + ) + (func $a10 (; 24 ;) + (local $0 i32) + (set_local $0 + (i32.const 1) + ) + (block + (call $a10) + (call $a10) + ) + ) + (func $a11 (; 25 ;) + (local $0 i32) + (call $a11) + (call $a11) + ) + (func $a12 (; 26 ;) (type $0) (param $x i32) + (drop + (get_local $x) + ) + (call $a12 + (i32.const 1) + ) + (call $a12 + (i32.const 2) + ) + ) +) diff --git a/test/passes/dae.wast b/test/passes/dae.wast new file mode 100644 index 000000000..3400341a1 --- /dev/null +++ b/test/passes/dae.wast @@ -0,0 +1,87 @@ +(module + (export "a8" (func $a8)) + (table 1 1 anyfunc) + (elem (i32.const 0) $a9) + (func $a (param $x i32)) + (func $b + (call $a (i32.const 1)) ;; best case scenario + ) + (func $a1 (param $x i32) + (unreachable) + ) + (func $b1 + (call $a1 (i32.const 2)) ;; same value in both, so works + ) + (func $b11 + (call $a1 (i32.const 2)) + ) + (func $a2 (param $x i32) + (drop (get_local $x)) + ) + (func $b2 + (call $a2 (i32.const 3)) ;; different value! + ) + (func $b22 + (call $a2 (i32.const 4)) + ) + (func $a3 (param $x i32) + (drop (i32.const -1)) ;; diff value, but at least unused, so no need to send + ) + (func $b3 + (call $a3 (i32.const 3)) + ) + (func $b33 + (call $a3 (i32.const 4)) + ) + (func $a4 (param $x i32) ;; diff value, but with effects + ) + (func $b4 + (call $a4 (unreachable)) + ) + (func $b43 + (call $a4 (i32.const 4)) + ) + (func $a5 (param $x i32) (param $y f64) ;; optimize two + (drop (get_local $x)) + (drop (get_local $y)) + ) + (func $b5 + (call $a5 (i32.const 1) (f64.const 3.14159)) + ) + (func $a6 (param $x i32) (param $y f64) ;; optimize just one + (drop (get_local $x)) + (drop (get_local $y)) + ) + (func $b6 + (call $a6 (unreachable) (f64.const 3.14159)) + ) + (func $a7 (param $x i32) (param $y f64) ;; optimize just the other one + (drop (get_local $x)) + (drop (get_local $y)) + ) + (func $b7 + (call $a7 (i32.const 1) (unreachable)) + ) + (func $a8 (param $x i32)) ;; exported, do not optimize + (func $b8 + (call $a8 (i32.const 1)) + ) + (func $a9 (param $x i32)) ;; tabled, do not optimize + (func $b9 + (call $a9 (i32.const 1)) + ) + (func $a10 (param $x i32) ;; recursion + (call $a10 (i32.const 1)) + (call $a10 (i32.const 1)) + ) + (func $a11 (param $x i32) ;; partially successful recursion + (call $a11 (i32.const 1)) + (call $a11 (i32.const 2)) + ) + (func $a12 (param $x i32) ;; unsuccessful recursion + (drop (get_local $x)) + (call $a12 (i32.const 1)) + (call $a12 (i32.const 2)) + ) +) + diff --git a/test/wasm-only.asm.js b/test/wasm-only.asm.js index 0013a30c3..056f45801 100644 --- a/test/wasm-only.asm.js +++ b/test/wasm-only.asm.js @@ -163,7 +163,9 @@ function asm(global, env, buffer) { a = 0; x = i64(x); b = +0; + store4(50, a, 0); store8(100, x, 0); + stored(200, b, 0); illegalParam(0, i64(x), 12.34); // "coercion"/"cast" } function result() { // illegal result, but not exported diff --git a/test/wasm-only.fromasm b/test/wasm-only.fromasm index 0593e609a..f64f13f59 100644 --- a/test/wasm-only.fromasm +++ b/test/wasm-only.fromasm @@ -489,10 +489,18 @@ ) ) (func $illegalParam (; 15 ;) (; has Stack IR ;) (param $0 i32) (param $1 i64) (param $2 f64) + (i32.store + (i32.const 50) + (get_local $0) + ) (i64.store (i32.const 100) (get_local $1) ) + (f64.store + (i32.const 200) + (get_local $2) + ) (call $illegalParam (i32.const 0) (get_local $1) @@ -520,235 +528,18 @@ (get_local $1) ) ) - (func $switch64 (; 19 ;) (; has Stack IR ;) (param $0 i64) (result i32) - (block $switch (result i32) - (block $switch-default - (block $switch-case0 - (block $switch-case - (br_if $switch-default - (i32.wrap/i64 - (i64.shr_u - (tee_local $0 - (i64.sub - (get_local $0) - (i64.const 42949672965) - ) - ) - (i64.const 32) - ) - ) - ) - (br_table $switch-case0 $switch-default $switch-case $switch-default - (i32.wrap/i64 - (get_local $0) - ) - ) - ) - (br $switch - (i32.const 11000) - ) - ) - (br $switch - (i32.const 10) - ) - ) - (i32.const 1) - ) - ) - (func $unreachable_leftovers (; 20 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) - (block $__rjto$0 - (if - (i32.eqz - (get_local $1) - ) - (block - (br_if $__rjto$0 - (get_local $2) - ) - (i32.store - (get_local $0) - (i32.const -2) - ) - (return) - ) - ) - (i32.store - (get_local $0) - (i32.const -1) - ) + (func $unreachable_leftovers (; 19 ;) (; has Stack IR ;) + (i32.store + (i32.const 0) + (i32.const -2) ) ) - (func $switch64TOOMUCH (; 21 ;) (; has Stack IR ;) (param $0 i64) (result i32) + (func $_memchr (; 20 ;) (; has Stack IR ;) (result i32) + (local $0 i32) (local $1 i32) - (local $2 i64) - (block $switch-default - (if - (i64.ne - (tee_local $2 - (get_local $0) - ) - (i64.const -9223372036854775808) - ) - (br_if $switch-default - (i64.ne - (get_local $2) - (i64.const 4611686018427387904) - ) - ) - ) - (return - (i32.const 40) - ) - ) - (block $switch-default4 - (if - (i32.ne - (tee_local $1 - (i32.const 100) - ) - (i32.const 214748364) - ) - (br_if $switch-default4 - (i32.ne - (get_local $1) - (i32.const 107374182) - ) - ) - ) - (return - (i32.const 41) - ) - ) - (block $switch5 - (if - (i64.ne - (get_local $0) - (i64.const -9223372036854775808) - ) - (br_if $switch5 - (i64.ne - (get_local $0) - (i64.const 4611686018427387904) - ) - ) - ) - (return - (i32.const 42) - ) - ) - (block $switch8 - (if - (i32.ne - (i32.const 100) - (i32.const 214748364) - ) - (br_if $switch8 - (i32.ne - (get_local $1) - (i32.const 107374182) - ) - ) - ) - (return - (i32.const 43) - ) - ) - (i32.const 44) - ) - (func $_memchr (; 22 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) - (local $3 i32) - (local $4 i32) - (local $5 i32) - (set_local $5 - (i32.and - (get_local $1) - (i32.const 255) - ) - ) + (local $2 i32) (block $label$break$L8 (block $__rjti$2 - (if - (i32.and - (tee_local $4 - (i32.ne - (get_local $2) - (i32.const 0) - ) - ) - (i32.ne - (i32.and - (get_local $0) - (i32.const 3) - ) - (i32.const 0) - ) - ) - (block - (set_local $4 - (i32.and - (get_local $1) - (i32.const 255) - ) - ) - (set_local $3 - (get_local $2) - ) - (set_local $2 - (get_local $0) - ) - (loop $while-in - (br_if $__rjti$2 - (i32.eq - (i32.load8_u - (get_local $2) - ) - (i32.and - (get_local $4) - (i32.const 255) - ) - ) - ) - (br_if $while-in - (i32.and - (tee_local $0 - (i32.ne - (tee_local $3 - (i32.add - (get_local $3) - (i32.const -1) - ) - ) - (i32.const 0) - ) - ) - (i32.ne - (i32.and - (tee_local $2 - (i32.add - (get_local $2) - (i32.const 1) - ) - ) - (i32.const 3) - ) - (i32.const 0) - ) - ) - ) - ) - ) - (block - (set_local $3 - (get_local $2) - ) - (set_local $2 - (get_local $0) - ) - (set_local $0 - (get_local $4) - ) - ) - ) (br_if $__rjti$2 (get_local $0) ) @@ -758,27 +549,13 @@ (br $label$break$L8) ) (set_local $0 - (get_local $3) + (get_local $2) ) (if - (i32.ne - (i32.load8_u - (get_local $2) - ) - (tee_local $1 - (i32.and - (get_local $1) - (i32.const 255) - ) - ) + (i32.load8_u + (get_local $1) ) (block - (set_local $3 - (i32.mul - (get_local $5) - (i32.const 16843009) - ) - ) (block $__rjto$0 (block $__rjti$0 (br_if $__rjti$0 @@ -793,12 +570,9 @@ (i32.and (i32.xor (i32.and - (tee_local $4 - (i32.xor - (i32.load - (get_local $2) - ) - (get_local $3) + (tee_local $2 + (i32.load + (get_local $1) ) ) (i32.const -2139062144) @@ -806,15 +580,15 @@ (i32.const -2139062144) ) (i32.add - (get_local $4) + (get_local $2) (i32.const -16843009) ) ) ) (block - (set_local $2 + (set_local $1 (i32.add - (get_local $2) + (get_local $1) (i32.const 4) ) ) @@ -849,19 +623,15 @@ ) (loop $while-in5 (br_if $label$break$L8 - (i32.eq + (i32.eqz (i32.load8_u - (get_local $2) - ) - (i32.and (get_local $1) - (i32.const 255) ) ) ) - (set_local $2 + (set_local $1 (i32.add - (get_local $2) + (get_local $1) (i32.const 1) ) ) @@ -881,12 +651,12 @@ ) ) (select - (get_local $2) + (get_local $1) (i32.const 0) (get_local $0) ) ) - (func $keepAlive (; 23 ;) (; has Stack IR ;) + (func $keepAlive (; 21 ;) (; has Stack IR ;) (call $loads) (call $loads) (call $stores) @@ -947,40 +717,13 @@ (i32.const 0) ) ) + (call $unreachable_leftovers) + (call $unreachable_leftovers) (drop - (call $switch64 - (i64.const 0) - ) - ) - (drop - (call $switch64 - (i64.const 0) - ) - ) - (call $unreachable_leftovers - (i32.const 0) - (i32.const 0) - (i32.const 0) - ) - (call $unreachable_leftovers - (i32.const 0) - (i32.const 0) - (i32.const 0) - ) - (drop - (call $_memchr - (i32.const 0) - (i32.const 0) - (i32.const 0) - ) - ) - (drop - (call $switch64TOOMUCH - (i64.const 0) - ) + (call $_memchr) ) ) - (func $legalstub$illegalParam (; 24 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 f64) + (func $legalstub$illegalParam (; 22 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 f64) (call $illegalParam (get_local $0) (i64.or @@ -997,13 +740,13 @@ (get_local $3) ) ) - (func $legalstub$illegalResult (; 25 ;) (; has Stack IR ;) (result i32) + (func $legalstub$illegalResult (; 23 ;) (; has Stack IR ;) (result i32) (set_global $tempRet0 (i32.const 2) ) (i32.const 1) ) - (func $legalfunc$illegalImport (; 26 ;) (; has Stack IR ;) (param $0 f64) (param $1 i64) (param $2 i32) + (func $legalfunc$illegalImport (; 24 ;) (; has Stack IR ;) (param $0 f64) (param $1 i64) (param $2 i32) (call $legalimport$illegalImport (get_local $0) (i32.wrap/i64 @@ -1018,7 +761,7 @@ (get_local $2) ) ) - (func $legalfunc$_fabsf (; 27 ;) (; has Stack IR ;) (param $0 f32) (result f32) + (func $legalfunc$_fabsf (; 25 ;) (; has Stack IR ;) (param $0 f32) (result f32) (f32.demote/f64 (call $legalimport$_fabsf (f64.promote/f32 @@ -1027,7 +770,7 @@ ) ) ) - (func $legalfunc$do_i64 (; 28 ;) (; has Stack IR ;) (result i64) + (func $legalfunc$do_i64 (; 26 ;) (; has Stack IR ;) (result i64) (i64.or (i64.extend_u/i32 (call $legalimport$do_i64) @@ -1040,10 +783,10 @@ ) ) ) - (func $getTempRet0 (; 29 ;) (; has Stack IR ;) (result i32) + (func $getTempRet0 (; 27 ;) (; has Stack IR ;) (result i32) (get_global $tempRet0) ) - (func $setTempRet0 (; 30 ;) (; has Stack IR ;) (param $0 i32) + (func $setTempRet0 (; 28 ;) (; has Stack IR ;) (param $0 i32) (set_global $tempRet0 (get_local $0) ) diff --git a/test/wasm-only.fromasm.clamp b/test/wasm-only.fromasm.clamp index 0593e609a..f64f13f59 100644 --- a/test/wasm-only.fromasm.clamp +++ b/test/wasm-only.fromasm.clamp @@ -489,10 +489,18 @@ ) ) (func $illegalParam (; 15 ;) (; has Stack IR ;) (param $0 i32) (param $1 i64) (param $2 f64) + (i32.store + (i32.const 50) + (get_local $0) + ) (i64.store (i32.const 100) (get_local $1) ) + (f64.store + (i32.const 200) + (get_local $2) + ) (call $illegalParam (i32.const 0) (get_local $1) @@ -520,235 +528,18 @@ (get_local $1) ) ) - (func $switch64 (; 19 ;) (; has Stack IR ;) (param $0 i64) (result i32) - (block $switch (result i32) - (block $switch-default - (block $switch-case0 - (block $switch-case - (br_if $switch-default - (i32.wrap/i64 - (i64.shr_u - (tee_local $0 - (i64.sub - (get_local $0) - (i64.const 42949672965) - ) - ) - (i64.const 32) - ) - ) - ) - (br_table $switch-case0 $switch-default $switch-case $switch-default - (i32.wrap/i64 - (get_local $0) - ) - ) - ) - (br $switch - (i32.const 11000) - ) - ) - (br $switch - (i32.const 10) - ) - ) - (i32.const 1) - ) - ) - (func $unreachable_leftovers (; 20 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) - (block $__rjto$0 - (if - (i32.eqz - (get_local $1) - ) - (block - (br_if $__rjto$0 - (get_local $2) - ) - (i32.store - (get_local $0) - (i32.const -2) - ) - (return) - ) - ) - (i32.store - (get_local $0) - (i32.const -1) - ) + (func $unreachable_leftovers (; 19 ;) (; has Stack IR ;) + (i32.store + (i32.const 0) + (i32.const -2) ) ) - (func $switch64TOOMUCH (; 21 ;) (; has Stack IR ;) (param $0 i64) (result i32) + (func $_memchr (; 20 ;) (; has Stack IR ;) (result i32) + (local $0 i32) (local $1 i32) - (local $2 i64) - (block $switch-default - (if - (i64.ne - (tee_local $2 - (get_local $0) - ) - (i64.const -9223372036854775808) - ) - (br_if $switch-default - (i64.ne - (get_local $2) - (i64.const 4611686018427387904) - ) - ) - ) - (return - (i32.const 40) - ) - ) - (block $switch-default4 - (if - (i32.ne - (tee_local $1 - (i32.const 100) - ) - (i32.const 214748364) - ) - (br_if $switch-default4 - (i32.ne - (get_local $1) - (i32.const 107374182) - ) - ) - ) - (return - (i32.const 41) - ) - ) - (block $switch5 - (if - (i64.ne - (get_local $0) - (i64.const -9223372036854775808) - ) - (br_if $switch5 - (i64.ne - (get_local $0) - (i64.const 4611686018427387904) - ) - ) - ) - (return - (i32.const 42) - ) - ) - (block $switch8 - (if - (i32.ne - (i32.const 100) - (i32.const 214748364) - ) - (br_if $switch8 - (i32.ne - (get_local $1) - (i32.const 107374182) - ) - ) - ) - (return - (i32.const 43) - ) - ) - (i32.const 44) - ) - (func $_memchr (; 22 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) - (local $3 i32) - (local $4 i32) - (local $5 i32) - (set_local $5 - (i32.and - (get_local $1) - (i32.const 255) - ) - ) + (local $2 i32) (block $label$break$L8 (block $__rjti$2 - (if - (i32.and - (tee_local $4 - (i32.ne - (get_local $2) - (i32.const 0) - ) - ) - (i32.ne - (i32.and - (get_local $0) - (i32.const 3) - ) - (i32.const 0) - ) - ) - (block - (set_local $4 - (i32.and - (get_local $1) - (i32.const 255) - ) - ) - (set_local $3 - (get_local $2) - ) - (set_local $2 - (get_local $0) - ) - (loop $while-in - (br_if $__rjti$2 - (i32.eq - (i32.load8_u - (get_local $2) - ) - (i32.and - (get_local $4) - (i32.const 255) - ) - ) - ) - (br_if $while-in - (i32.and - (tee_local $0 - (i32.ne - (tee_local $3 - (i32.add - (get_local $3) - (i32.const -1) - ) - ) - (i32.const 0) - ) - ) - (i32.ne - (i32.and - (tee_local $2 - (i32.add - (get_local $2) - (i32.const 1) - ) - ) - (i32.const 3) - ) - (i32.const 0) - ) - ) - ) - ) - ) - (block - (set_local $3 - (get_local $2) - ) - (set_local $2 - (get_local $0) - ) - (set_local $0 - (get_local $4) - ) - ) - ) (br_if $__rjti$2 (get_local $0) ) @@ -758,27 +549,13 @@ (br $label$break$L8) ) (set_local $0 - (get_local $3) + (get_local $2) ) (if - (i32.ne - (i32.load8_u - (get_local $2) - ) - (tee_local $1 - (i32.and - (get_local $1) - (i32.const 255) - ) - ) + (i32.load8_u + (get_local $1) ) (block - (set_local $3 - (i32.mul - (get_local $5) - (i32.const 16843009) - ) - ) (block $__rjto$0 (block $__rjti$0 (br_if $__rjti$0 @@ -793,12 +570,9 @@ (i32.and (i32.xor (i32.and - (tee_local $4 - (i32.xor - (i32.load - (get_local $2) - ) - (get_local $3) + (tee_local $2 + (i32.load + (get_local $1) ) ) (i32.const -2139062144) @@ -806,15 +580,15 @@ (i32.const -2139062144) ) (i32.add - (get_local $4) + (get_local $2) (i32.const -16843009) ) ) ) (block - (set_local $2 + (set_local $1 (i32.add - (get_local $2) + (get_local $1) (i32.const 4) ) ) @@ -849,19 +623,15 @@ ) (loop $while-in5 (br_if $label$break$L8 - (i32.eq + (i32.eqz (i32.load8_u - (get_local $2) - ) - (i32.and (get_local $1) - (i32.const 255) ) ) ) - (set_local $2 + (set_local $1 (i32.add - (get_local $2) + (get_local $1) (i32.const 1) ) ) @@ -881,12 +651,12 @@ ) ) (select - (get_local $2) + (get_local $1) (i32.const 0) (get_local $0) ) ) - (func $keepAlive (; 23 ;) (; has Stack IR ;) + (func $keepAlive (; 21 ;) (; has Stack IR ;) (call $loads) (call $loads) (call $stores) @@ -947,40 +717,13 @@ (i32.const 0) ) ) + (call $unreachable_leftovers) + (call $unreachable_leftovers) (drop - (call $switch64 - (i64.const 0) - ) - ) - (drop - (call $switch64 - (i64.const 0) - ) - ) - (call $unreachable_leftovers - (i32.const 0) - (i32.const 0) - (i32.const 0) - ) - (call $unreachable_leftovers - (i32.const 0) - (i32.const 0) - (i32.const 0) - ) - (drop - (call $_memchr - (i32.const 0) - (i32.const 0) - (i32.const 0) - ) - ) - (drop - (call $switch64TOOMUCH - (i64.const 0) - ) + (call $_memchr) ) ) - (func $legalstub$illegalParam (; 24 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 f64) + (func $legalstub$illegalParam (; 22 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 f64) (call $illegalParam (get_local $0) (i64.or @@ -997,13 +740,13 @@ (get_local $3) ) ) - (func $legalstub$illegalResult (; 25 ;) (; has Stack IR ;) (result i32) + (func $legalstub$illegalResult (; 23 ;) (; has Stack IR ;) (result i32) (set_global $tempRet0 (i32.const 2) ) (i32.const 1) ) - (func $legalfunc$illegalImport (; 26 ;) (; has Stack IR ;) (param $0 f64) (param $1 i64) (param $2 i32) + (func $legalfunc$illegalImport (; 24 ;) (; has Stack IR ;) (param $0 f64) (param $1 i64) (param $2 i32) (call $legalimport$illegalImport (get_local $0) (i32.wrap/i64 @@ -1018,7 +761,7 @@ (get_local $2) ) ) - (func $legalfunc$_fabsf (; 27 ;) (; has Stack IR ;) (param $0 f32) (result f32) + (func $legalfunc$_fabsf (; 25 ;) (; has Stack IR ;) (param $0 f32) (result f32) (f32.demote/f64 (call $legalimport$_fabsf (f64.promote/f32 @@ -1027,7 +770,7 @@ ) ) ) - (func $legalfunc$do_i64 (; 28 ;) (; has Stack IR ;) (result i64) + (func $legalfunc$do_i64 (; 26 ;) (; has Stack IR ;) (result i64) (i64.or (i64.extend_u/i32 (call $legalimport$do_i64) @@ -1040,10 +783,10 @@ ) ) ) - (func $getTempRet0 (; 29 ;) (; has Stack IR ;) (result i32) + (func $getTempRet0 (; 27 ;) (; has Stack IR ;) (result i32) (get_global $tempRet0) ) - (func $setTempRet0 (; 30 ;) (; has Stack IR ;) (param $0 i32) + (func $setTempRet0 (; 28 ;) (; has Stack IR ;) (param $0 i32) (set_global $tempRet0 (get_local $0) ) diff --git a/test/wasm-only.fromasm.clamp.no-opts b/test/wasm-only.fromasm.clamp.no-opts index 3c717b31d..786bef708 100644 --- a/test/wasm-only.fromasm.clamp.no-opts +++ b/test/wasm-only.fromasm.clamp.no-opts @@ -737,10 +737,18 @@ ) ) (func $illegalParam (; 19 ;) (param $a i32) (param $x i64) (param $b f64) + (i32.store + (i32.const 50) + (get_local $a) + ) (i64.store (i32.const 100) (get_local $x) ) + (f64.store + (i32.const 200) + (get_local $b) + ) (call $illegalParam (i32.const 0) (get_local $x) diff --git a/test/wasm-only.fromasm.imprecise b/test/wasm-only.fromasm.imprecise index 6077f9429..e9522a7c3 100644 --- a/test/wasm-only.fromasm.imprecise +++ b/test/wasm-only.fromasm.imprecise @@ -189,10 +189,18 @@ ) ) (func $illegalParam (; 9 ;) (; has Stack IR ;) (param $0 i32) (param $1 i64) (param $2 f64) + (i32.store + (i32.const 50) + (get_local $0) + ) (i64.store (i32.const 100) (get_local $1) ) + (f64.store + (i32.const 200) + (get_local $2) + ) (call $illegalParam (i32.const 0) (get_local $1) @@ -220,235 +228,18 @@ (get_local $1) ) ) - (func $switch64 (; 13 ;) (; has Stack IR ;) (param $0 i64) (result i32) - (block $switch (result i32) - (block $switch-default - (block $switch-case0 - (block $switch-case - (br_if $switch-default - (i32.wrap/i64 - (i64.shr_u - (tee_local $0 - (i64.sub - (get_local $0) - (i64.const 42949672965) - ) - ) - (i64.const 32) - ) - ) - ) - (br_table $switch-case0 $switch-default $switch-case $switch-default - (i32.wrap/i64 - (get_local $0) - ) - ) - ) - (br $switch - (i32.const 11000) - ) - ) - (br $switch - (i32.const 10) - ) - ) - (i32.const 1) - ) - ) - (func $unreachable_leftovers (; 14 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) - (block $__rjto$0 - (if - (i32.eqz - (get_local $1) - ) - (block - (br_if $__rjto$0 - (get_local $2) - ) - (i32.store - (get_local $0) - (i32.const -2) - ) - (return) - ) - ) - (i32.store - (get_local $0) - (i32.const -1) - ) + (func $unreachable_leftovers (; 13 ;) (; has Stack IR ;) + (i32.store + (i32.const 0) + (i32.const -2) ) ) - (func $switch64TOOMUCH (; 15 ;) (; has Stack IR ;) (param $0 i64) (result i32) + (func $_memchr (; 14 ;) (; has Stack IR ;) (result i32) + (local $0 i32) (local $1 i32) - (local $2 i64) - (block $switch-default - (if - (i64.ne - (tee_local $2 - (get_local $0) - ) - (i64.const -9223372036854775808) - ) - (br_if $switch-default - (i64.ne - (get_local $2) - (i64.const 4611686018427387904) - ) - ) - ) - (return - (i32.const 40) - ) - ) - (block $switch-default4 - (if - (i32.ne - (tee_local $1 - (i32.const 100) - ) - (i32.const 214748364) - ) - (br_if $switch-default4 - (i32.ne - (get_local $1) - (i32.const 107374182) - ) - ) - ) - (return - (i32.const 41) - ) - ) - (block $switch5 - (if - (i64.ne - (get_local $0) - (i64.const -9223372036854775808) - ) - (br_if $switch5 - (i64.ne - (get_local $0) - (i64.const 4611686018427387904) - ) - ) - ) - (return - (i32.const 42) - ) - ) - (block $switch8 - (if - (i32.ne - (i32.const 100) - (i32.const 214748364) - ) - (br_if $switch8 - (i32.ne - (get_local $1) - (i32.const 107374182) - ) - ) - ) - (return - (i32.const 43) - ) - ) - (i32.const 44) - ) - (func $_memchr (; 16 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) - (local $3 i32) - (local $4 i32) - (local $5 i32) - (set_local $5 - (i32.and - (get_local $1) - (i32.const 255) - ) - ) + (local $2 i32) (block $label$break$L8 (block $__rjti$2 - (if - (i32.and - (tee_local $4 - (i32.ne - (get_local $2) - (i32.const 0) - ) - ) - (i32.ne - (i32.and - (get_local $0) - (i32.const 3) - ) - (i32.const 0) - ) - ) - (block - (set_local $4 - (i32.and - (get_local $1) - (i32.const 255) - ) - ) - (set_local $3 - (get_local $2) - ) - (set_local $2 - (get_local $0) - ) - (loop $while-in - (br_if $__rjti$2 - (i32.eq - (i32.load8_u - (get_local $2) - ) - (i32.and - (get_local $4) - (i32.const 255) - ) - ) - ) - (br_if $while-in - (i32.and - (tee_local $0 - (i32.ne - (tee_local $3 - (i32.add - (get_local $3) - (i32.const -1) - ) - ) - (i32.const 0) - ) - ) - (i32.ne - (i32.and - (tee_local $2 - (i32.add - (get_local $2) - (i32.const 1) - ) - ) - (i32.const 3) - ) - (i32.const 0) - ) - ) - ) - ) - ) - (block - (set_local $3 - (get_local $2) - ) - (set_local $2 - (get_local $0) - ) - (set_local $0 - (get_local $4) - ) - ) - ) (br_if $__rjti$2 (get_local $0) ) @@ -458,27 +249,13 @@ (br $label$break$L8) ) (set_local $0 - (get_local $3) + (get_local $2) ) (if - (i32.ne - (i32.load8_u - (get_local $2) - ) - (tee_local $1 - (i32.and - (get_local $1) - (i32.const 255) - ) - ) + (i32.load8_u + (get_local $1) ) (block - (set_local $3 - (i32.mul - (get_local $5) - (i32.const 16843009) - ) - ) (block $__rjto$0 (block $__rjti$0 (br_if $__rjti$0 @@ -493,12 +270,9 @@ (i32.and (i32.xor (i32.and - (tee_local $4 - (i32.xor - (i32.load - (get_local $2) - ) - (get_local $3) + (tee_local $2 + (i32.load + (get_local $1) ) ) (i32.const -2139062144) @@ -506,15 +280,15 @@ (i32.const -2139062144) ) (i32.add - (get_local $4) + (get_local $2) (i32.const -16843009) ) ) ) (block - (set_local $2 + (set_local $1 (i32.add - (get_local $2) + (get_local $1) (i32.const 4) ) ) @@ -549,19 +323,15 @@ ) (loop $while-in5 (br_if $label$break$L8 - (i32.eq + (i32.eqz (i32.load8_u - (get_local $2) - ) - (i32.and (get_local $1) - (i32.const 255) ) ) ) - (set_local $2 + (set_local $1 (i32.add - (get_local $2) + (get_local $1) (i32.const 1) ) ) @@ -581,12 +351,12 @@ ) ) (select - (get_local $2) + (get_local $1) (i32.const 0) (get_local $0) ) ) - (func $keepAlive (; 17 ;) (; has Stack IR ;) + (func $keepAlive (; 15 ;) (; has Stack IR ;) (call $stores) (call $stores) (call $test) @@ -645,40 +415,13 @@ (i32.const 0) ) ) + (call $unreachable_leftovers) + (call $unreachable_leftovers) (drop - (call $switch64 - (i64.const 0) - ) - ) - (drop - (call $switch64 - (i64.const 0) - ) - ) - (call $unreachable_leftovers - (i32.const 0) - (i32.const 0) - (i32.const 0) - ) - (call $unreachable_leftovers - (i32.const 0) - (i32.const 0) - (i32.const 0) - ) - (drop - (call $_memchr - (i32.const 0) - (i32.const 0) - (i32.const 0) - ) - ) - (drop - (call $switch64TOOMUCH - (i64.const 0) - ) + (call $_memchr) ) ) - (func $legalstub$illegalParam (; 18 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 f64) + (func $legalstub$illegalParam (; 16 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 f64) (call $illegalParam (get_local $0) (i64.or @@ -695,13 +438,13 @@ (get_local $3) ) ) - (func $legalstub$illegalResult (; 19 ;) (; has Stack IR ;) (result i32) + (func $legalstub$illegalResult (; 17 ;) (; has Stack IR ;) (result i32) (set_global $tempRet0 (i32.const 2) ) (i32.const 1) ) - (func $legalfunc$illegalImport (; 20 ;) (; has Stack IR ;) (param $0 f64) (param $1 i64) (param $2 i32) + (func $legalfunc$illegalImport (; 18 ;) (; has Stack IR ;) (param $0 f64) (param $1 i64) (param $2 i32) (call $legalimport$illegalImport (get_local $0) (i32.wrap/i64 @@ -716,7 +459,7 @@ (get_local $2) ) ) - (func $legalfunc$_fabsf (; 21 ;) (; has Stack IR ;) (param $0 f32) (result f32) + (func $legalfunc$_fabsf (; 19 ;) (; has Stack IR ;) (param $0 f32) (result f32) (f32.demote/f64 (call $legalimport$_fabsf (f64.promote/f32 @@ -725,7 +468,7 @@ ) ) ) - (func $legalfunc$do_i64 (; 22 ;) (; has Stack IR ;) (result i64) + (func $legalfunc$do_i64 (; 20 ;) (; has Stack IR ;) (result i64) (i64.or (i64.extend_u/i32 (call $legalimport$do_i64) @@ -738,10 +481,10 @@ ) ) ) - (func $getTempRet0 (; 23 ;) (; has Stack IR ;) (result i32) + (func $getTempRet0 (; 21 ;) (; has Stack IR ;) (result i32) (get_global $tempRet0) ) - (func $setTempRet0 (; 24 ;) (; has Stack IR ;) (param $0 i32) + (func $setTempRet0 (; 22 ;) (; has Stack IR ;) (param $0 i32) (set_global $tempRet0 (get_local $0) ) diff --git a/test/wasm-only.fromasm.imprecise.no-opts b/test/wasm-only.fromasm.imprecise.no-opts index 997f66614..484a69fa6 100644 --- a/test/wasm-only.fromasm.imprecise.no-opts +++ b/test/wasm-only.fromasm.imprecise.no-opts @@ -572,10 +572,18 @@ ) ) (func $illegalParam (; 11 ;) (param $a i32) (param $x i64) (param $b f64) + (i32.store + (i32.const 50) + (get_local $a) + ) (i64.store (i32.const 100) (get_local $x) ) + (f64.store + (i32.const 200) + (get_local $b) + ) (call $illegalParam (i32.const 0) (get_local $x) diff --git a/test/wasm-only.fromasm.no-opts b/test/wasm-only.fromasm.no-opts index 3c717b31d..786bef708 100644 --- a/test/wasm-only.fromasm.no-opts +++ b/test/wasm-only.fromasm.no-opts @@ -737,10 +737,18 @@ ) ) (func $illegalParam (; 19 ;) (param $a i32) (param $x i64) (param $b f64) + (i32.store + (i32.const 50) + (get_local $a) + ) (i64.store (i32.const 100) (get_local $x) ) + (f64.store + (i32.const 200) + (get_local $b) + ) (call $illegalParam (i32.const 0) (get_local $x) |