diff options
author | Alon Zakai <alonzakai@gmail.com> | 2018-06-08 17:51:22 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-08 17:51:22 -0700 |
commit | c7b78eadec731675ef3274126d0d19df5e4263c5 (patch) | |
tree | 2f373af3e8b8bad6adc3af9e52c3e5ca4a95ff37 /src/passes/pass.cpp | |
parent | e3d201158d9136d6ffb655f70904dae5f9079317 (diff) | |
download | binaryen-c7b78eadec731675ef3274126d0d19df5e4263c5.tar.gz binaryen-c7b78eadec731675ef3274126d0d19df5e4263c5.tar.bz2 binaryen-c7b78eadec731675ef3274126d0d19df5e4263c5.zip |
-O4: When -O3 isn't enough (#1596)
This defines a new -O4 optimization mode, as flatten + flat-only opts (currently local-cse) + -O3.
In practice, flattening is not needed for LLVM output, which is pretty flat already (no block or if values, etc., even if it does use tees and does nest expressions; and LLVM has already done gvn etc. anyhow). In general, though, wasm generated by a non-LLVM compiler may naturally be nested because wasm allows that. See for example #1593 where an AssemblyScript testcase requires flattening to be fully optimized. So -O4 can help there.
-O4 takes 3x longer to run than -O3 in my testing, basically because flat IR is much bigger. But when it's useful it may be worth it. It does handle that AssemblyScript testcase and others like it. There's not much big real-world code that isn't LLVM yet, but running the fuzzer - which happily creates nested stuff all the time - I see -O4 consistently shrink the size by around 20% over -O3.
Diffstat (limited to 'src/passes/pass.cpp')
-rw-r--r-- | src/passes/pass.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/passes/pass.cpp b/src/passes/pass.cpp index 2f917d779..c0354524d 100644 --- a/src/passes/pass.cpp +++ b/src/passes/pass.cpp @@ -132,6 +132,12 @@ void PassRunner::addDefaultOptimizationPasses() { } void PassRunner::addDefaultFunctionOptimizationPasses() { + // if we are willing to work very very hard, flatten the IR and do opts + // that depend on flat IR + if (options.optimizeLevel >= 4) { + add("flatten"); + add("local-cse"); + } if (!options.debugInfo) { // debug info must be preserved, do not dce it add("dce"); } |