summaryrefslogtreecommitdiff
path: root/src/passes/Vacuum.cpp
diff options
context:
space:
mode:
authorAlon Zakai (kripken) <alonzakai@gmail.com>2017-07-10 18:48:02 -0700
committerAlon Zakai (kripken) <alonzakai@gmail.com>2017-07-11 11:07:45 -0700
commit4be7ec00157250ca83b61a2e1885645c67c6369c (patch)
treec0e6b98b252aad7307e1a915cbad7c5641625cab /src/passes/Vacuum.cpp
parent45f8fedce6d432bfe24573ae4edb092202ef7bb9 (diff)
downloadbinaryen-4be7ec00157250ca83b61a2e1885645c67c6369c.tar.gz
binaryen-4be7ec00157250ca83b61a2e1885645c67c6369c.tar.bz2
binaryen-4be7ec00157250ca83b61a2e1885645c67c6369c.zip
handle unary and binary nodes that have implicit traps in vacuum
Diffstat (limited to 'src/passes/Vacuum.cpp')
-rw-r--r--src/passes/Vacuum.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/passes/Vacuum.cpp b/src/passes/Vacuum.cpp
index 70230e502..40f4a6e59 100644
--- a/src/passes/Vacuum.cpp
+++ b/src/passes/Vacuum.cpp
@@ -93,8 +93,14 @@ struct Vacuum : public WalkerPass<PostWalker<Vacuum>> {
if (resultUsed) {
return curr; // used, keep it
}
- // for unary, binary, and select, we need to check their arguments for side effects
+ // for unary, binary, and select, we need to check their arguments for side effects,
+ // as well as the node itself, as some unaries and binaries have implicit traps
if (auto* unary = curr->dynCast<Unary>()) {
+ EffectAnalyzer tester(getPassOptions());
+ tester.visitUnary(unary);
+ if (tester.hasSideEffects()) {
+ return curr;
+ }
if (EffectAnalyzer(getPassOptions(), unary->value).hasSideEffects()) {
curr = unary->value;
continue;
@@ -102,6 +108,11 @@ struct Vacuum : public WalkerPass<PostWalker<Vacuum>> {
return nullptr;
}
} else if (auto* binary = curr->dynCast<Binary>()) {
+ EffectAnalyzer tester(getPassOptions());
+ tester.visitBinary(binary);
+ if (tester.hasSideEffects()) {
+ return curr;
+ }
if (EffectAnalyzer(getPassOptions(), binary->left).hasSideEffects()) {
if (EffectAnalyzer(getPassOptions(), binary->right).hasSideEffects()) {
return curr; // leave them