summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/unit/input/stack_ir.wast12
-rw-r--r--test/unit/test_stack_ir.py19
2 files changed, 31 insertions, 0 deletions
diff --git a/test/unit/input/stack_ir.wast b/test/unit/input/stack_ir.wast
new file mode 100644
index 000000000..0d5d0dfc3
--- /dev/null
+++ b/test/unit/input/stack_ir.wast
@@ -0,0 +1,12 @@
+(module
+ (import "env" "bar" (func $bar (param i32) (result i32)))
+ (func "foo1" (result i32)
+ (local $x i32)
+ (local.set $x (call $bar (i32.const 0)))
+ (drop
+ (call $bar (i32.const 1))
+ )
+ (local.get $x) ;; local2stack can help here
+ )
+)
+
diff --git a/test/unit/test_stack_ir.py b/test/unit/test_stack_ir.py
new file mode 100644
index 000000000..1fcab88d8
--- /dev/null
+++ b/test/unit/test_stack_ir.py
@@ -0,0 +1,19 @@
+import os
+from scripts.test import shared
+from . import utils
+
+
+class StackIRTest(utils.BinaryenTestCase):
+ # test that stack IR opts make a difference.
+ def test_stack_ir_opts(self):
+ path = self.input_path('stack_ir.wast')
+ opt = shared.run_process(shared.WASM_OPT + [path, '-O', '--generate-stack-ir', '--optimize-stack-ir', '--print-stack-ir', '-o', 'a.wasm'], capture_output=True).stdout
+ nonopt = shared.run_process(shared.WASM_OPT + [path, '-O', '--generate-stack-ir', '--print-stack-ir', '-o', 'b.wasm'], capture_output=True).stdout
+ # see a difference in the printed stack IR (the optimizations let us
+ # remove a pair of local.set/get)
+ self.assertNotEqual(opt, nonopt)
+ self.assertLess(len(opt), len(nonopt))
+ # see a difference in the actual emitted wasm binary.
+ opt_size = os.path.getsize('a.wasm')
+ nonopt_size = os.path.getsize('b.wasm')
+ self.assertLess(opt_size, nonopt_size)