From c7b78eadec731675ef3274126d0d19df5e4263c5 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 8 Jun 2018 17:51:22 -0700 Subject: -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. --- src/passes/pass.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/passes/pass.cpp') 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"); } -- cgit v1.2.3