summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2017-02-28 19:21:27 -0800
committerGitHub <noreply@github.com>2017-02-28 19:21:27 -0800
commit8968a50fd4248860cc79ee20eabf4071336f0481 (patch)
tree58ea1bece17d02f1544eb4decb824fc36ae59afe
parent9607b1b7692edad2fe379ade5ee146132fa5f0d7 (diff)
downloadbinaryen-8968a50fd4248860cc79ee20eabf4071336f0481.tar.gz
binaryen-8968a50fd4248860cc79ee20eabf4071336f0481.tar.bz2
binaryen-8968a50fd4248860cc79ee20eabf4071336f0481.zip
do not merge a drop out of an if if the sides have different types, then the if would be invalid (#927)
-rw-r--r--src/passes/Vacuum.cpp14
-rw-r--r--test/passes/vacuum.txt12
-rw-r--r--test/passes/vacuum.wast12
3 files changed, 33 insertions, 5 deletions
diff --git a/src/passes/Vacuum.cpp b/src/passes/Vacuum.cpp
index 1b4da4c47..63a098fc0 100644
--- a/src/passes/Vacuum.cpp
+++ b/src/passes/Vacuum.cpp
@@ -213,11 +213,15 @@ struct Vacuum : public WalkerPass<ExpressionStackWalker<Vacuum>> {
curr->ifFalse = nullptr;
curr->condition = Builder(*getModule()).makeUnary(EqZInt32, curr->condition);
} else if (curr->ifTrue->is<Drop>() && curr->ifFalse->is<Drop>()) {
- // instead of dropping both sides, drop the if
- curr->ifTrue = curr->ifTrue->cast<Drop>()->value;
- curr->ifFalse = curr->ifFalse->cast<Drop>()->value;
- curr->finalize();
- replaceCurrent(Builder(*getModule()).makeDrop(curr));
+ // instead of dropping both sides, drop the if, if they are the same type
+ auto* left = curr->ifTrue->cast<Drop>()->value;
+ auto* right = curr->ifFalse->cast<Drop>()->value;
+ if (left->type == right->type) {
+ curr->ifTrue = left;
+ curr->ifFalse = right;
+ curr->finalize();
+ replaceCurrent(Builder(*getModule()).makeDrop(curr));
+ }
}
} else {
// no else
diff --git a/test/passes/vacuum.txt b/test/passes/vacuum.txt
index bc3cbfda3..131686b42 100644
--- a/test/passes/vacuum.txt
+++ b/test/passes/vacuum.txt
@@ -218,6 +218,18 @@
)
(i32.const 2)
)
+ (func $if2drops-different (type $3) (result i32)
+ (if
+ (call $if2drops)
+ (drop
+ (call $if2drops)
+ )
+ (drop
+ (call $unary)
+ )
+ )
+ (i32.const 2)
+ )
(func $if-const (type $1) (param $x i32)
(call $if-const
(i32.const 3)
diff --git a/test/passes/vacuum.wast b/test/passes/vacuum.wast
index 05a8611c5..06dea2034 100644
--- a/test/passes/vacuum.wast
+++ b/test/passes/vacuum.wast
@@ -427,6 +427,18 @@
)
(i32.const 2)
)
+ (func $if2drops-different (result i32)
+ (if
+ (call $if2drops)
+ (drop
+ (call $if2drops) ;; i32
+ )
+ (drop
+ (call $unary) ;; f32!
+ )
+ )
+ (i32.const 2)
+ )
(func $if-const (param $x i32)
(if (i32.const 0) (call $if-const (i32.const 1)))
(if (i32.const 2) (call $if-const (i32.const 3)))