diff options
author | Alon Zakai <alonzakai@gmail.com> | 2018-06-08 15:45:02 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-08 15:45:02 -0700 |
commit | e3d201158d9136d6ffb655f70904dae5f9079317 (patch) | |
tree | 93329d0026eab20e5344358a902a6e2cf8b49d62 /src/tools/wasm-reduce.cpp | |
parent | 7676221b837bbd20daf1889dbdabf3cb76721658 (diff) | |
download | binaryen-e3d201158d9136d6ffb655f70904dae5f9079317.tar.gz binaryen-e3d201158d9136d6ffb655f70904dae5f9079317.tar.bz2 binaryen-e3d201158d9136d6ffb655f70904dae5f9079317.zip |
Improve local-cse (#1594)
This makes it much more effective, by rewriting it to depend on flatten. In flattened IR, it is very simple to check if an expression is equivalent to one already available for use in a local, and use that one instead, basically we just track values in locals.
Helps with #1521
Diffstat (limited to 'src/tools/wasm-reduce.cpp')
-rw-r--r-- | src/tools/wasm-reduce.cpp | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/src/tools/wasm-reduce.cpp b/src/tools/wasm-reduce.cpp index 0dfb97907..6b19e6216 100644 --- a/src/tools/wasm-reduce.cpp +++ b/src/tools/wasm-reduce.cpp @@ -236,13 +236,15 @@ struct Reducer : public WalkerPass<PostWalker<Reducer, UnifiedExpressionVisitor< "-O1", "-O2", "-O3", + "--flatten -Os", + "--flatten -O3", + "--flatten --local-cse -Os", "--coalesce-locals --vacuum", "--dce", "--duplicate-function-elimination", "--inlining", "--inlining-optimizing", "--optimize-level=3 --inlining-optimizing", - "--local-cse --vacuum", "--memory-packing", "--remove-unused-names --merge-blocks --vacuum", "--optimize-instructions", @@ -263,24 +265,21 @@ struct Reducer : public WalkerPass<PostWalker<Reducer, UnifiedExpressionVisitor< //std::cerr << "| starting passes loop iteration\n"; more = false; // try both combining with a generic shrink (so minor pass overhead is compensated for), and without - for (auto shrinking : { false, true }) { - for (auto pass : passes) { - std::string currCommand = Path::getBinaryenBinaryTool("wasm-opt") + " "; - if (shrinking) currCommand += " --dce --vacuum "; - currCommand += working + " -o " + test + " " + pass; - if (debugInfo) currCommand += " -g "; - if (verbose) std::cerr << "| trying pass command: " << currCommand << "\n"; - if (!ProgramResult(currCommand).failed()) { - auto newSize = file_size(test); - if (newSize < oldSize) { - // the pass didn't fail, and the size looks smaller, so promising - // see if it is still has the property we are preserving - if (ProgramResult(command) == expected) { - std::cerr << "| command \"" << currCommand << "\" succeeded, reduced size to " << newSize << ", and preserved the property\n"; - copy_file(test, working); - more = true; - oldSize = newSize; - } + for (auto pass : passes) { + std::string currCommand = Path::getBinaryenBinaryTool("wasm-opt") + " "; + currCommand += working + " -o " + test + " " + pass; + if (debugInfo) currCommand += " -g "; + if (verbose) std::cerr << "| trying pass command: " << currCommand << "\n"; + if (!ProgramResult(currCommand).failed()) { + auto newSize = file_size(test); + if (newSize < oldSize) { + // the pass didn't fail, and the size looks smaller, so promising + // see if it is still has the property we are preserving + if (ProgramResult(command) == expected) { + std::cerr << "| command \"" << currCommand << "\" succeeded, reduced size to " << newSize << ", and preserved the property\n"; + copy_file(test, working); + more = true; + oldSize = newSize; } } } |