diff options
-rw-r--r-- | src/passes/OptimizeInstructions.cpp | 10 | ||||
-rw-r--r-- | test/emcc_O2_hello_world.fromasm | 9 | ||||
-rw-r--r-- | test/emcc_O2_hello_world.fromasm.imprecise | 9 | ||||
-rw-r--r-- | test/passes/optimize-instructions.txt | 17 | ||||
-rw-r--r-- | 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 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) + ) + ) ) |