summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/emcc_hello_world.fromasm118
-rw-r--r--test/emcc_hello_world.fromasm.imprecise118
-rw-r--r--test/passes/optimize-instructions.txt431
-rw-r--r--test/passes/optimize-instructions.wast584
-rw-r--r--test/passes/precompute.txt3
-rw-r--r--test/passes/precompute.wast6
6 files changed, 1117 insertions, 143 deletions
diff --git a/test/emcc_hello_world.fromasm b/test/emcc_hello_world.fromasm
index 87cf3f385..b3d40099f 100644
--- a/test/emcc_hello_world.fromasm
+++ b/test/emcc_hello_world.fromasm
@@ -328,7 +328,7 @@
)
)
(if
- (i32.load8_s
+ (i32.load8_u
(get_local $0)
)
(block
@@ -1471,7 +1471,7 @@
)
(if
(i32.ne
- (i32.load8_s
+ (i32.load8_u
(i32.add
(get_local $0)
(tee_local $6
@@ -1867,15 +1867,12 @@
(loop $while-in
(if
(i32.eq
- (i32.load8_s
+ (i32.load8_u
(get_local $2)
)
- (i32.shr_s
- (i32.shl
- (get_local $4)
- (i32.const 24)
- )
- (i32.const 24)
+ (i32.and
+ (get_local $4)
+ (i32.const 255)
)
)
(block
@@ -1944,20 +1941,17 @@
)
(if
(i32.ne
- (i32.load8_s
+ (i32.load8_u
(get_local $2)
)
- (i32.shr_s
- (i32.shl
- (tee_local $1
- (i32.and
- (get_local $1)
- (i32.const 255)
- )
+ (i32.and
+ (tee_local $1
+ (i32.and
+ (get_local $1)
+ (i32.const 255)
)
- (i32.const 24)
)
- (i32.const 24)
+ (i32.const 255)
)
)
(block
@@ -2038,15 +2032,12 @@
(loop $while-in5
(br_if $label$break$L8
(i32.eq
- (i32.load8_s
+ (i32.load8_u
(get_local $2)
)
- (i32.shr_s
- (i32.shl
- (get_local $1)
- (i32.const 24)
- )
- (i32.const 24)
+ (i32.and
+ (get_local $1)
+ (i32.const 255)
)
)
)
@@ -2513,16 +2504,13 @@
)
(br_if $__rjti$9
(i32.eqz
- (i32.shr_s
- (i32.shl
- (tee_local $7
- (i32.load8_s
- (get_local $5)
- )
+ (i32.and
+ (tee_local $7
+ (i32.load8_s
+ (get_local $5)
)
- (i32.const 24)
)
- (i32.const 24)
+ (i32.const 255)
)
)
)
@@ -2577,7 +2565,7 @@
(loop $while-in
(br_if $label$break$L12
(i32.ne
- (i32.load8_s offset=1
+ (i32.load8_u offset=1
(get_local $6)
)
(i32.const 37)
@@ -2591,7 +2579,7 @@
)
(br_if $while-in
(i32.eq
- (i32.load8_s
+ (i32.load8_u
(tee_local $6
(i32.add
(get_local $6)
@@ -2683,7 +2671,7 @@
(get_local $10)
(tee_local $11
(i32.eq
- (i32.load8_s offset=2
+ (i32.load8_u offset=2
(get_local $6)
)
(i32.const 36)
@@ -2828,12 +2816,9 @@
(block $do-once5
(if
(i32.eq
- (i32.shr_s
- (i32.shl
- (get_local $6)
- (i32.const 24)
- )
- (i32.const 24)
+ (i32.and
+ (get_local $6)
+ (i32.const 255)
)
(i32.const 42)
)
@@ -2861,7 +2846,7 @@
)
(br_if $__rjti$0
(i32.ne
- (i32.load8_s offset=2
+ (i32.load8_u offset=2
(get_local $10)
)
(i32.const 36)
@@ -3093,7 +3078,7 @@
(set_local $6
(if i32
(i32.eq
- (i32.load8_s
+ (i32.load8_u
(get_local $10)
)
(i32.const 46)
@@ -3101,21 +3086,18 @@
(block i32
(if
(i32.ne
- (i32.shr_s
- (i32.shl
- (tee_local $8
- (i32.load8_s
- (tee_local $6
- (i32.add
- (get_local $10)
- (i32.const 1)
- )
+ (i32.and
+ (tee_local $8
+ (i32.load8_s
+ (tee_local $6
+ (i32.add
+ (get_local $10)
+ (i32.const 1)
)
)
)
- (i32.const 24)
)
- (i32.const 24)
+ (i32.const 255)
)
(i32.const 42)
)
@@ -3214,7 +3196,7 @@
)
(if
(i32.eq
- (i32.load8_s offset=3
+ (i32.load8_u offset=3
(get_local $10)
)
(i32.const 36)
@@ -3384,12 +3366,9 @@
)
(if
(i32.eqz
- (i32.shr_s
- (i32.shl
- (get_local $13)
- (i32.const 24)
- )
- (i32.const 24)
+ (i32.and
+ (get_local $13)
+ (i32.const 255)
)
)
(block
@@ -3409,12 +3388,9 @@
(block $__rjti$2
(if
(i32.eq
- (i32.shr_s
- (i32.shl
- (get_local $13)
- (i32.const 24)
- )
- (i32.const 24)
+ (i32.and
+ (get_local $13)
+ (i32.const 255)
)
(i32.const 19)
)
@@ -4249,7 +4225,7 @@
)
(if f64
(i32.eq
- (i32.load8_s
+ (i32.load8_u
(get_local $9)
)
(i32.const 45)
@@ -5312,7 +5288,7 @@
(block
(br_if $do-once83
(i32.ne
- (i32.load8_s
+ (i32.load8_u
(get_local $31)
)
(i32.const 45)
diff --git a/test/emcc_hello_world.fromasm.imprecise b/test/emcc_hello_world.fromasm.imprecise
index 2cd23ba1d..2e35d2a56 100644
--- a/test/emcc_hello_world.fromasm.imprecise
+++ b/test/emcc_hello_world.fromasm.imprecise
@@ -325,7 +325,7 @@
)
)
(if
- (i32.load8_s
+ (i32.load8_u
(get_local $0)
)
(block
@@ -1468,7 +1468,7 @@
)
(if
(i32.ne
- (i32.load8_s
+ (i32.load8_u
(i32.add
(get_local $0)
(tee_local $6
@@ -1864,15 +1864,12 @@
(loop $while-in
(if
(i32.eq
- (i32.load8_s
+ (i32.load8_u
(get_local $2)
)
- (i32.shr_s
- (i32.shl
- (get_local $4)
- (i32.const 24)
- )
- (i32.const 24)
+ (i32.and
+ (get_local $4)
+ (i32.const 255)
)
)
(block
@@ -1941,20 +1938,17 @@
)
(if
(i32.ne
- (i32.load8_s
+ (i32.load8_u
(get_local $2)
)
- (i32.shr_s
- (i32.shl
- (tee_local $1
- (i32.and
- (get_local $1)
- (i32.const 255)
- )
+ (i32.and
+ (tee_local $1
+ (i32.and
+ (get_local $1)
+ (i32.const 255)
)
- (i32.const 24)
)
- (i32.const 24)
+ (i32.const 255)
)
)
(block
@@ -2035,15 +2029,12 @@
(loop $while-in5
(br_if $label$break$L8
(i32.eq
- (i32.load8_s
+ (i32.load8_u
(get_local $2)
)
- (i32.shr_s
- (i32.shl
- (get_local $1)
- (i32.const 24)
- )
- (i32.const 24)
+ (i32.and
+ (get_local $1)
+ (i32.const 255)
)
)
)
@@ -2456,16 +2447,13 @@
)
(br_if $__rjti$9
(i32.eqz
- (i32.shr_s
- (i32.shl
- (tee_local $7
- (i32.load8_s
- (get_local $5)
- )
+ (i32.and
+ (tee_local $7
+ (i32.load8_s
+ (get_local $5)
)
- (i32.const 24)
)
- (i32.const 24)
+ (i32.const 255)
)
)
)
@@ -2520,7 +2508,7 @@
(loop $while-in
(br_if $label$break$L12
(i32.ne
- (i32.load8_s offset=1
+ (i32.load8_u offset=1
(get_local $6)
)
(i32.const 37)
@@ -2534,7 +2522,7 @@
)
(br_if $while-in
(i32.eq
- (i32.load8_s
+ (i32.load8_u
(tee_local $6
(i32.add
(get_local $6)
@@ -2626,7 +2614,7 @@
(get_local $10)
(tee_local $11
(i32.eq
- (i32.load8_s offset=2
+ (i32.load8_u offset=2
(get_local $6)
)
(i32.const 36)
@@ -2771,12 +2759,9 @@
(block $do-once5
(if
(i32.eq
- (i32.shr_s
- (i32.shl
- (get_local $6)
- (i32.const 24)
- )
- (i32.const 24)
+ (i32.and
+ (get_local $6)
+ (i32.const 255)
)
(i32.const 42)
)
@@ -2804,7 +2789,7 @@
)
(br_if $__rjti$0
(i32.ne
- (i32.load8_s offset=2
+ (i32.load8_u offset=2
(get_local $10)
)
(i32.const 36)
@@ -3036,7 +3021,7 @@
(set_local $6
(if i32
(i32.eq
- (i32.load8_s
+ (i32.load8_u
(get_local $10)
)
(i32.const 46)
@@ -3044,21 +3029,18 @@
(block i32
(if
(i32.ne
- (i32.shr_s
- (i32.shl
- (tee_local $8
- (i32.load8_s
- (tee_local $6
- (i32.add
- (get_local $10)
- (i32.const 1)
- )
+ (i32.and
+ (tee_local $8
+ (i32.load8_s
+ (tee_local $6
+ (i32.add
+ (get_local $10)
+ (i32.const 1)
)
)
)
- (i32.const 24)
)
- (i32.const 24)
+ (i32.const 255)
)
(i32.const 42)
)
@@ -3157,7 +3139,7 @@
)
(if
(i32.eq
- (i32.load8_s offset=3
+ (i32.load8_u offset=3
(get_local $10)
)
(i32.const 36)
@@ -3327,12 +3309,9 @@
)
(if
(i32.eqz
- (i32.shr_s
- (i32.shl
- (get_local $13)
- (i32.const 24)
- )
- (i32.const 24)
+ (i32.and
+ (get_local $13)
+ (i32.const 255)
)
)
(block
@@ -3352,12 +3331,9 @@
(block $__rjti$2
(if
(i32.eq
- (i32.shr_s
- (i32.shl
- (get_local $13)
- (i32.const 24)
- )
- (i32.const 24)
+ (i32.and
+ (get_local $13)
+ (i32.const 255)
)
(i32.const 19)
)
@@ -4210,7 +4186,7 @@
(get_local $15)
)
(i32.eq
- (i32.load8_s
+ (i32.load8_u
(get_local $9)
)
(i32.const 45)
@@ -5249,7 +5225,7 @@
(block
(br_if $do-once83
(i32.ne
- (i32.load8_s
+ (i32.load8_u
(get_local $31)
)
(i32.const 45)
diff --git a/test/passes/optimize-instructions.txt b/test/passes/optimize-instructions.txt
index f959c3cd6..14f29a783 100644
--- a/test/passes/optimize-instructions.txt
+++ b/test/passes/optimize-instructions.txt
@@ -3,6 +3,7 @@
(type $1 (func))
(type $2 (func (result i32)))
(type $3 (func (param i32) (result i32)))
+ (type $4 (func (param i32 i32)))
(memory $0 0)
(export "load-off-2" (func $load-off-2))
(func $f (type $0) (param $i1 i32) (param $i2 i64)
@@ -176,7 +177,8 @@
)
)
(drop
- (i32.eqz
+ (i32.eq
+ (i32.const 0)
(i32.const 100)
)
)
@@ -515,4 +517,431 @@
)
)
)
+ (func $sign-ext (type $4) (param $0 i32) (param $1 i32)
+ (drop
+ (i32.eqz
+ (i32.and
+ (get_local $0)
+ (i32.const 255)
+ )
+ )
+ )
+ (drop
+ (i32.eqz
+ (i32.and
+ (get_local $0)
+ (i32.const 65535)
+ )
+ )
+ )
+ (drop
+ (i32.eqz
+ (i32.and
+ (get_local $0)
+ (i32.const 134217727)
+ )
+ )
+ )
+ (drop
+ (i32.eq
+ (i32.and
+ (get_local $0)
+ (i32.const 255)
+ )
+ (i32.const 100)
+ )
+ )
+ (drop
+ (i32.eq
+ (i32.and
+ (get_local $0)
+ (i32.const 255)
+ )
+ (i32.const 255)
+ )
+ )
+ (drop
+ (i32.eq
+ (i32.and
+ (get_local $0)
+ (i32.const 255)
+ )
+ (i32.and
+ (get_local $1)
+ (i32.const 255)
+ )
+ )
+ )
+ (drop
+ (i32.eq
+ (i32.and
+ (get_local $0)
+ (i32.const 65535)
+ )
+ (i32.and
+ (get_local $1)
+ (i32.const 65535)
+ )
+ )
+ )
+ (drop
+ (i32.eqz
+ (i32.shr_s
+ (i32.shl
+ (get_local $0)
+ (i32.const 24)
+ )
+ (i32.const 23)
+ )
+ )
+ )
+ (drop
+ (i32.eqz
+ (i32.shr_u
+ (i32.shl
+ (get_local $0)
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ )
+ (drop
+ (i32.lt_s
+ (i32.shr_s
+ (i32.shl
+ (get_local $0)
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ (i32.const 0)
+ )
+ )
+ )
+ (func $sign-ext-input (type $4) (param $0 i32) (param $1 i32)
+ (drop
+ (i32.const 100)
+ )
+ (drop
+ (i32.const 127)
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.const 128)
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (get_local $0)
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (unreachable)
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.div_s
+ (i32.const 1)
+ (i32.const 2)
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.and
+ (i32.const 127)
+ (i32.const 128)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.and
+ (i32.const 128)
+ (i32.const 129)
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.xor
+ (i32.const 127)
+ (i32.const 128)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.xor
+ (i32.const 128)
+ (i32.const 129)
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.or
+ (i32.const 127)
+ (i32.const 126)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.or
+ (i32.const 127)
+ (i32.const 128)
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.shl
+ (i32.const 32)
+ (i32.const 2)
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shl
+ (i32.const 32)
+ (i32.const 1)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.shl
+ (i32.const 32)
+ (i32.const 35)
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.shr_u
+ (i32.const 256)
+ (i32.const 1)
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_u
+ (i32.const 256)
+ (i32.const 2)
+ )
+ )
+ (drop
+ (i32.shr_u
+ (i32.const 128)
+ (i32.const 35)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.shr_s
+ (i32.const 256)
+ (i32.const 1)
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.const 256)
+ (i32.const 2)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.const 128)
+ (i32.const 35)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.shr_s
+ (i32.const -1)
+ (i32.const 32)
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.and
+ (i32.const -1)
+ (i32.const 2147483647)
+ )
+ (i32.const 32)
+ )
+ )
+ (drop
+ (i32.ne
+ (i32.const -1)
+ (i32.const -1)
+ )
+ )
+ (drop
+ (f32.le
+ (f32.const -1)
+ (f32.const -1)
+ )
+ )
+ (drop
+ (i32.clz
+ (i32.const 0)
+ )
+ )
+ (drop
+ (i32.shl
+ (i32.clz
+ (i32.const 0)
+ )
+ (i32.const 2)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.shl
+ (i32.clz
+ (i32.const 0)
+ )
+ (i32.const 3)
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.wrap/i64
+ (i64.clz
+ (i64.const 0)
+ )
+ )
+ )
+ (drop
+ (i32.shl
+ (i32.wrap/i64
+ (i64.clz
+ (i64.const 0)
+ )
+ )
+ (i32.const 1)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.shl
+ (i32.wrap/i64
+ (i64.clz
+ (i64.const 0)
+ )
+ )
+ (i32.const 2)
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.eqz
+ (i32.const -1)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.shr_u
+ (i32.wrap/i64
+ (i64.const -1)
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_u
+ (i32.wrap/i64
+ (i64.const -1)
+ )
+ (i32.const 25)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.shr_u
+ (i32.wrap/i64
+ (i64.extend_s/i32
+ (i32.const -1)
+ )
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_u
+ (i32.wrap/i64
+ (i64.extend_s/i32
+ (i32.const -1)
+ )
+ )
+ (i32.const 25)
+ )
+ )
+ )
)
diff --git a/test/passes/optimize-instructions.wast b/test/passes/optimize-instructions.wast
index 41ca48951..8eec3f3cd 100644
--- a/test/passes/optimize-instructions.wast
+++ b/test/passes/optimize-instructions.wast
@@ -192,6 +192,8 @@
)
)
)
+ ;; we handle only 0 in the right position, as we assume a const is there, and don't care about if
+ ;; both are consts here (precompute does that, so no need)
(drop
(i32.eq
(i32.const 100)
@@ -430,4 +432,586 @@
)
)
)
+ (func $sign-ext (param $0 i32) (param $1 i32)
+ ;; eq of sign-ext to const, can be a zext
+ (drop
+ (i32.eq
+ (i32.shr_s
+ (i32.shl
+ (get_local $0)
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ (i32.const 0)
+ )
+ )
+ (drop
+ (i32.eq
+ (i32.shr_s
+ (i32.shl
+ (get_local $0)
+ (i32.const 16)
+ )
+ (i32.const 16)
+ )
+ (i32.const 0)
+ )
+ )
+ (drop
+ (i32.eq
+ (i32.shr_s
+ (i32.shl
+ (get_local $0)
+ (i32.const 5) ;; weird size, but still valid
+ )
+ (i32.const 5)
+ )
+ (i32.const 0)
+ )
+ )
+ (drop
+ (i32.eq
+ (i32.shr_s
+ (i32.shl
+ (get_local $0)
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ (i32.const 100) ;; non-zero
+ )
+ )
+ (drop
+ (i32.eq
+ (i32.shr_s
+ (i32.shl
+ (get_local $0)
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ (i32.const 32767) ;; non-zero and bigger than the mask
+ )
+ )
+ ;; eq of two sign-ext, can both be a zext
+ (drop
+ (i32.eq
+ (i32.shr_s
+ (i32.shl
+ (get_local $0)
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ (i32.shr_s
+ (i32.shl
+ (get_local $1)
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ )
+ (drop
+ (i32.eq
+ (i32.shr_s
+ (i32.shl
+ (get_local $0)
+ (i32.const 16)
+ )
+ (i32.const 16)
+ )
+ (i32.shr_s
+ (i32.shl
+ (get_local $1)
+ (i32.const 16)
+ )
+ (i32.const 16)
+ )
+ )
+ )
+ ;; corner cases we should not opt
+ (drop
+ (i32.eq
+ (i32.shr_s
+ (i32.shl
+ (get_local $0)
+ (i32.const 24)
+ )
+ (i32.const 23) ;; different shift
+ )
+ (i32.const 0)
+ )
+ )
+ (drop
+ (i32.eq
+ (i32.shr_u ;; unsigned
+ (i32.shl
+ (get_local $0)
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ (i32.const 0)
+ )
+ )
+ (drop
+ (i32.lt_s ;; non-eq
+ (i32.shr_s
+ (i32.shl
+ (get_local $0)
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ (i32.const 0)
+ )
+ )
+ )
+ (func $sign-ext-input (param $0 i32) (param $1 i32)
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.const 100) ;; small!
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.const 127) ;; just small enough
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.const 128) ;; just too big
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (get-local $0) ;; who knows...
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (unreachable) ;; ignore
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.div_s ;; this could be optimizable in theory, but currently we don't look into adds etc.
+ (i32.const 1)
+ (i32.const 2)
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.and ;; takes the min, here it is ok
+ (i32.const 127)
+ (i32.const 128)
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.and ;; takes the min, here it is not
+ (i32.const 128)
+ (i32.const 129)
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.xor ;; takes the min, here it is ok
+ (i32.const 127)
+ (i32.const 128)
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.xor ;; takes the min, here it is not
+ (i32.const 128)
+ (i32.const 129)
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.or ;; takes the max, here it is ok
+ (i32.const 127)
+ (i32.const 126)
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.or ;; takes the max, here it is not
+ (i32.const 127)
+ (i32.const 128)
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.shl ;; adds, here it is too much
+ (i32.const 32)
+ (i32.const 2)
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.shl ;; adds, here it is ok
+ (i32.const 32)
+ (i32.const 1)
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.shl ;; adds, here it is too much and "overflows"
+ (i32.const 32)
+ (i32.const 35)
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.shr_u ;; subtracts, here it is still too much
+ (i32.const 256)
+ (i32.const 1)
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.shr_u ;; subtracts, here it is ok
+ (i32.const 256)
+ (i32.const 2)
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.shr_u ;; subtracts, here it "overflows"
+ (i32.const 128)
+ (i32.const 35)
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.shr_s ;; subtracts, here it is still too much
+ (i32.const 256)
+ (i32.const 1)
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.shr_s ;; subtracts, here it is ok
+ (i32.const 256)
+ (i32.const 2)
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.shr_s ;; subtracts, here it "overflows"
+ (i32.const 128)
+ (i32.const 35)
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.shr_s ;; subtracts, here there is a sign bit, so it stays 32 bits no matter how much we shift
+ (i32.const -1)
+ (i32.const 32)
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.shr_s ;; subtracts, here we mask out that sign bit
+ (i32.and
+ (i32.const -1)
+ (i32.const 2147483647)
+ )
+ (i32.const 32)
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.ne ;; 1 bit
+ (i32.const -1)
+ (i32.const -1)
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (f32.le
+ (f32.const -1)
+ (f32.const -1)
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.clz ;; assumed 5 bits
+ (i32.const 0)
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.shl
+ (i32.clz ;; assumed 5 bits
+ (i32.const 0)
+ )
+ (i32.const 2) ;; + 2, so 7
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.shl
+ (i32.clz ;; assumed 5 bits
+ (i32.const 0)
+ )
+ (i32.const 3) ;; + 3, so 8, too much
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.wrap/i64 ;; preserves 6
+ (i64.clz ;; assumed 6 bits
+ (i64.const 0)
+ )
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.shl
+ (i32.wrap/i64 ;; preserves 6
+ (i64.clz ;; assumed 6 bits
+ (i64.const 0)
+ )
+ )
+ (i32.const 1) ;; + 1, so 7
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.shl
+ (i32.wrap/i64 ;; preserves 6
+ (i64.clz ;; assumed 6 bits
+ (i64.const 0)
+ )
+ )
+ (i32.const 2) ;; + 2, so 8, too much
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.eqz ;; 1 bit
+ (i32.const -1)
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.shr_u
+ (i32.wrap/i64 ;; down to 32
+ (i64.const -1) ;; 64
+ )
+ (i32.const 24) ;; 32 - 24 = 8
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.shr_u
+ (i32.wrap/i64 ;; down to 32
+ (i64.const -1) ;; 64
+ )
+ (i32.const 25) ;; 32 - 25 = 7, ok
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.shr_u
+ (i32.wrap/i64 ;; stay 32
+ (i64.extend_s/i32
+ (i32.const -1)
+ )
+ )
+ (i32.const 24) ;; 32 - 24 = 8
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.shr_u
+ (i32.wrap/i64 ;; stay 32
+ (i64.extend_s/i32
+ (i32.const -1)
+ )
+ )
+ (i32.const 25) ;; 32 - 25 = 7, ok
+ )
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ )
)
diff --git a/test/passes/precompute.txt b/test/passes/precompute.txt
index e7fc6526f..af44d18d8 100644
--- a/test/passes/precompute.txt
+++ b/test/passes/precompute.txt
@@ -4,6 +4,9 @@
(type $2 (func))
(memory $0 0)
(func $x (type $0) (param $x i32)
+ (call $x
+ (i32.const 2300)
+ )
(nop)
(drop
(i32.add
diff --git a/test/passes/precompute.wast b/test/passes/precompute.wast
index b498d9df0..d5e91fb9d 100644
--- a/test/passes/precompute.wast
+++ b/test/passes/precompute.wast
@@ -2,6 +2,12 @@
(memory 0)
(type $0 (func (param i32)))
(func $x (type $0) (param $x i32)
+ (call $x
+ (i32.add
+ (i32.const 100)
+ (i32.const 2200)
+ )
+ )
(drop
(i32.add
(i32.const 1)