diff options
author | Max Graey <maxgraey@gmail.com> | 2022-08-27 04:58:35 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-26 18:58:35 -0700 |
commit | d5b6972c9963be063d9f8db4ed8c99166c1c7ac5 (patch) | |
tree | f9c34a2730439312d163a4828e85919388779956 /test | |
parent | c929cf6b5ce444e1fadd52f6d289142ad5b3df5a (diff) | |
download | binaryen-d5b6972c9963be063d9f8db4ed8c99166c1c7ac5.tar.gz binaryen-d5b6972c9963be063d9f8db4ed8c99166c1c7ac5.tar.bz2 binaryen-d5b6972c9963be063d9f8db4ed8c99166c1c7ac5.zip |
[OptimizeInstructions] Canonicalize relational ops near min/max values (#4282)
A continuation of #4272.
```
(signed)x < s_min + 1 ==> x == s_min
(signed)x >= s_min + 1 ==> x != s_min
(signed)x > s_max - 1 ==> x == s_max
(signed)x <= s_max - 1 ==> x != s_max
(unsigned)x <= u_max - 1 ==> x != u_max
(unsigned)x > u_max - 1 ==> x == u_max
```
Diffstat (limited to 'test')
-rw-r--r-- | test/lit/passes/optimize-instructions.wast | 130 | ||||
-rw-r--r-- | test/lit/wat-kitchen-sink.wast | 2 |
2 files changed, 131 insertions, 1 deletions
diff --git a/test/lit/passes/optimize-instructions.wast b/test/lit/passes/optimize-instructions.wast index 73e7fd286..91e08e328 100644 --- a/test/lit/passes/optimize-instructions.wast +++ b/test/lit/passes/optimize-instructions.wast @@ -1644,6 +1644,136 @@ (i32.const 1) )) ) + ;; CHECK: (func $canonicalize-cmp-near-min-max (param $x i32) (param $y i64) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (i32.eq + ;; CHECK-NEXT: (local.get $x) + ;; CHECK-NEXT: (i32.const -2147483648) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (i64.eq + ;; CHECK-NEXT: (local.get $y) + ;; CHECK-NEXT: (i64.const -9223372036854775808) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (i32.ne + ;; CHECK-NEXT: (local.get $x) + ;; CHECK-NEXT: (i32.const -2147483648) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (i64.ne + ;; CHECK-NEXT: (local.get $y) + ;; CHECK-NEXT: (i64.const -9223372036854775808) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (i32.eq + ;; CHECK-NEXT: (local.get $x) + ;; CHECK-NEXT: (i32.const 2147483647) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (i64.eq + ;; CHECK-NEXT: (local.get $y) + ;; CHECK-NEXT: (i64.const 9223372036854775807) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (i32.ne + ;; CHECK-NEXT: (local.get $x) + ;; CHECK-NEXT: (i32.const 2147483647) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (i64.ne + ;; CHECK-NEXT: (local.get $y) + ;; CHECK-NEXT: (i64.const 9223372036854775807) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (i32.ne + ;; CHECK-NEXT: (local.get $x) + ;; CHECK-NEXT: (i32.const -1) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (i64.ne + ;; CHECK-NEXT: (local.get $y) + ;; CHECK-NEXT: (i64.const -1) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (i32.eq + ;; CHECK-NEXT: (local.get $x) + ;; CHECK-NEXT: (i32.const -1) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (i64.eq + ;; CHECK-NEXT: (local.get $y) + ;; CHECK-NEXT: (i64.const -1) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $canonicalize-cmp-near-min-max (param $x i32) (param $y i64) + ;; (signed)x < s_min + 1 ==> x == s_min + (drop (i32.lt_s + (local.get $x) + (i32.const -2147483647) + )) + (drop (i64.lt_s + (local.get $y) + (i64.const -9223372036854775807) + )) + ;; (signed)x >= s_min + 1 ==> x != s_min + (drop (i32.ge_s + (local.get $x) + (i32.const -2147483647) + )) + (drop (i64.ge_s + (local.get $y) + (i64.const -9223372036854775807) + )) + ;; (signed)x > s_max - 1 ==> x == s_max + (drop (i32.gt_s + (local.get $x) + (i32.const 2147483646) + )) + (drop (i64.gt_s + (local.get $y) + (i64.const 9223372036854775806) + )) + ;; (signed)x <= s_max - 1 ==> x != s_max + (drop (i32.le_s + (local.get $x) + (i32.const 2147483646) + )) + (drop (i64.le_s + (local.get $y) + (i64.const 9223372036854775806) + )) + ;; (unsigned)x <= u_max - 1 ==> x == u_max + (drop (i32.le_u + (local.get $x) + (i32.const -2) + )) + (drop (i64.le_u + (local.get $y) + (i64.const -2) + )) + ;; (unsigned)x > u_max - 1 ==> x != u_max + (drop (i32.gt_u + (local.get $x) + (i32.const -2) + )) + (drop (i64.gt_u + (local.get $y) + (i64.const -2) + )) + ) ;; CHECK: (func $canonicalize-cmp-const (param $x i32) (param $fx f64) ;; CHECK-NEXT: (drop ;; CHECK-NEXT: (i32.le_s diff --git a/test/lit/wat-kitchen-sink.wast b/test/lit/wat-kitchen-sink.wast index 09c983c5d..a8a9ea42d 100644 --- a/test/lit/wat-kitchen-sink.wast +++ b/test/lit/wat-kitchen-sink.wast @@ -9,7 +9,7 @@ ;; CHECK: (type $i32_=>_none (func_subtype (param i32) func)) - ;; CHECK: (rec + ;; CHECK: (rec ;; CHECK-NEXT: (type $s0 (struct_subtype data)) (type $s0 (sub (struct))) ;; CHECK: (type $s1 (struct_subtype data)) |