summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMax Graey <maxgraey@gmail.com>2020-08-23 08:41:33 +0300
committerGitHub <noreply@github.com>2020-08-22 22:41:33 -0700
commitfa83375d2bed8802de67e1689e056209561636e6 (patch)
treed90890899b4b1582dee9b41710ee2aaacce96ee3 /test
parent7d1c17479318609b4af564f8206c1e367fdf6eac (diff)
downloadbinaryen-fa83375d2bed8802de67e1689e056209561636e6.tar.gz
binaryen-fa83375d2bed8802de67e1689e056209561636e6.tar.bz2
binaryen-fa83375d2bed8802de67e1689e056209561636e6.zip
Optimize bulk memory.copy (#3038)
Replace it with a load and a store when the size is a small constant and remove it entirely when it would be a nop.
Diffstat (limited to 'test')
-rw-r--r--test/passes/optimize-instructions_all-features.txt67
-rw-r--r--test/passes/optimize-instructions_all-features.wast73
2 files changed, 140 insertions, 0 deletions
diff --git a/test/passes/optimize-instructions_all-features.txt b/test/passes/optimize-instructions_all-features.txt
index e08702b91..b97106f2d 100644
--- a/test/passes/optimize-instructions_all-features.txt
+++ b/test/passes/optimize-instructions_all-features.txt
@@ -10,6 +10,7 @@
(type $i64_=>_i64 (func (param i64) (result i64)))
(type $i32_i64_f32_=>_none (func (param i32 i64 f32)))
(type $i32_i64_f32_f64_=>_none (func (param i32 i64 f32 f64)))
+ (type $i32_i32_i32_=>_none (func (param i32 i32 i32)))
(type $i32_i32_f64_f64_=>_none (func (param i32 i32 f64 f64)))
(type $i32_i64_f64_i32_=>_none (func (param i32 i64 f64 i32)))
(type $none_=>_f64 (func (result f64)))
@@ -3727,6 +3728,72 @@
)
)
)
+ (func $optimize-bulk-memory-copy (param $dst i32) (param $src i32) (param $sz i32)
+ (nop)
+ (block
+ (drop
+ (local.get $dst)
+ )
+ (drop
+ (local.get $src)
+ )
+ )
+ (i32.store8
+ (local.get $dst)
+ (i32.load8_u
+ (local.get $src)
+ )
+ )
+ (i32.store16 align=1
+ (local.get $dst)
+ (i32.load16_u align=1
+ (local.get $src)
+ )
+ )
+ (memory.copy
+ (local.get $dst)
+ (local.get $src)
+ (i32.const 3)
+ )
+ (i32.store align=1
+ (local.get $dst)
+ (i32.load align=1
+ (local.get $src)
+ )
+ )
+ (memory.copy
+ (local.get $dst)
+ (local.get $src)
+ (i32.const 5)
+ )
+ (memory.copy
+ (local.get $dst)
+ (local.get $src)
+ (i32.const 6)
+ )
+ (memory.copy
+ (local.get $dst)
+ (local.get $src)
+ (i32.const 7)
+ )
+ (i64.store align=1
+ (local.get $dst)
+ (i64.load align=1
+ (local.get $src)
+ )
+ )
+ (v128.store align=1
+ (local.get $dst)
+ (v128.load align=1
+ (local.get $src)
+ )
+ )
+ (memory.copy
+ (local.get $dst)
+ (local.get $src)
+ (local.get $sz)
+ )
+ )
)
(module
(type $none_=>_none (func))
diff --git a/test/passes/optimize-instructions_all-features.wast b/test/passes/optimize-instructions_all-features.wast
index 2790cc9ea..b62ecdcfd 100644
--- a/test/passes/optimize-instructions_all-features.wast
+++ b/test/passes/optimize-instructions_all-features.wast
@@ -4233,6 +4233,79 @@
)
))
)
+ (func $optimize-bulk-memory-copy (param $dst i32) (param $src i32) (param $sz i32)
+ (memory.copy ;; nop
+ (local.get $dst)
+ (local.get $dst)
+ (local.get $sz)
+ )
+
+ (memory.copy ;; nop
+ (local.get $dst)
+ (local.get $src)
+ (i32.const 0)
+ )
+
+ (memory.copy
+ (local.get $dst)
+ (local.get $src)
+ (i32.const 1)
+ )
+
+ (memory.copy
+ (local.get $dst)
+ (local.get $src)
+ (i32.const 2)
+ )
+
+ (memory.copy
+ (local.get $dst)
+ (local.get $src)
+ (i32.const 3)
+ )
+
+ (memory.copy
+ (local.get $dst)
+ (local.get $src)
+ (i32.const 4)
+ )
+
+ (memory.copy
+ (local.get $dst)
+ (local.get $src)
+ (i32.const 5)
+ )
+
+ (memory.copy
+ (local.get $dst)
+ (local.get $src)
+ (i32.const 6)
+ )
+
+ (memory.copy
+ (local.get $dst)
+ (local.get $src)
+ (i32.const 7)
+ )
+
+ (memory.copy
+ (local.get $dst)
+ (local.get $src)
+ (i32.const 8)
+ )
+
+ (memory.copy
+ (local.get $dst)
+ (local.get $src)
+ (i32.const 16)
+ )
+
+ (memory.copy ;; skip
+ (local.get $dst)
+ (local.get $src)
+ (local.get $sz)
+ )
+ )
)
(module
(import "env" "memory" (memory $0 (shared 256 256)))