Skip to content

Commit 525f076

Browse files
authored
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.
1 parent fc48efe commit 525f076

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/passes/pass.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,13 @@ void PassRunner::addDefaultFunctionOptimizationPasses() {
669669
}
670670

671671
void PassRunner::addDefaultGlobalOptimizationPrePasses() {
672+
// Removing duplicate functions is fast and saves work later.
672673
addIfNoDWARFIssues("duplicate-function-elimination");
674+
// Do a global cleanup before anything heavy, as it is fairly fast and can
675+
// save a lot of work if there is a significant amount of dead code.
676+
if (options.optimizeLevel >= 2) {
677+
addIfNoDWARFIssues("remove-unused-module-elements");
678+
}
673679
addIfNoDWARFIssues("memory-packing");
674680
if (options.optimizeLevel >= 2) {
675681
addIfNoDWARFIssues("once-reduction");

0 commit comments

Comments
 (0)