summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-01-05 10:57:41 -0800
committerAlon Zakai <alonzakai@gmail.com>2016-01-05 11:21:40 -0800
commit8452a0b54562590e568b5f86fe35c0fb4001a78c (patch)
tree7e71f5f84f985565b4c83cec9d1c0772f4a7f529
parent6c3b37355c7e24a763e0f6e65829391f5fe29b42 (diff)
downloadbinaryen-8452a0b54562590e568b5f86fe35c0fb4001a78c.tar.gz
binaryen-8452a0b54562590e568b5f86fe35c0fb4001a78c.tar.bz2
binaryen-8452a0b54562590e568b5f86fe35c0fb4001a78c.zip
MergeBlocks #32
-rw-r--r--CMakeLists.txt2
-rwxr-xr-xbuild.sh6
-rw-r--r--src/asm2wasm.h1
-rw-r--r--src/passes/MergeBlocks.cpp56
-rw-r--r--test/emcc_O2_hello_world.fromasm340
-rw-r--r--test/emcc_hello_world.fromasm342
-rw-r--r--test/passes/merge-blocks.txt170
-rw-r--r--test/passes/merge-blocks.wast86
8 files changed, 634 insertions, 369 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f1d575635..124a93fd0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -34,6 +34,7 @@ SET(binaryen-shell_SOURCES
src/binaryen-shell.cpp
src/pass.cpp
src/passes/LowerIfElse.cpp
+ src/passes/MergeBlocks.cpp
src/passes/NameManager.cpp
src/passes/RemoveImports.cpp
src/passes/RemoveUnusedBrs.cpp
@@ -49,6 +50,7 @@ INSTALL(TARGETS binaryen-shell DESTINATION bin)
SET(asm2wasm_SOURCES
src/asm2wasm-main.cpp
src/pass.cpp
+ src/passes/MergeBlocks.cpp
src/passes/RemoveUnusedBrs.cpp
src/passes/RemoveUnusedNames.cpp
src/emscripten-optimizer/parser.cpp
diff --git a/build.sh b/build.sh
index 6ec6e054a..c6cee16f6 100755
--- a/build.sh
+++ b/build.sh
@@ -1,13 +1,13 @@
./update.py
echo "building binaryen shell"
-g++ -O2 -std=c++11 src/binaryen-shell.cpp src/pass.cpp src/passes/LowerIfElse.cpp src/passes/NameManager.cpp src/passes/RemoveImports.cpp src/passes/RemoveUnusedNames.cpp src/support/colors.cpp -o bin/binaryen-shell -Isrc/ -msse2 -mfpmath=sse # use sse for math, avoid x87, necessarily for proper float rounding on 32-bit
+g++ -O2 -std=c++11 src/binaryen-shell.cpp src/pass.cpp src/passes/LowerIfElse.cpp src/passes/MergeBlocks.cpp src/passes/NameManager.cpp src/passes/RemoveImports.cpp src/passes/RemoveUnusedBrs.cpp src/passes/RemoveUnusedNames.cpp src/support/colors.cpp -o bin/binaryen-shell -Isrc/ -msse2 -mfpmath=sse # use sse for math, avoid x87, necessarily for proper float rounding on 32-bit
echo "building asm2wasm"
-g++ -O2 -std=c++11 src/asm2wasm-main.cpp src/passes/RemoveUnusedBrs.cpp src/pass.cpp src/passes/RemoveUnusedNames.cpp src/emscripten-optimizer/parser.cpp src/emscripten-optimizer/simple_ast.cpp src/emscripten-optimizer/optimizer-shared.cpp src/support/colors.cpp -Isrc/ -o bin/asm2wasm
+g++ -O2 -std=c++11 src/asm2wasm-main.cpp src/passes/MergeBlocks.cpp src/passes/RemoveUnusedBrs.cpp src/pass.cpp src/passes/RemoveUnusedNames.cpp src/emscripten-optimizer/parser.cpp src/emscripten-optimizer/simple_ast.cpp src/emscripten-optimizer/optimizer-shared.cpp src/support/colors.cpp -Isrc/ -o bin/asm2wasm
echo "building wasm2asm"
g++ -O2 -std=c++11 src/wasm2asm-main.cpp src/emscripten-optimizer/parser.cpp src/emscripten-optimizer/simple_ast.cpp src/emscripten-optimizer/optimizer-shared.cpp src/support/colors.cpp -Isrc/ -o bin/wasm2asm
echo "building s2wasm"
g++ -O2 -std=c++11 src/s2wasm-main.cpp src/support/colors.cpp -Isrc/ -o bin/s2wasm
echo "building interpreter/js"
-em++ -std=c++11 src/wasm-js.cpp src/pass.cpp src/passes/RemoveUnusedBrs.cpp src/passes/RemoveUnusedNames.cpp src/emscripten-optimizer/parser.cpp src/emscripten-optimizer/simple_ast.cpp src/emscripten-optimizer/optimizer-shared.cpp src/support/colors.cpp -Isrc/ -o bin/wasm.js -s MODULARIZE=1 -s 'EXPORT_NAME="WasmJS"' --memory-init-file 0 -Oz -s ALLOW_MEMORY_GROWTH=1 -profiling -s DEMANGLE_SUPPORT=1 #-DWASM_JS_DEBUG -DWASM_INTERPRETER_DEBUG=2
+em++ -std=c++11 src/wasm-js.cpp src/pass.cpp src/passes/MergeBlocks.cpp src/passes/RemoveUnusedBrs.cpp src/passes/RemoveUnusedNames.cpp src/emscripten-optimizer/parser.cpp src/emscripten-optimizer/simple_ast.cpp src/emscripten-optimizer/optimizer-shared.cpp src/support/colors.cpp -Isrc/ -o bin/wasm.js -s MODULARIZE=1 -s 'EXPORT_NAME="WasmJS"' --memory-init-file 0 -Oz -s ALLOW_MEMORY_GROWTH=1 -profiling -s DEMANGLE_SUPPORT=1 #-DWASM_JS_DEBUG -DWASM_INTERPRETER_DEBUG=2
cat src/js/wasm.js-post.js >> bin/wasm.js
diff --git a/src/asm2wasm.h b/src/asm2wasm.h
index e91a9344e..0320b7924 100644
--- a/src/asm2wasm.h
+++ b/src/asm2wasm.h
@@ -1573,6 +1573,7 @@ void Asm2WasmBuilder::optimize() {
PassRunner passRunner(&allocator);
passRunner.add("remove-unused-brs");
passRunner.add("remove-unused-names");
+ passRunner.add("merge-blocks");
passRunner.run(&wasm);
}
diff --git a/src/passes/MergeBlocks.cpp b/src/passes/MergeBlocks.cpp
new file mode 100644
index 000000000..3d7afc4cb
--- /dev/null
+++ b/src/passes/MergeBlocks.cpp
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2015 WebAssembly Community Group participants
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//
+// Merges blocks to their parents.
+//
+
+#include <wasm.h>
+#include <pass.h>
+
+namespace wasm {
+
+struct MergeBlocks : public Pass {
+ void visitBlock(Block *curr) override {
+ bool more = true;
+ while (more) {
+ more = false;
+ for (size_t i = 0; i < curr->list.size(); i++) {
+ Block* child = curr->list[i]->dyn_cast<Block>();
+ if (!child) continue;
+ if (child->name.is()) continue; // named blocks can have breaks to them (and certainly do, if we ran RemoveUnusedNames and RemoveUnusedBrs)
+ ExpressionList merged;
+ for (size_t j = 0; j < i; j++) {
+ merged.push_back(curr->list[j]);
+ }
+ for (auto item : child->list) {
+ merged.push_back(item);
+ }
+ for (size_t j = i + 1; j < curr->list.size(); j++) {
+ merged.push_back(curr->list[j]);
+ }
+ curr->list = merged;
+ more = true;
+ break;
+ }
+ }
+ }
+};
+
+static RegisterPass<MergeBlocks> registerPass("merge-blocks", "merges blocks to their parents");
+
+} // namespace wasm
+
diff --git a/test/emcc_O2_hello_world.fromasm b/test/emcc_O2_hello_world.fromasm
index 84e10d632..e056b0c05 100644
--- a/test/emcc_O2_hello_world.fromasm
+++ b/test/emcc_O2_hello_world.fromasm
@@ -3710,22 +3710,20 @@
(i32.const 608)
)
)
- (block
- (set_local $i50
- (i32.add
- (get_local $i51)
- (get_local $i43)
- )
+ (set_local $i50
+ (i32.add
+ (get_local $i51)
+ (get_local $i43)
)
- (i32.or
- (i32.le_u
- (get_local $i50)
- (get_local $i51)
- )
- (i32.gt_u
- (get_local $i50)
- (get_local $i52)
- )
+ )
+ (i32.or
+ (i32.le_u
+ (get_local $i50)
+ (get_local $i51)
+ )
+ (i32.gt_u
+ (get_local $i50)
+ (get_local $i52)
)
)
)
@@ -4091,26 +4089,24 @@
(i32.const 656)
)
)
- (block
- (set_local $i5
- (i32.and
- (i32.add
- (i32.sub
- (get_local $i44)
- (get_local $i61)
- )
- (get_local $i52)
- )
+ (set_local $i5
+ (i32.and
+ (i32.add
(i32.sub
- (i32.const 0)
- (get_local $i52)
+ (get_local $i44)
+ (get_local $i61)
)
+ (get_local $i52)
+ )
+ (i32.sub
+ (i32.const 0)
+ (get_local $i52)
)
)
- (i32.lt_u
- (get_local $i5)
- (i32.const 2147483647)
- )
+ )
+ (i32.lt_u
+ (get_local $i5)
+ (i32.const 2147483647)
)
)
(i32.const 0)
@@ -4202,26 +4198,24 @@
(get_local $i43)
)
)
- (block
- (set_local $i43
- (call_import $_sbrk
- (i32.const 0)
- )
+ (set_local $i43
+ (call_import $_sbrk
+ (i32.const 0)
+ )
+ )
+ (i32.and
+ (i32.lt_u
+ (get_local $i63)
+ (get_local $i43)
)
(i32.and
- (i32.lt_u
+ (i32.ne
(get_local $i63)
- (get_local $i43)
+ (i32.const -1)
)
- (i32.and
- (i32.ne
- (get_local $i63)
- (i32.const -1)
- )
- (i32.ne
- (get_local $i43)
- (i32.const -1)
- )
+ (i32.ne
+ (get_local $i43)
+ (i32.const -1)
)
)
)
@@ -10755,39 +10749,37 @@
(nop)
(br $while-out$0)
)
- (block
- (if
- (i32.eq
- (get_local $i3)
- (i32.const 0)
- )
- (br $topmost
- (get_local $i4)
- )
+ (if
+ (i32.eq
+ (get_local $i3)
+ (i32.const 0)
)
- (i32.store8 align=1
- (get_local $i1)
- (i32.load8_s align=1
- (get_local $i2)
- )
+ (br $topmost
+ (get_local $i4)
)
- (set_local $i1
- (i32.add
- (get_local $i1)
- (i32.const 1)
- )
+ )
+ (i32.store8 align=1
+ (get_local $i1)
+ (i32.load8_s align=1
+ (get_local $i2)
)
- (set_local $i2
- (i32.add
- (get_local $i2)
- (i32.const 1)
- )
+ )
+ (set_local $i1
+ (i32.add
+ (get_local $i1)
+ (i32.const 1)
)
- (set_local $i3
- (i32.sub
- (get_local $i3)
- (i32.const 1)
- )
+ )
+ (set_local $i2
+ (i32.add
+ (get_local $i2)
+ (i32.const 1)
+ )
+ )
+ (set_local $i3
+ (i32.sub
+ (get_local $i3)
+ (i32.const 1)
)
)
(br $while-in$1)
@@ -10803,30 +10795,28 @@
(nop)
(br $while-out$2)
)
- (block
- (i32.store align=4
- (get_local $i1)
- (i32.load align=4
- (get_local $i2)
- )
+ (i32.store align=4
+ (get_local $i1)
+ (i32.load align=4
+ (get_local $i2)
)
- (set_local $i1
- (i32.add
- (get_local $i1)
- (i32.const 4)
- )
+ )
+ (set_local $i1
+ (i32.add
+ (get_local $i1)
+ (i32.const 4)
)
- (set_local $i2
- (i32.add
- (get_local $i2)
- (i32.const 4)
- )
+ )
+ (set_local $i2
+ (i32.add
+ (get_local $i2)
+ (i32.const 4)
)
- (set_local $i3
- (i32.sub
- (get_local $i3)
- (i32.const 4)
- )
+ )
+ (set_local $i3
+ (i32.sub
+ (get_local $i3)
+ (i32.const 4)
)
)
(br $while-in$3)
@@ -10844,30 +10834,28 @@
(nop)
(br $while-out$4)
)
- (block
- (i32.store8 align=1
- (get_local $i1)
- (i32.load8_s align=1
- (get_local $i2)
- )
+ (i32.store8 align=1
+ (get_local $i1)
+ (i32.load8_s align=1
+ (get_local $i2)
)
- (set_local $i1
- (i32.add
- (get_local $i1)
- (i32.const 1)
- )
+ )
+ (set_local $i1
+ (i32.add
+ (get_local $i1)
+ (i32.const 1)
)
- (set_local $i2
- (i32.add
- (get_local $i2)
- (i32.const 1)
- )
+ )
+ (set_local $i2
+ (i32.add
+ (get_local $i2)
+ (i32.const 1)
)
- (set_local $i3
- (i32.sub
- (get_local $i3)
- (i32.const 1)
- )
+ )
+ (set_local $i3
+ (i32.sub
+ (get_local $i3)
+ (i32.const 1)
)
)
(br $while-in$5)
@@ -10960,16 +10948,14 @@
(nop)
(br $while-out$0)
)
- (block
- (i32.store8 align=1
+ (i32.store8 align=1
+ (get_local $i1)
+ (get_local $i2)
+ )
+ (set_local $i1
+ (i32.add
(get_local $i1)
- (get_local $i2)
- )
- (set_local $i1
- (i32.add
- (get_local $i1)
- (i32.const 1)
- )
+ (i32.const 1)
)
)
(br $while-in$1)
@@ -10987,16 +10973,14 @@
(nop)
(br $while-out$2)
)
- (block
- (i32.store align=4
+ (i32.store align=4
+ (get_local $i1)
+ (get_local $i6)
+ )
+ (set_local $i1
+ (i32.add
(get_local $i1)
- (get_local $i6)
- )
- (set_local $i1
- (i32.add
- (get_local $i1)
- (i32.const 4)
- )
+ (i32.const 4)
)
)
(br $while-in$3)
@@ -11014,16 +10998,14 @@
(nop)
(br $while-out$4)
)
- (block
- (i32.store8 align=1
+ (i32.store8 align=1
+ (get_local $i1)
+ (get_local $i2)
+ )
+ (set_local $i1
+ (i32.add
(get_local $i1)
- (get_local $i2)
- )
- (set_local $i1
- (i32.add
- (get_local $i1)
- (i32.const 1)
- )
+ (i32.const 1)
)
)
(br $while-in$5)
@@ -11095,19 +11077,17 @@
(i32.const 20)
)
)
- (block
- (set_local $i6
- (i32.load align=4
- (get_local $i5)
- )
+ (set_local $i6
+ (i32.load align=4
+ (get_local $i5)
)
- (i32.lt_u
- (get_local $i6)
- (i32.load align=4
- (i32.add
- (get_local $i2)
- (i32.const 16)
- )
+ )
+ (i32.lt_u
+ (get_local $i6)
+ (i32.load align=4
+ (i32.add
+ (get_local $i2)
+ (i32.const 16)
)
)
)
@@ -11489,33 +11469,29 @@
)
)
)
- (block
- (i32.store align=4
- (i32.add
- (get_local $i5)
- (i32.const 4)
- )
- (i32.const 21505)
+ (i32.store align=4
+ (i32.add
+ (get_local $i5)
+ (i32.const 4)
)
- (block
- (i32.store align=4
- (i32.add
- (get_local $i5)
- (i32.const 8)
- )
- (i32.add
- (get_local $i4)
- (i32.const 12)
- )
- )
- (i32.ne
- (call_import $___syscall54
- (i32.const 54)
- (get_local $i5)
- )
- (i32.const 0)
- )
+ (i32.const 21505)
+ )
+ (i32.store align=4
+ (i32.add
+ (get_local $i5)
+ (i32.const 8)
)
+ (i32.add
+ (get_local $i4)
+ (i32.const 12)
+ )
+ )
+ (i32.ne
+ (call_import $___syscall54
+ (i32.const 54)
+ (get_local $i5)
+ )
+ (i32.const 0)
)
)
(i32.const 0)
diff --git a/test/emcc_hello_world.fromasm b/test/emcc_hello_world.fromasm
index bea407a53..574eb098a 100644
--- a/test/emcc_hello_world.fromasm
+++ b/test/emcc_hello_world.fromasm
@@ -30427,13 +30427,11 @@
)
)
)
- (block
- (i32.store align=4
- (i32.const 168)
- (get_local $h)
- )
- (get_local $l)
+ (i32.store align=4
+ (i32.const 168)
+ (get_local $h)
)
+ (get_local $l)
)
(func $_i64Add (param $a i32) (param $b i32) (param $c i32) (param $d i32) (result i32)
(local $l i32)
@@ -30456,13 +30454,11 @@
)
)
)
- (block
- (i32.store align=4
- (i32.const 168)
- (get_local $h)
- )
- (get_local $l)
+ (i32.store align=4
+ (i32.const 168)
+ (get_local $h)
)
+ (get_local $l)
)
(func $_memset (param $ptr i32) (param $value i32) (param $num i32) (result i32)
(local $stop i32)
@@ -30545,16 +30541,14 @@
(nop)
(br $while-out$0)
)
- (block
- (i32.store8 align=1
+ (i32.store8 align=1
+ (get_local $ptr)
+ (get_local $value)
+ )
+ (set_local $ptr
+ (i32.add
(get_local $ptr)
- (get_local $value)
- )
- (set_local $ptr
- (i32.add
- (get_local $ptr)
- (i32.const 1)
- )
+ (i32.const 1)
)
)
(br $while-in$1)
@@ -30572,16 +30566,14 @@
(nop)
(br $while-out$2)
)
- (block
- (i32.store align=4
+ (i32.store align=4
+ (get_local $ptr)
+ (get_local $value4)
+ )
+ (set_local $ptr
+ (i32.add
(get_local $ptr)
- (get_local $value4)
- )
- (set_local $ptr
- (i32.add
- (get_local $ptr)
- (i32.const 4)
- )
+ (i32.const 4)
)
)
(br $while-in$3)
@@ -30599,16 +30591,14 @@
(nop)
(br $while-out$4)
)
- (block
- (i32.store8 align=1
+ (i32.store8 align=1
+ (get_local $ptr)
+ (get_local $value)
+ )
+ (set_local $ptr
+ (i32.add
(get_local $ptr)
- (get_local $value)
- )
- (set_local $ptr
- (i32.add
- (get_local $ptr)
- (i32.const 1)
- )
+ (i32.const 1)
)
)
(br $while-in$5)
@@ -30782,39 +30772,37 @@
(nop)
(br $while-out$0)
)
- (block
- (if
- (i32.eq
- (get_local $num)
- (i32.const 0)
- )
- (br $topmost
- (get_local $ret)
- )
+ (if
+ (i32.eq
+ (get_local $num)
+ (i32.const 0)
)
- (i32.store8 align=1
- (get_local $dest)
- (i32.load8_s align=1
- (get_local $src)
- )
+ (br $topmost
+ (get_local $ret)
)
- (set_local $dest
- (i32.add
- (get_local $dest)
- (i32.const 1)
- )
+ )
+ (i32.store8 align=1
+ (get_local $dest)
+ (i32.load8_s align=1
+ (get_local $src)
)
- (set_local $src
- (i32.add
- (get_local $src)
- (i32.const 1)
- )
+ )
+ (set_local $dest
+ (i32.add
+ (get_local $dest)
+ (i32.const 1)
)
- (set_local $num
- (i32.sub
- (get_local $num)
- (i32.const 1)
- )
+ )
+ (set_local $src
+ (i32.add
+ (get_local $src)
+ (i32.const 1)
+ )
+ )
+ (set_local $num
+ (i32.sub
+ (get_local $num)
+ (i32.const 1)
)
)
(br $while-in$1)
@@ -30830,30 +30818,28 @@
(nop)
(br $while-out$2)
)
- (block
- (i32.store align=4
- (get_local $dest)
- (i32.load align=4
- (get_local $src)
- )
+ (i32.store align=4
+ (get_local $dest)
+ (i32.load align=4
+ (get_local $src)
)
- (set_local $dest
- (i32.add
- (get_local $dest)
- (i32.const 4)
- )
+ )
+ (set_local $dest
+ (i32.add
+ (get_local $dest)
+ (i32.const 4)
)
- (set_local $src
- (i32.add
- (get_local $src)
- (i32.const 4)
- )
+ )
+ (set_local $src
+ (i32.add
+ (get_local $src)
+ (i32.const 4)
)
- (set_local $num
- (i32.sub
- (get_local $num)
- (i32.const 4)
- )
+ )
+ (set_local $num
+ (i32.sub
+ (get_local $num)
+ (i32.const 4)
)
)
(br $while-in$3)
@@ -30871,30 +30857,28 @@
(nop)
(br $while-out$4)
)
- (block
- (i32.store8 align=1
- (get_local $dest)
- (i32.load8_s align=1
- (get_local $src)
- )
+ (i32.store8 align=1
+ (get_local $dest)
+ (i32.load8_s align=1
+ (get_local $src)
)
- (set_local $dest
- (i32.add
- (get_local $dest)
- (i32.const 1)
- )
+ )
+ (set_local $dest
+ (i32.add
+ (get_local $dest)
+ (i32.const 1)
)
- (set_local $src
- (i32.add
- (get_local $src)
- (i32.const 1)
- )
+ )
+ (set_local $src
+ (i32.add
+ (get_local $src)
+ (i32.const 1)
)
- (set_local $num
- (i32.sub
- (get_local $num)
- (i32.const 1)
- )
+ )
+ (set_local $num
+ (i32.sub
+ (get_local $num)
+ (i32.const 1)
)
)
(br $while-in$5)
@@ -31121,46 +31105,44 @@
(get_local $$1)
)
)
- (block
- (i32.store align=4
- (i32.const 168)
+ (i32.store align=4
+ (i32.const 168)
+ (i32.add
(i32.add
- (i32.add
- (i32.shr_u
- (get_local $$8)
- (i32.const 16)
- )
- (i32.mul
- (get_local $$11)
- (get_local $$6)
- )
- )
(i32.shr_u
- (i32.add
- (i32.and
- (get_local $$8)
- (i32.const 65535)
- )
- (get_local $$12)
- )
+ (get_local $$8)
(i32.const 16)
)
+ (i32.mul
+ (get_local $$11)
+ (get_local $$6)
+ )
)
- )
- (i32.or
- (i32.const 0)
- (i32.or
- (i32.shl
- (i32.add
+ (i32.shr_u
+ (i32.add
+ (i32.and
(get_local $$8)
- (get_local $$12)
+ (i32.const 65535)
)
- (i32.const 16)
+ (get_local $$12)
)
- (i32.and
- (get_local $$3)
- (i32.const 65535)
+ (i32.const 16)
+ )
+ )
+ )
+ (i32.or
+ (i32.const 0)
+ (i32.or
+ (i32.shl
+ (i32.add
+ (get_local $$8)
+ (get_local $$12)
)
+ (i32.const 16)
+ )
+ (i32.and
+ (get_local $$3)
+ (i32.const 65535)
)
)
)
@@ -31532,13 +31514,11 @@
(i32.const 8)
(get_local $__stackBase__)
)
- (block
- (i32.store align=4
- (i32.const 168)
- (get_local $$10$1)
- )
- (get_local $$10$0)
+ (i32.store align=4
+ (i32.const 168)
+ (get_local $$10$1)
)
+ (get_local $$10$0)
)
(func $___muldi3 (param $$a$0 i32) (param $$a$1 i32) (param $$b$0 i32) (param $$b$1 i32) (result i32)
(local $$x_sroa_0_0_extract_trunc i32)
@@ -31569,34 +31549,32 @@
(get_local $$y_sroa_0_0_extract_trunc)
)
)
- (block
- (i32.store align=4
- (i32.const 168)
- (i32.or
+ (i32.store align=4
+ (i32.const 168)
+ (i32.or
+ (i32.add
(i32.add
- (i32.add
- (i32.mul
- (get_local $$b$1)
- (get_local $$x_sroa_0_0_extract_trunc)
- )
- (get_local $$2)
+ (i32.mul
+ (get_local $$b$1)
+ (get_local $$x_sroa_0_0_extract_trunc)
)
- (get_local $$1$1)
- )
- (i32.and
- (get_local $$1$1)
- (i32.const 0)
+ (get_local $$2)
)
+ (get_local $$1$1)
)
- )
- (i32.or
- (i32.const 0)
(i32.and
- (get_local $$1$0)
- (i32.const -1)
+ (get_local $$1$1)
+ (i32.const 0)
)
)
)
+ (i32.or
+ (i32.const 0)
+ (i32.and
+ (get_local $$1$0)
+ (i32.const -1)
+ )
+ )
)
(func $___udivdi3 (param $$a$0 i32) (param $$a$1 i32) (param $$b$0 i32) (param $$b$1 i32) (result i32)
(local $$1$0 i32)
@@ -31642,20 +31620,18 @@
(i32.const 8)
(get_local $__stackBase__)
)
- (block
- (i32.store align=4
- (i32.const 168)
- (i32.load align=4
- (i32.add
- (get_local $$rem)
- (i32.const 4)
- )
- )
- )
+ (i32.store align=4
+ (i32.const 168)
(i32.load align=4
- (get_local $$rem)
+ (i32.add
+ (get_local $$rem)
+ (i32.const 4)
+ )
)
)
+ (i32.load align=4
+ (get_local $$rem)
+ )
)
(func $___udivmoddi4 (param $$a$0 i32) (param $$a$1 i32) (param $$b$0 i32) (param $$b$1 i32) (param $$rem i32) (result i32)
(local $$n_sroa_0_0_extract_trunc i32)
@@ -32901,13 +32877,11 @@
(get_local $$carry_0_lcssa$0)
)
)
- (block
- (i32.store align=4
- (i32.const 168)
- (get_local $$_0$1)
- )
- (get_local $$_0$0)
+ (i32.store align=4
+ (i32.const 168)
+ (get_local $$_0$1)
)
+ (get_local $$_0$0)
)
)
(func $dynCall_ii (param $index i32) (param $a1 i32) (result i32)
diff --git a/test/passes/merge-blocks.txt b/test/passes/merge-blocks.txt
new file mode 100644
index 000000000..876fe7b2f
--- /dev/null
+++ b/test/passes/merge-blocks.txt
@@ -0,0 +1,170 @@
+(module
+ (memory 16777216 16777216)
+ (func $b0-yes (param $i1 i32)
+ (block $topmost
+ (block $block0
+ (i32.const 10)
+ )
+ )
+ )
+ (func $b1-yes (param $i1 i32)
+ (block $topmost
+ (block $block0
+ (block $block1
+ (i32.const 10)
+ )
+ )
+ )
+ )
+ (func $b2-yes (param $i1 i32)
+ (block $topmost
+ (i32.const 5)
+ (block $block0
+ (i32.const 10)
+ )
+ (i32.const 15)
+ )
+ )
+ (func $b3-yes (param $i1 i32)
+ (block $topmost
+ (i32.const 3)
+ (block $block0
+ (i32.const 6)
+ (block $block1
+ (i32.const 10)
+ )
+ (i32.const 15)
+ )
+ (i32.const 20)
+ )
+ )
+ (func $b4 (param $i1 i32)
+ (block $topmost
+ (block $inner
+ (i32.const 10)
+ (br $inner)
+ )
+ )
+ )
+ (func $b5 (param $i1 i32)
+ (block $topmost
+ (block $middle
+ (block $inner
+ (i32.const 10)
+ (br $inner)
+ )
+ (br $middle)
+ )
+ )
+ )
+ (func $b6 (param $i1 i32)
+ (block $topmost
+ (i32.const 5)
+ (block $inner
+ (i32.const 10)
+ (br $inner)
+ )
+ (i32.const 15)
+ )
+ )
+ (func $b7 (param $i1 i32)
+ (block $topmost
+ (i32.const 3)
+ (block $middle
+ (i32.const 6)
+ (block $inner
+ (i32.const 10)
+ (br $inner)
+ )
+ (i32.const 15)
+ (br $middle)
+ )
+ (i32.const 20)
+ )
+ )
+)
+(module
+ (memory 16777216 16777216)
+ (func $b0-yes (param $i1 i32)
+ (block $topmost
+ (block $block0
+ (i32.const 10)
+ )
+ )
+ )
+ (func $b1-yes (param $i1 i32)
+ (block $topmost
+ (block $block0
+ (block $block1
+ (i32.const 10)
+ )
+ )
+ )
+ )
+ (func $b2-yes (param $i1 i32)
+ (block $topmost
+ (i32.const 5)
+ (block $block0
+ (i32.const 10)
+ )
+ (i32.const 15)
+ )
+ )
+ (func $b3-yes (param $i1 i32)
+ (block $topmost
+ (i32.const 3)
+ (block $block0
+ (i32.const 6)
+ (block $block1
+ (i32.const 10)
+ )
+ (i32.const 15)
+ )
+ (i32.const 20)
+ )
+ )
+ (func $b4 (param $i1 i32)
+ (block $topmost
+ (block $inner
+ (i32.const 10)
+ (br $inner)
+ )
+ )
+ )
+ (func $b5 (param $i1 i32)
+ (block $topmost
+ (block $middle
+ (block $inner
+ (i32.const 10)
+ (br $inner)
+ )
+ (br $middle)
+ )
+ )
+ )
+ (func $b6 (param $i1 i32)
+ (block $topmost
+ (i32.const 5)
+ (block $inner
+ (i32.const 10)
+ (br $inner)
+ )
+ (i32.const 15)
+ )
+ )
+ (func $b7 (param $i1 i32)
+ (block $topmost
+ (i32.const 3)
+ (block $middle
+ (i32.const 6)
+ (block $inner
+ (i32.const 10)
+ (br $inner)
+ )
+ (i32.const 15)
+ (br $middle)
+ )
+ (i32.const 20)
+ )
+ )
+)
diff --git a/test/passes/merge-blocks.wast b/test/passes/merge-blocks.wast
new file mode 100644
index 000000000..bd58ebc38
--- /dev/null
+++ b/test/passes/merge-blocks.wast
@@ -0,0 +1,86 @@
+(module
+ (memory 16777216 16777216)
+ (func $b0-yes (param $i1 i32)
+ (block $topmost
+ (block
+ (i32.const 10)
+ )
+ )
+ )
+ (func $b1-yes (param $i1 i32)
+ (block $topmost
+ (block
+ (block
+ (i32.const 10)
+ )
+ )
+ )
+ )
+ (func $b2-yes (param $i1 i32)
+ (block $topmost
+ (i32.const 5)
+ (block
+ (i32.const 10)
+ )
+ (i32.const 15)
+ )
+ )
+ (func $b3-yes (param $i1 i32)
+ (block $topmost
+ (i32.const 3)
+ (block
+ (i32.const 6)
+ (block
+ (i32.const 10)
+ )
+ (i32.const 15)
+ )
+ (i32.const 20)
+ )
+ )
+ (func $b4 (param $i1 i32)
+ (block $topmost
+ (block $inner
+ (i32.const 10)
+ (br $inner)
+ )
+ )
+ )
+ (func $b5 (param $i1 i32)
+ (block $topmost
+ (block $middle
+ (block $inner
+ (i32.const 10)
+ (br $inner)
+ )
+ (br $middle)
+ )
+ )
+ )
+ (func $b6 (param $i1 i32)
+ (block $topmost
+ (i32.const 5)
+ (block $inner
+ (i32.const 10)
+ (br $inner)
+ )
+ (i32.const 15)
+ )
+ )
+ (func $b7 (param $i1 i32)
+ (block $topmost
+ (i32.const 3)
+ (block $middle
+ (i32.const 6)
+ (block $inner
+ (i32.const 10)
+ (br $inner)
+ )
+ (i32.const 15)
+ (br $middle)
+ )
+ (i32.const 20)
+ )
+ )
+)
+