From 06d5168d02287e51043d581644fcd25c9853a1f7 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 17 May 2022 12:40:21 -0700 Subject: wasm-reduce: Fix order in shrinkByReduction call (#4673) The old code would short-circuit and not do anything after we managed any reduction in the loop here. That would end up doing entire iterations of the whole pipeline before removing another element segment, which could be slow. --- src/tools/wasm-reduce.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/tools/wasm-reduce.cpp b/src/tools/wasm-reduce.cpp index c6f9be0de..b9f8c6dbe 100644 --- a/src/tools/wasm-reduce.cpp +++ b/src/tools/wasm-reduce.cpp @@ -831,7 +831,10 @@ struct Reducer // First, shrink segment elements. bool shrank = false; for (auto& segment : module->elementSegments) { - shrank = shrank || shrinkByReduction(segment.get(), 1); + // Try to shrink all the segments (code in shrinkByReduction will decide + // which to actually try to shrink, based on the current factor), and note + // if we shrank anything at all (which we'll use later down). + shrank = shrinkByReduction(segment.get(), 1) || shrank; } // Second, try to replace elements with a "zero". -- cgit v1.2.3