From 324e6b390952941b5c9f8241f21a3e7a59ef9ec8 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 27 Oct 2016 10:41:54 -0700 Subject: [PATCH] recurse in optimizeBoolean --- src/passes/OptimizeInstructions.cpp | 10 ++++++++++ test/emcc_O2_hello_world.fromasm | 9 +++------ test/emcc_O2_hello_world.fromasm.imprecise | 9 +++------ test/passes/optimize-instructions.txt | 17 +++++++++++++++++ test/passes/optimize-instructions.wast | 17 +++++++++++++++++ 5 files changed, 50 insertions(+), 12 deletions(-) diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp index 6454d35100f..6ba34990fe4 100644 --- a/src/passes/OptimizeInstructions.cpp +++ b/src/passes/OptimizeInstructions.cpp @@ -371,7 +371,17 @@ struct OptimizeInstructions : public WalkerPassdynCast()) { + if (block->type == i32 && block->list.size() > 0) { + block->list.back() = optimizeBoolean(block->list.back()); + } + } else if (auto* iff = boolean->dynCast()) { + 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 78428e1ceca..63290654364 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 0cd471b282e..36a8a7099f0 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 1bd41082272..226f1766e95 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 56e9d08fbe0..dfa6365f9b2 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) + ) + ) )