summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2018-12-21 13:19:18 -0800
committerGitHub <noreply@github.com>2018-12-21 13:19:18 -0800
commitfdd4cb7b11d43c6ff200c9541f8567000a8d4bcd (patch)
tree36c6a991a1a6f0b288eec05bf9ec197ba6d7624d /test
parent0f41b0708384c1f5d85304d5ed94d9edd57d38c9 (diff)
downloadbinaryen-fdd4cb7b11d43c6ff200c9541f8567000a8d4bcd.tar.gz
binaryen-fdd4cb7b11d43c6ff200c9541f8567000a8d4bcd.tar.bz2
binaryen-fdd4cb7b11d43c6ff200c9541f8567000a8d4bcd.zip
LocalCSE: Consider pass options, both size and cost (#1840)
With this we can optimize redundant global accesses fairly well (at least locally; licm also works), see #1831
Diffstat (limited to 'test')
-rw-r--r--test/example/cpp-unit.cpp18
-rw-r--r--test/example/cpp-unit.txt1
-rw-r--r--test/passes/licm.txt17
-rw-r--r--test/passes/licm.wast9
-rw-r--r--test/passes/local-cse.txt15
-rw-r--r--test/passes/local-cse.wast8
6 files changed, 68 insertions, 0 deletions
diff --git a/test/example/cpp-unit.cpp b/test/example/cpp-unit.cpp
new file mode 100644
index 000000000..f51ca72b6
--- /dev/null
+++ b/test/example/cpp-unit.cpp
@@ -0,0 +1,18 @@
+// test multiple uses of the threadPool
+
+#include <assert.h>
+
+#include <wasm.h>
+#include <ir/cost.h>
+
+using namespace wasm;
+
+int main()
+{
+ // Some optimizations assume that the cost of a get is zero, e.g. local-cse.
+ GetLocal get;
+ assert(CostAnalyzer(&get).cost == 0);
+
+ std::cout << "Success.\n";
+ return 0;
+}
diff --git a/test/example/cpp-unit.txt b/test/example/cpp-unit.txt
new file mode 100644
index 000000000..a9d787cc5
--- /dev/null
+++ b/test/example/cpp-unit.txt
@@ -0,0 +1 @@
+Success.
diff --git a/test/passes/licm.txt b/test/passes/licm.txt
index e76a0d683..25c78c7a0 100644
--- a/test/passes/licm.txt
+++ b/test/passes/licm.txt
@@ -4,6 +4,7 @@
(type $2 (func (result i64)))
(type $3 (func (param i32)))
(type $4 (func (param i32) (result i32)))
+ (global $glob (mut i32) (i32.const 1))
(func $loop1 (; 0 ;) (type $0)
(drop
(i32.const 10)
@@ -674,4 +675,20 @@
)
)
)
+ (func $global (; 40 ;) (type $0)
+ (local $x i32)
+ (set_local $x
+ (get_global $glob)
+ )
+ (drop
+ (get_local $x)
+ )
+ (loop $loop
+ (nop)
+ (nop)
+ (br_if $loop
+ (get_local $x)
+ )
+ )
+ )
)
diff --git a/test/passes/licm.wast b/test/passes/licm.wast
index d4227525b..349739ce8 100644
--- a/test/passes/licm.wast
+++ b/test/passes/licm.wast
@@ -1,4 +1,5 @@
(module
+ (global $glob (mut i32) (i32.const 1))
(func $loop1
(loop $loop
(drop (i32.const 10))
@@ -388,5 +389,13 @@
(br_if $loop (i32.const 1))
)
)
+ (func $global
+ (local $x i32)
+ (loop $loop
+ (set_local $x (get_global $glob))
+ (drop (get_local $x))
+ (br_if $loop (get_local $x))
+ )
+ )
)
diff --git a/test/passes/local-cse.txt b/test/passes/local-cse.txt
index 970a13dd8..62395f73f 100644
--- a/test/passes/local-cse.txt
+++ b/test/passes/local-cse.txt
@@ -1,5 +1,7 @@
(module
(type $0 (func (result i64)))
+ (type $1 (func))
+ (global $glob (mut i32) (i32.const 1))
(func $i64-shifts (; 0 ;) (type $0) (result i64)
(local $temp i64)
(set_local $temp
@@ -19,4 +21,17 @@
)
(get_local $temp)
)
+ (func $global (; 1 ;) (type $1)
+ (local $x i32)
+ (local $y i32)
+ (set_local $x
+ (get_global $glob)
+ )
+ (set_local $y
+ (get_local $x)
+ )
+ (set_local $y
+ (get_local $x)
+ )
+ )
)
diff --git a/test/passes/local-cse.wast b/test/passes/local-cse.wast
index 23ea6ff68..09534be60 100644
--- a/test/passes/local-cse.wast
+++ b/test/passes/local-cse.wast
@@ -1,4 +1,5 @@
(module
+ (global $glob (mut i32) (i32.const 1))
(func $i64-shifts (result i64)
(local $temp i64)
(set_local $temp
@@ -18,4 +19,11 @@
)
(get_local $temp)
)
+ (func $global
+ (local $x i32)
+ (local $y i32)
+ (set_local $x (get_global $glob))
+ (set_local $y (get_global $glob))
+ (set_local $y (get_global $glob))
+ )
)