From 9627c8360d179c2cae168f8bca3bf1b7216c34a8 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 8 Nov 2023 07:54:03 -0800 Subject: LocalCSE: Do not optimize small things like global.get (#6087) LocalCSE is nice for large expressions, but for small things it has always been of unclear benefit since VMs also do GVN/CSE anyhow. So we are likely not speeding anything up, but hopefully we are reducing code size at least. Doing LocalCSE on something small like a global.get is very possibly going to increase code size, however (since we add a tee, and since the local gets are of similar size to global gets - depends on LUB sizes). On real-world Java code that overhead is noticeable, so this PR makes us more careful, and we skip things of size 1 (no children). --- src/passes/LocalCSE.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/passes/LocalCSE.cpp b/src/passes/LocalCSE.cpp index 9e92093e1..52346030c 100644 --- a/src/passes/LocalCSE.cpp +++ b/src/passes/LocalCSE.cpp @@ -334,13 +334,16 @@ struct Scanner // and so adding one set+one get and removing one of the items itself // is not detrimental, and may be beneficial. // TODO: investigate size 2 - if (options.shrinkLevel > 0 && Measurer::measure(curr) >= 3) { + auto size = Measurer::measure(curr); + if (options.shrinkLevel > 0 && size >= 3) { return true; } // If we focus on speed, any reduction in cost is beneficial, as the - // cost of a get is essentially free. - if (options.shrinkLevel == 0 && CostAnalyzer(curr).cost > 0) { + // cost of a get is essentially free. However, we need to balance that with + // the fact that the VM will also do CSE/GVN itself, so minor improvements + // are not worthwhile, so skip things of size 1 (like a global.get). + if (options.shrinkLevel == 0 && CostAnalyzer(curr).cost > 0 && size >= 2) { return true; } -- cgit v1.2.3