summaryrefslogtreecommitdiff
path: root/src/passes/LocalCSE.cpp
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2018-12-21 13:19:18 -0800
committerGitHub <noreply@github.com>2018-12-21 13:19:18 -0800
commitfdd4cb7b11d43c6ff200c9541f8567000a8d4bcd (patch)
tree36c6a991a1a6f0b288eec05bf9ec197ba6d7624d /src/passes/LocalCSE.cpp
parent0f41b0708384c1f5d85304d5ed94d9edd57d38c9 (diff)
downloadbinaryen-fdd4cb7b11d43c6ff200c9541f8567000a8d4bcd.tar.gz
binaryen-fdd4cb7b11d43c6ff200c9541f8567000a8d4bcd.tar.bz2
binaryen-fdd4cb7b11d43c6ff200c9541f8567000a8d4bcd.zip
LocalCSE: Consider pass options, both size and cost (#1840)
With this we can optimize redundant global accesses fairly well (at least locally; licm also works), see #1831
Diffstat (limited to 'src/passes/LocalCSE.cpp')
-rw-r--r--src/passes/LocalCSE.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/passes/LocalCSE.cpp b/src/passes/LocalCSE.cpp
index 12f0d9d93..8faa5b47c 100644
--- a/src/passes/LocalCSE.cpp
+++ b/src/passes/LocalCSE.cpp
@@ -42,6 +42,7 @@
#include <wasm-traversal.h>
#include <pass.h>
#include <ir/effects.h>
+#include <ir/cost.h>
#include <ir/equivalent_sets.h>
#include <ir/hashed.h>
@@ -208,8 +209,19 @@ struct LocalCSE : public WalkerPass<LinearExecutionWalker<LocalCSE>> {
if (EffectAnalyzer(getPassOptions(), value).hasSideEffects()) {
return false; // we can't combine things with side effects
}
- // check what we care about TODO: use optimize/shrink levels?
- return Measurer::measure(value) > 1;
+ auto& options = getPassRunner()->options;
+ // If the size is at least 3, then if we have two of them we have 6,
+ // and so adding one set+two gets and removing one of the items itself
+ // is not detrimental, and may be beneficial.
+ if (options.shrinkLevel > 0 && Measurer::measure(value) >= 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(value).cost > 0) {
+ return true;
+ }
+ return false;
}
};