summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-10-27 11:28:35 -0700
committerGitHub <noreply@github.com>2016-10-27 11:28:35 -0700
commitaa06410ccd112d6276e734f8413f2754d32a1f47 (patch)
tree05da45facce4cff1920656bc168cb5a6628391b9
parent82639c7c658f4335850fe290f4cd6b34f3fb91f5 (diff)
downloadbinaryen-aa06410ccd112d6276e734f8413f2754d32a1f47.tar.gz
binaryen-aa06410ccd112d6276e734f8413f2754d32a1f47.tar.bz2
binaryen-aa06410ccd112d6276e734f8413f2754d32a1f47.zip
recurse in optimizeBoolean (#809)
-rw-r--r--src/passes/OptimizeInstructions.cpp10
-rw-r--r--test/emcc_O2_hello_world.fromasm9
-rw-r--r--test/emcc_O2_hello_world.fromasm.imprecise9
-rw-r--r--test/passes/optimize-instructions.txt17
-rw-r--r--test/passes/optimize-instructions.wast17
5 files changed, 50 insertions, 12 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp
index 6454d3510..6ba34990f 100644
--- a/src/passes/OptimizeInstructions.cpp
+++ b/src/passes/OptimizeInstructions.cpp
@@ -371,7 +371,17 @@ private:
}
}
}
+ } else if (auto* block = boolean->dynCast<Block>()) {
+ if (block->type == i32 && block->list.size() > 0) {
+ block->list.back() = optimizeBoolean(block->list.back());
+ }
+ } else if (auto* iff = boolean->dynCast<If>()) {
+ if (iff->type == i32) {
+ iff->ifTrue = optimizeBoolean(iff->ifTrue);
+ iff->ifFalse = optimizeBoolean(iff->ifFalse);
+ }
}
+ // TODO: recurse into br values?
return boolean;
}
diff --git a/test/emcc_O2_hello_world.fromasm b/test/emcc_O2_hello_world.fromasm
index 78428e1ce..632906543 100644
--- a/test/emcc_O2_hello_world.fromasm
+++ b/test/emcc_O2_hello_world.fromasm
@@ -9600,12 +9600,9 @@
(i32.const 12)
)
)
- (i32.ne
- (call $___syscall54
- (i32.const 54)
- (get_local $3)
- )
- (i32.const 0)
+ (call $___syscall54
+ (i32.const 54)
+ (get_local $3)
)
)
)
diff --git a/test/emcc_O2_hello_world.fromasm.imprecise b/test/emcc_O2_hello_world.fromasm.imprecise
index 0cd471b28..36a8a7099 100644
--- a/test/emcc_O2_hello_world.fromasm.imprecise
+++ b/test/emcc_O2_hello_world.fromasm.imprecise
@@ -9598,12 +9598,9 @@
(i32.const 12)
)
)
- (i32.ne
- (call $___syscall54
- (i32.const 54)
- (get_local $3)
- )
- (i32.const 0)
+ (call $___syscall54
+ (i32.const 54)
+ (get_local $3)
)
)
)
diff --git a/test/passes/optimize-instructions.txt b/test/passes/optimize-instructions.txt
index 1bd410822..226f1766e 100644
--- a/test/passes/optimize-instructions.txt
+++ b/test/passes/optimize-instructions.txt
@@ -375,4 +375,21 @@
)
(i32.const 1)
)
+ (func $recurse-bool (type $1)
+ (if
+ (if i32
+ (i32.const 1)
+ (call $ne0)
+ (call $ne0)
+ )
+ (nop)
+ )
+ (if
+ (block $block i32
+ (nop)
+ (call $ne0)
+ )
+ (nop)
+ )
+ )
)
diff --git a/test/passes/optimize-instructions.wast b/test/passes/optimize-instructions.wast
index 56e9d08fb..dfa6365f9 100644
--- a/test/passes/optimize-instructions.wast
+++ b/test/passes/optimize-instructions.wast
@@ -296,4 +296,21 @@
)
(i32.const 1)
)
+ (func $recurse-bool
+ (if
+ (if i32
+ (i32.const 1)
+ (i32.ne (call $ne0) (i32.const 0))
+ (i32.ne (call $ne0) (i32.const 0))
+ )
+ (nop)
+ )
+ (if
+ (block i32
+ (nop)
+ (i32.ne (call $ne0) (i32.const 0))
+ )
+ (nop)
+ )
+ )
)