diff options
author | Alon Zakai (kripken) <alonzakai@gmail.com> | 2017-02-13 15:17:57 -0800 |
---|---|---|
committer | Alon Zakai (kripken) <alonzakai@gmail.com> | 2017-02-16 22:45:39 -0800 |
commit | eec567640d154147fb88754fd13aada738a63eef (patch) | |
tree | 38c4479faf66e20a953f833d298855315d1b8627 /test | |
parent | 04d38f6f881b16a014c47e897a4590d76ec548ff (diff) | |
download | binaryen-eec567640d154147fb88754fd13aada738a63eef.tar.gz binaryen-eec567640d154147fb88754fd13aada738a63eef.tar.bz2 binaryen-eec567640d154147fb88754fd13aada738a63eef.zip |
use local info about maxBits and sign-extendedness in OptimizeInstructions
fix the maxBits of a signed load, which this uncovered - all the bits may be used in such a case
Diffstat (limited to 'test')
-rw-r--r-- | test/emcc_hello_world.fromasm | 5 | ||||
-rw-r--r-- | test/emcc_hello_world.fromasm.imprecise | 5 | ||||
-rw-r--r-- | test/passes/optimize-instructions.txt | 259 | ||||
-rw-r--r-- | test/passes/optimize-instructions.wast | 289 |
4 files changed, 548 insertions, 10 deletions
diff --git a/test/emcc_hello_world.fromasm b/test/emcc_hello_world.fromasm index 88db1c1ce..f01ba2f5d 100644 --- a/test/emcc_hello_world.fromasm +++ b/test/emcc_hello_world.fromasm @@ -5507,10 +5507,7 @@ (tee_local $5 (i32.add (i32.xor - (i32.and - (get_local $32) - (i32.const 1) - ) + (get_local $32) (i32.const 1) ) (get_local $17) diff --git a/test/emcc_hello_world.fromasm.imprecise b/test/emcc_hello_world.fromasm.imprecise index 5ed229e6f..22878e91f 100644 --- a/test/emcc_hello_world.fromasm.imprecise +++ b/test/emcc_hello_world.fromasm.imprecise @@ -5444,10 +5444,7 @@ (tee_local $5 (i32.add (i32.xor - (i32.and - (get_local $32) - (i32.const 1) - ) + (get_local $32) (i32.const 1) ) (get_local $17) diff --git a/test/passes/optimize-instructions.txt b/test/passes/optimize-instructions.txt index 31dceaf60..80d264e94 100644 --- a/test/passes/optimize-instructions.txt +++ b/test/passes/optimize-instructions.txt @@ -1240,8 +1240,22 @@ ) ) (drop + (i32.shr_s + (i32.shl + (i32.shr_u + (i32.load8_s + (i32.const 256) + ) + (i32.const 1) + ) + (i32.const 24) + ) + (i32.const 24) + ) + ) + (drop (i32.shr_u - (i32.load8_s + (i32.load8_u (i32.const 256) ) (i32.const 1) @@ -1344,4 +1358,247 @@ ) ) ) + (func $local-info-zero-ext (type $4) (param $0 i32) (param $1 i32) + (local $x i32) + (local $y i32) + (local $z i32) + (local $w i32) + (set_local $x + (i32.const 212) + ) + (drop + (get_local $x) + ) + (set_local $y + (i32.const 500) + ) + (drop + (i32.and + (get_local $y) + (i32.const 255) + ) + ) + (set_local $0 + (i32.const 212) + ) + (drop + (i32.and + (get_local $0) + (i32.const 255) + ) + ) + (set_local $z + (i32.const 212) + ) + (set_local $z + (i32.const 220) + ) + (drop + (get_local $z) + ) + (set_local $w + (i32.const 212) + ) + (set_local $w + (i32.const 1000) + ) + (drop + (i32.and + (get_local $w) + (i32.const 255) + ) + ) + ) + (func $local-info-sign-ext-bitsize (type $4) (param $0 i32) (param $1 i32) + (local $x i32) + (local $y i32) + (local $z i32) + (local $w i32) + (set_local $x + (i32.const 127) + ) + (drop + (get_local $x) + ) + (set_local $y + (i32.const 128) + ) + (drop + (i32.shr_s + (i32.shl + (get_local $y) + (i32.const 24) + ) + (i32.const 24) + ) + ) + (set_local $0 + (i32.const 127) + ) + (drop + (i32.shr_s + (i32.shl + (get_local $0) + (i32.const 24) + ) + (i32.const 24) + ) + ) + (set_local $z + (i32.const 127) + ) + (set_local $z + (i32.const 100) + ) + (drop + (get_local $z) + ) + (set_local $w + (i32.const 127) + ) + (set_local $w + (i32.const 150) + ) + (drop + (i32.shr_s + (i32.shl + (get_local $w) + (i32.const 24) + ) + (i32.const 24) + ) + ) + ) + (func $local-info-sign-ext-already-exted (type $4) (param $0 i32) (param $1 i32) + (local $x i32) + (local $y i32) + (local $z i32) + (local $w i32) + (set_local $x + (i32.shr_s + (i32.shl + (get_local $0) + (i32.const 24) + ) + (i32.const 24) + ) + ) + (drop + (get_local $x) + ) + (set_local $y + (i32.shr_s + (i32.shl + (get_local $0) + (i32.const 16) + ) + (i32.const 16) + ) + ) + (drop + (i32.shr_s + (i32.shl + (get_local $y) + (i32.const 24) + ) + (i32.const 24) + ) + ) + (set_local $0 + (i32.shr_s + (i32.shl + (get_local $0) + (i32.const 24) + ) + (i32.const 24) + ) + ) + (drop + (i32.shr_s + (i32.shl + (get_local $0) + (i32.const 24) + ) + (i32.const 24) + ) + ) + (set_local $z + (i32.shr_s + (i32.shl + (get_local $0) + (i32.const 24) + ) + (i32.const 24) + ) + ) + (set_local $z + (i32.shr_s + (i32.shl + (get_local $1) + (i32.const 24) + ) + (i32.const 24) + ) + ) + (drop + (get_local $z) + ) + (set_local $w + (i32.shr_s + (i32.shl + (get_local $0) + (i32.const 24) + ) + (i32.const 24) + ) + ) + (set_local $w + (i32.shr_s + (i32.shl + (get_local $0) + (i32.const 23) + ) + (i32.const 24) + ) + ) + (drop + (i32.shr_s + (i32.shl + (get_local $w) + (i32.const 24) + ) + (i32.const 24) + ) + ) + (drop + (i32.shr_s + (i32.shl + (get_local $0) + (i32.const 24) + ) + (i32.const 23) + ) + ) + ) + (func $signed-loads-fill-the-bits (type $3) (param $$e i32) (result i32) + (local $$0 i32) + (local $$conv i32) + (set_local $$0 + (i32.load8_s + (i32.const 1024) + ) + ) + (set_local $$conv + (i32.and + (get_local $$0) + (i32.const 255) + ) + ) + (return + (i32.eq + (get_local $$conv) + (get_local $$e) + ) + ) + ) ) diff --git a/test/passes/optimize-instructions.wast b/test/passes/optimize-instructions.wast index c305ccbbb..0169bb054 100644 --- a/test/passes/optimize-instructions.wast +++ b/test/passes/optimize-instructions.wast @@ -1556,7 +1556,21 @@ (i32.shr_s (i32.shl (i32.shr_u - (i32.load8_s ;; one byte, but reduced to 7 + (i32.load8_s ;; one byte, but sexted to 32 + (i32.const 256) + ) + (i32.const 1) + ) + (i32.const 24) + ) + (i32.const 24) + ) + ) + (drop + (i32.shr_s + (i32.shl + (i32.shr_u + (i32.load8_u ;; one byte, but reduced to 7 (i32.const 256) ) (i32.const 1) @@ -1691,4 +1705,277 @@ ) ) ) + (func $local-info-zero-ext (param $0 i32) (param $1 i32) + (local $x i32) + (local $y i32) + (local $z i32) + (local $w i32) + (set_local $x + (i32.const 212) ;; mask is unneeded, we are small + ) + (drop + (i32.and + (get_local $x) + (i32.const 255) + ) + ) + (set_local $y + (i32.const 500) ;; mask is needed, we are too big + ) + (drop + (i32.and + (get_local $y) + (i32.const 255) + ) + ) + (set_local $0 + (i32.const 212) ;; mask is unneeded, but we are a param, not a var, so no + ) + (drop + (i32.and + (get_local $0) + (i32.const 255) + ) + ) + (set_local $z + (i32.const 212) ;; mask is unneeded, we are small + ) + (set_local $z + (i32.const 220) ;; mask is still unneeded even with 2 uses + ) + (drop + (i32.and + (get_local $z) + (i32.const 255) + ) + ) + (set_local $w + (i32.const 212) ;; mask is unneeded, we are small + ) + (set_local $w + (i32.const 1000) ;; mask is needed, one use is too big + ) + (drop + (i32.and + (get_local $w) + (i32.const 255) + ) + ) + ) + (func $local-info-sign-ext-bitsize (param $0 i32) (param $1 i32) + (local $x i32) + (local $y i32) + (local $z i32) + (local $w i32) + (set_local $x + (i32.const 127) ;; mask is unneeded, we are small + ) + (drop + (i32.shr_s + (i32.shl + (get_local $x) + (i32.const 24) + ) + (i32.const 24) + ) + ) + (set_local $y + (i32.const 128) ;; mask is needed, we are too big + ) + (drop + (i32.shr_s + (i32.shl + (get_local $y) + (i32.const 24) + ) + (i32.const 24) + ) + ) + (set_local $0 + (i32.const 127) ;; mask is unneeded, but we are a param, not a var, so no + ) + (drop + (i32.shr_s + (i32.shl + (get_local $0) + (i32.const 24) + ) + (i32.const 24) + ) + ) + (set_local $z + (i32.const 127) ;; mask is unneeded, we are small + ) + (set_local $z + (i32.const 100) ;; mask is still unneeded even with 2 uses + ) + (drop + (i32.shr_s + (i32.shl + (get_local $z) + (i32.const 24) + ) + (i32.const 24) + ) + ) + (set_local $w + (i32.const 127) ;; mask is unneeded, we are small + ) + (set_local $w + (i32.const 150) ;; mask is needed, one use is too big + ) + (drop + (i32.shr_s + (i32.shl + (get_local $w) + (i32.const 24) + ) + (i32.const 24) + ) + ) + ) + (func $local-info-sign-ext-already-exted (param $0 i32) (param $1 i32) + (local $x i32) + (local $y i32) + (local $z i32) + (local $w i32) + (set_local $x + (i32.shr_s + (i32.shl + (get_local $0) ;; already sign-exted here, so no need later + (i32.const 24) + ) + (i32.const 24) + ) + ) + (drop + (i32.shr_s + (i32.shl + (get_local $x) + (i32.const 24) + ) + (i32.const 24) + ) + ) + (set_local $y + (i32.shr_s + (i32.shl + (get_local $0) ;; already sign-exted here, but wrong bit size + (i32.const 16) + ) + (i32.const 16) + ) + ) + (drop + (i32.shr_s + (i32.shl + (get_local $y) + (i32.const 24) + ) + (i32.const 24) + ) + ) + (set_local $0 + (i32.shr_s + (i32.shl + (get_local $0) ;; already sign-exted here, so no need later, but we are a param + (i32.const 24) + ) + (i32.const 24) + ) + ) + (drop + (i32.shr_s + (i32.shl + (get_local $0) + (i32.const 24) + ) + (i32.const 24) + ) + ) + (set_local $z + (i32.shr_s + (i32.shl + (get_local $0) ;; already sign-exted here, so no need later + (i32.const 24) + ) + (i32.const 24) + ) + ) + (set_local $z + (i32.shr_s + (i32.shl + (get_local $1) ;; already sign-exted here, so no need later + (i32.const 24) + ) + (i32.const 24) + ) + ) + (drop + (i32.shr_s + (i32.shl + (get_local $z) + (i32.const 24) + ) + (i32.const 24) + ) + ) + (set_local $w + (i32.shr_s + (i32.shl + (get_local $0) ;; already sign-exted here, so no need later + (i32.const 24) + ) + (i32.const 24) + ) + ) + (set_local $w + (i32.shr_s + (i32.shl + (get_local $0) ;; not quite a sign-ext + (i32.const 23) + ) + (i32.const 24) + ) + ) + (drop + (i32.shr_s + (i32.shl + (get_local $w) + (i32.const 24) + ) + (i32.const 24) + ) + ) + (drop ;; odd corner case + (i32.shr_s + (i32.shl + (get_local $0) ;; param, so we should know nothing + (i32.const 24) + ) + (i32.const 23) ;; different shift, smaller + ) + ) + ) + (func $signed-loads-fill-the-bits (param $$e i32) (result i32) + (local $$0 i32) + (local $$conv i32) + (set_local $$0 + (i32.load8_s ;; one byte, but 32 bits due to sign-extend + (i32.const 1024) + ) + ) + (set_local $$conv + (i32.and + (get_local $$0) + (i32.const 255) ;; so we need this zexting! + ) + ) + (return + (i32.eq + (get_local $$conv) + (get_local $$e) + ) + ) + ) ) |