diff options
author | Alon Zakai <azakai@google.com> | 2023-11-08 07:54:03 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-08 07:54:03 -0800 |
commit | 9627c8360d179c2cae168f8bca3bf1b7216c34a8 (patch) | |
tree | 77f4eeb54f47b59f44d90e0c206dbbf40600f3b3 /src | |
parent | 3640f9c992746867c5cf4cead11077e36a51eb7c (diff) | |
download | binaryen-9627c8360d179c2cae168f8bca3bf1b7216c34a8.tar.gz binaryen-9627c8360d179c2cae168f8bca3bf1b7216c34a8.tar.bz2 binaryen-9627c8360d179c2cae168f8bca3bf1b7216c34a8.zip |
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).
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/LocalCSE.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
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; } |