summaryrefslogtreecommitdiff
path: root/src/passes/pass.cpp
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2024-05-29 09:48:34 -0700
committerGitHub <noreply@github.com>2024-05-29 09:48:34 -0700
commit525f0761496c6aafea80a2d2e8cb709515eb06c5 (patch)
tree0b6a82561377b86b68697b65c3021c29212e4ee3 /src/passes/pass.cpp
parentfc48efe380c0d3360db17a54f0cdd0267d8ee1cf (diff)
downloadbinaryen-525f0761496c6aafea80a2d2e8cb709515eb06c5.tar.gz
binaryen-525f0761496c6aafea80a2d2e8cb709515eb06c5.tar.bz2
binaryen-525f0761496c6aafea80a2d2e8cb709515eb06c5.zip
Run RemoveUnneededModuleElements early (#6620)
Doing it before anything else can help a lot if there is a significant amount of dead code that can be removed, as it saves work for all the later passes. We did run this pass if GC was enabled just a few passes later down, but even so it is worthwhile to run it an additional time, and it makes sense to do even without GC (though in typical optimized LLVM outputs there will be little dead code). If there is no dead code then this is wasted work, but this is a fairly fast pass, and I measure no significant slowdown due to this. E.g. on the 35 MB clang.wasm (which is already optimized, so little dead code) it takes around a second, while all of -O2 takes almost two minutes, so the difference is just 1%. On J2CL I measure a 15% speedup in -O3 --closed-world -tnh, and also the binary is 2.5% smaller, which means there is less work for later cycles of -O3.
Diffstat (limited to 'src/passes/pass.cpp')
-rw-r--r--src/passes/pass.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/passes/pass.cpp b/src/passes/pass.cpp
index 8f954e5e3..ad0cc448c 100644
--- a/src/passes/pass.cpp
+++ b/src/passes/pass.cpp
@@ -669,7 +669,13 @@ void PassRunner::addDefaultFunctionOptimizationPasses() {
}
void PassRunner::addDefaultGlobalOptimizationPrePasses() {
+ // Removing duplicate functions is fast and saves work later.
addIfNoDWARFIssues("duplicate-function-elimination");
+ // Do a global cleanup before anything heavy, as it is fairly fast and can
+ // save a lot of work if there is a significant amount of dead code.
+ if (options.optimizeLevel >= 2) {
+ addIfNoDWARFIssues("remove-unused-module-elements");
+ }
addIfNoDWARFIssues("memory-packing");
if (options.optimizeLevel >= 2) {
addIfNoDWARFIssues("once-reduction");