diff options
author | Alon Zakai (kripken) <alonzakai@gmail.com> | 2017-07-30 11:07:51 -0700 |
---|---|---|
committer | Alon Zakai (kripken) <alonzakai@gmail.com> | 2017-07-30 11:07:51 -0700 |
commit | 6cdffee098cb891c7309eb372aea63c0baa7a2c5 (patch) | |
tree | dbab872c51cfec5bd482030199bccdf1f2c2dde9 /test | |
parent | 56e49752b4258b89660825f2970a7e55067d7122 (diff) | |
download | binaryen-6cdffee098cb891c7309eb372aea63c0baa7a2c5.tar.gz binaryen-6cdffee098cb891c7309eb372aea63c0baa7a2c5.tar.bz2 binaryen-6cdffee098cb891c7309eb372aea63c0baa7a2c5.zip |
fix optimizing two shifts into one; if the number of effective shifts overflows, it is not vali to just add them
Diffstat (limited to 'test')
-rw-r--r-- | test/passes/optimize-instructions.txt | 39 | ||||
-rw-r--r-- | test/passes/optimize-instructions.wast | 36 |
2 files changed, 71 insertions, 4 deletions
diff --git a/test/passes/optimize-instructions.txt b/test/passes/optimize-instructions.txt index f7948860c..e376d97d9 100644 --- a/test/passes/optimize-instructions.txt +++ b/test/passes/optimize-instructions.txt @@ -6,6 +6,7 @@ (type $4 (func (param i32 i32))) (type $5 (func (param i32))) (type $6 (func (param i32 i32) (result i32))) + (type $7 (func (param i64) (result i64))) (memory $0 0) (export "load-off-2" (func $load-off-2)) (func $f (type $0) (param $i1 i32) (param $i2 i64) @@ -734,7 +735,7 @@ (i32.shr_s (i32.shl (i32.const 32) - (i32.const 59) + (i32.const 27) ) (i32.const 24) ) @@ -1083,19 +1084,19 @@ (drop (i32.shl (get_local $0) - (i32.const 211) + (i32.const 19) ) ) (drop (i32.shr_s (get_local $0) - (i32.const 211) + (i32.const 19) ) ) (drop (i32.shr_u (get_local $0) - (i32.const 211) + (i32.const 19) ) ) (drop @@ -2024,4 +2025,34 @@ (i32.const 255) ) ) + (func $shifts-square-overflow (type $3) (param $x i32) (result i32) + (i32.shr_u + (i32.shr_u + (get_local $x) + (i32.const 65535) + ) + (i32.const 32767) + ) + ) + (func $shifts-square-no-overflow-small (type $3) (param $x i32) (result i32) + (i32.shr_u + (get_local $x) + (i32.const 9) + ) + ) + (func $shifts-square-overflow-64 (type $7) (param $x i64) (result i64) + (i64.shr_u + (i64.shr_u + (get_local $x) + (i64.const 65535) + ) + (i64.const 64767) + ) + ) + (func $shifts-square-no-overflow-small-64 (type $7) (param $x i64) (result i64) + (i64.shr_u + (get_local $x) + (i64.const 9) + ) + ) ) diff --git a/test/passes/optimize-instructions.wast b/test/passes/optimize-instructions.wast index 107451b87..7e07e8aee 100644 --- a/test/passes/optimize-instructions.wast +++ b/test/passes/optimize-instructions.wast @@ -2451,4 +2451,40 @@ (i32.const 255) ) ) + (func $shifts-square-overflow (param $x i32) (result i32) + (i32.shr_u + (i32.shr_u + (get_local $x) + (i32.const 65535) ;; 31 bits effectively + ) + (i32.const 32767) ;; also 31 bits, so two shifts that force the value into nothing for sure + ) + ) + (func $shifts-square-no-overflow-small (param $x i32) (result i32) + (i32.shr_u + (i32.shr_u + (get_local $x) + (i32.const 1031) ;; 7 bits effectively + ) + (i32.const 4098) ;; 2 bits effectively + ) + ) + (func $shifts-square-overflow-64 (param $x i64) (result i64) + (i64.shr_u + (i64.shr_u + (get_local $x) + (i64.const 65535) ;; 63 bits effectively + ) + (i64.const 64767) ;; also 63 bits, so two shifts that force the value into nothing for sure + ) + ) + (func $shifts-square-no-overflow-small-64 (param $x i64) (result i64) + (i64.shr_u + (i64.shr_u + (get_local $x) + (i64.const 1031) ;; 7 bits effectively + ) + (i64.const 4098) ;; 2 bits effectively + ) + ) ) |