summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMax Graey <maxgraey@gmail.com>2020-10-30 08:08:48 +0200
committerGitHub <noreply@github.com>2020-10-29 23:08:48 -0700
commit5fc27e20479edfef0674c89e9bb7888ee25cb054 (patch)
treea748191c55e48d91bbc3d01ed64e6d3de0762c66 /test
parent25e47f2c3e7ca8151377075432b34c95073acaca (diff)
downloadbinaryen-5fc27e20479edfef0674c89e9bb7888ee25cb054.tar.gz
binaryen-5fc27e20479edfef0674c89e9bb7888ee25cb054.tar.bz2
binaryen-5fc27e20479edfef0674c89e9bb7888ee25cb054.zip
Fold subtraction of sums or differences from constants (#3295)
`C1 - (x + C2)` -> `(C1 - C2) - x` `C1 - (x - C2)` -> `(C1 + C2) - x` `C1 - (C2 - x)` -> `x + (C1 - C2)`
Diffstat (limited to 'test')
-rw-r--r--test/passes/optimize-instructions_all-features.txt44
-rw-r--r--test/passes/optimize-instructions_all-features.wast55
2 files changed, 99 insertions, 0 deletions
diff --git a/test/passes/optimize-instructions_all-features.txt b/test/passes/optimize-instructions_all-features.txt
index 96346ed22..522bd6fe8 100644
--- a/test/passes/optimize-instructions_all-features.txt
+++ b/test/passes/optimize-instructions_all-features.txt
@@ -4391,6 +4391,50 @@
)
)
)
+ (func $lhs-is-const (param $x i32) (param $y i64)
+ (drop
+ (i32.sub
+ (i32.const 1)
+ (local.get $x)
+ )
+ )
+ (drop
+ (i64.sub
+ (i64.const 1)
+ (local.get $y)
+ )
+ )
+ (drop
+ (i32.sub
+ (i32.const -2)
+ (local.get $x)
+ )
+ )
+ (drop
+ (i64.sub
+ (i64.const -2)
+ (local.get $y)
+ )
+ )
+ (drop
+ (i32.sub
+ (local.get $x)
+ (i32.const 1)
+ )
+ )
+ (drop
+ (i64.sub
+ (local.get $y)
+ (i64.const 1)
+ )
+ )
+ (drop
+ (i32.sub
+ (local.get $x)
+ (i32.const -2147483648)
+ )
+ )
+ )
(func $pre-combine-or (param $x i32) (param $y i32)
(drop
(i32.ge_s
diff --git a/test/passes/optimize-instructions_all-features.wast b/test/passes/optimize-instructions_all-features.wast
index cdb3c56f2..9b172e4bd 100644
--- a/test/passes/optimize-instructions_all-features.wast
+++ b/test/passes/optimize-instructions_all-features.wast
@@ -4842,6 +4842,61 @@
(local.get $x)
))
)
+ (func $lhs-is-const (param $x i32) (param $y i64)
+ ;; 0 - (x - 1)
+ (drop (i32.sub
+ (i32.const 0)
+ (i32.sub
+ (local.get $x)
+ (i32.const 1)
+ )
+ ))
+ (drop (i64.sub
+ (i64.const 0)
+ (i64.sub
+ (local.get $y)
+ (i64.const 1)
+ )
+ ))
+ ;; -1 - (x + 1)
+ (drop (i32.sub
+ (i32.const -1)
+ (i32.add
+ (local.get $x)
+ (i32.const 1)
+ )
+ ))
+ (drop (i64.sub
+ (i64.const -1)
+ (i64.add
+ (local.get $y)
+ (i64.const 1)
+ )
+ ))
+ ;; 1 - (2 - x)
+ (drop (i32.sub
+ (i32.const 1)
+ (i32.sub
+ (i32.const 2)
+ (local.get $x)
+ )
+ ))
+ (drop (i64.sub
+ (i64.const 1)
+ (i64.sub
+ (i64.const 2)
+ (local.get $y)
+ )
+ ))
+ ;; 0 - (0x80000000 - x)
+ (drop (i32.sub
+ (i32.const 0)
+ (i32.sub
+ (i32.const 0x80000000)
+ (local.get $x)
+ )
+ ))
+ )
(func $pre-combine-or (param $x i32) (param $y i32)
(drop (i32.or
(i32.gt_s