summaryrefslogtreecommitdiff
path: root/test/example
diff options
context:
space:
mode:
Diffstat (limited to 'test/example')
-rw-r--r--test/example/c-api-kitchen-sink.c27
-rw-r--r--test/example/c-api-kitchen-sink.txt222
2 files changed, 249 insertions, 0 deletions
diff --git a/test/example/c-api-kitchen-sink.c b/test/example/c-api-kitchen-sink.c
index 28fd901a4..b7b938c55 100644
--- a/test/example/c-api-kitchen-sink.c
+++ b/test/example/c-api-kitchen-sink.c
@@ -332,8 +332,35 @@ void test_relooper() {
BinaryenExpressionRef body = RelooperRenderAndDispose(relooper, block0, 0, module);
BinaryenFunctionRef sinker = BinaryenAddFunction(module, "loop-tail", v, localTypes, 1, body);
}
+ { // nontrivial loop + phi to head
+ RelooperRef relooper = RelooperCreate();
+ RelooperBlockRef block0 = RelooperAddBlock(relooper, makeInt32(module, 0));
+ RelooperBlockRef block1 = RelooperAddBlock(relooper, makeInt32(module, 1));
+ RelooperBlockRef block2 = RelooperAddBlock(relooper, makeInt32(module, 2));
+ RelooperBlockRef block3 = RelooperAddBlock(relooper, makeInt32(module, 3));
+ RelooperBlockRef block4 = RelooperAddBlock(relooper, makeInt32(module, 4));
+ RelooperBlockRef block5 = RelooperAddBlock(relooper, makeInt32(module, 5));
+ RelooperBlockRef block6 = RelooperAddBlock(relooper, makeInt32(module, 6));
+ RelooperAddBranch(block0, block1, NULL, makeInt32(module, 10));
+ RelooperAddBranch(block1, block2, makeInt32(module, -2), NULL);
+ RelooperAddBranch(block1, block6, NULL, makeInt32(module, 20));
+ RelooperAddBranch(block2, block3, makeInt32(module, -6), NULL);
+ RelooperAddBranch(block2, block1, NULL, makeInt32(module, 30));
+ RelooperAddBranch(block3, block4, makeInt32(module, -10), NULL);
+ RelooperAddBranch(block3, block5, NULL, NULL);
+ RelooperAddBranch(block4, block5, NULL, NULL);
+ RelooperAddBranch(block5, block6, NULL, makeInt32(module, 40));
+ BinaryenExpressionRef body = RelooperRenderAndDispose(relooper, block0, 0, module);
+ BinaryenFunctionRef sinker = BinaryenAddFunction(module, "nontrivial-loop-plus-phi-to-head", v, localTypes, 1, body);
+ }
+ printf("raw:\n");
BinaryenModulePrint(module);
+
+ printf("optimized:\n");
+ BinaryenModuleOptimize(module);
+ BinaryenModulePrint(module);
+
BinaryenModuleDispose(module);
}
diff --git a/test/example/c-api-kitchen-sink.txt b/test/example/c-api-kitchen-sink.txt
index 734038a74..71b937219 100644
--- a/test/example/c-api-kitchen-sink.txt
+++ b/test/example/c-api-kitchen-sink.txt
@@ -346,6 +346,7 @@ BinaryenFloat64: 4
)
)
)
+raw:
(module
(memory 0)
(type $v (func))
@@ -532,4 +533,225 @@ BinaryenFloat64: 4
(i32.const 2)
)
)
+ (func $nontrivial-loop-plus-phi-to-head (type $v)
+ (local $0 i32)
+ (block
+ (i32.const 0)
+ (block
+ (i32.const 10)
+ )
+ )
+ (block
+ (loop $shape$1$break $shape$1$continue
+ (block
+ (i32.const 1)
+ (if
+ (i32.eqz
+ (i32.const -2)
+ )
+ (block
+ (i32.const 20)
+ (br $shape$1$break)
+ )
+ )
+ )
+ (block
+ (i32.const 2)
+ (if
+ (i32.const -6)
+ (block
+ (set_local $0
+ (i32.const 4)
+ )
+ (br $shape$1$break)
+ )
+ (block
+ (i32.const 30)
+ (br $shape$1$continue)
+ )
+ )
+ )
+ )
+ (block
+ (block $shape$4$break
+ (if
+ (i32.eq
+ (get_local $0)
+ (i32.const 4)
+ )
+ (block
+ (block
+ (i32.const 3)
+ (block $shape$6$break
+ (if
+ (i32.const -10)
+ (block
+ (i32.const 4)
+ (block
+ (br $shape$6$break)
+ )
+ )
+ )
+ )
+ )
+ (block
+ (i32.const 5)
+ (block
+ (i32.const 40)
+ (br $shape$4$break)
+ )
+ )
+ )
+ )
+ )
+ (block
+ (i32.const 6)
+ )
+ )
+ )
+ )
+)
+optimized:
+(module
+ (memory 0)
+ (type $v (func))
+ (func $just-one-block (type $v)
+ (i32.const 1337)
+ )
+ (func $two-blocks (type $v)
+ (i32.const 0)
+ (i32.const 1)
+ )
+ (func $two-blocks-plus-code (type $v)
+ (i32.const 0)
+ (i32.const 77)
+ (i32.const 1)
+ )
+ (func $loop (type $v)
+ (loop $shape$0$break $shape$0$continue
+ (i32.const 0)
+ (i32.const 1)
+ (br $shape$0$continue)
+ )
+ )
+ (func $loop-plus-code (type $v)
+ (loop $shape$0$break $shape$0$continue
+ (i32.const 0)
+ (i32.const 33)
+ (i32.const 1)
+ (i32.const -66)
+ (br $shape$0$continue)
+ )
+ )
+ (func $split (type $v)
+ (i32.const 0)
+ (select
+ (i32.const 1)
+ (i32.const 2)
+ (i32.const 55)
+ )
+ )
+ (func $split-plus-code (type $v)
+ (i32.const 0)
+ (select
+ (block
+ (i32.const 10)
+ (i32.const 1)
+ )
+ (block
+ (i32.const 20)
+ (i32.const 2)
+ )
+ (i32.const 55)
+ )
+ )
+ (func $if (type $v)
+ (i32.const 0)
+ (if
+ (i32.const 55)
+ (i32.const 1)
+ )
+ (i32.const 2)
+ )
+ (func $if-plus-code (type $v)
+ (i32.const 0)
+ (select
+ (block
+ (i32.const -1)
+ (i32.const 1)
+ (i32.const -3)
+ )
+ (i32.const -2)
+ (i32.const 55)
+ )
+ (i32.const 2)
+ )
+ (func $if-else (type $v)
+ (i32.const 0)
+ (select
+ (i32.const 1)
+ (i32.const 2)
+ (i32.const 55)
+ )
+ (i32.const 3)
+ )
+ (func $loop-tail (type $v)
+ (loop $shape$0$break $shape$0$continue
+ (i32.const 0)
+ (i32.const 1)
+ (if
+ (i32.const 10)
+ (br $shape$0$continue)
+ (br $shape$0$break)
+ )
+ )
+ (i32.const 2)
+ )
+ (func $nontrivial-loop-plus-phi-to-head (type $v)
+ (local $0 i32)
+ (i32.const 0)
+ (i32.const 10)
+ (loop $shape$1$break $shape$1$continue
+ (i32.const 1)
+ (if
+ (i32.eqz
+ (i32.const -2)
+ )
+ (block
+ (i32.const 20)
+ (br $shape$1$break)
+ )
+ )
+ (i32.const 2)
+ (if
+ (i32.const -6)
+ (block
+ (set_local $0
+ (i32.const 4)
+ )
+ (br $shape$1$break)
+ )
+ (block
+ (i32.const 30)
+ (br $shape$1$continue)
+ )
+ )
+ )
+ (if
+ (i32.eq
+ (get_local $0)
+ (i32.const 4)
+ )
+ (block
+ (i32.const 3)
+ (if
+ (i32.const -10)
+ (i32.const 4)
+ )
+ (i32.const 5)
+ (i32.const 40)
+ )
+ )
+ (i32.const 6)
+ )
)