summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2017-03-21 18:25:18 -0700
committerGitHub <noreply@github.com>2017-03-21 18:25:18 -0700
commit7b71bb6b0d3966ce42b631d433c772e24d6e68be (patch)
treeb8392d1b5f1f827247d5afc48d2a93479683a860 /test
parentee501dfb427e675adee7790a6dbc7e90f9f5a4ca (diff)
downloadbinaryen-7b71bb6b0d3966ce42b631d433c772e24d6e68be.tar.gz
binaryen-7b71bb6b0d3966ce42b631d433c772e24d6e68be.tar.bz2
binaryen-7b71bb6b0d3966ce42b631d433c772e24d6e68be.zip
Fix comparisons of sign-extends to weird constants (#956)
* fix eq/ne of sign-ext with a constant, when the constant can never be equal to it as it has the effective sign bit but not the upper bits above it set, which the sign-ext would emit
Diffstat (limited to 'test')
-rw-r--r--test/passes/optimize-instructions.txt96
-rw-r--r--test/passes/optimize-instructions.wast124
2 files changed, 217 insertions, 3 deletions
diff --git a/test/passes/optimize-instructions.txt b/test/passes/optimize-instructions.txt
index 41d45d57f..03edc6e4c 100644
--- a/test/passes/optimize-instructions.txt
+++ b/test/passes/optimize-instructions.txt
@@ -541,7 +541,16 @@
(get_local $0)
(i32.const 255)
)
- (i32.const 255)
+ (i32.const -2147483648)
+ )
+ )
+ (drop
+ (i32.eq
+ (i32.and
+ (get_local $0)
+ (i32.const 255)
+ )
+ (i32.const 107)
)
)
(drop
@@ -1103,7 +1112,25 @@
(get_local $0)
(i32.const 255)
)
- (i32.const 232)
+ (i32.const -2147483648)
+ )
+ )
+ (drop
+ (i32.ne
+ (i32.and
+ (get_local $0)
+ (i32.const 255)
+ )
+ (i32.const -2147483648)
+ )
+ )
+ (drop
+ (i32.ne
+ (i32.and
+ (get_local $0)
+ (i32.const 255)
+ )
+ (i32.const 107)
)
)
(drop
@@ -1790,4 +1817,69 @@
)
)
)
+ (func $fuzz-comp-impossible (type $5) (param $x i32)
+ (drop
+ (i32.eq
+ (i32.and
+ (get_local $x)
+ (i32.const 65535)
+ )
+ (i32.const -2147483648)
+ )
+ )
+ (drop
+ (i32.eq
+ (i32.and
+ (get_local $x)
+ (i32.const 255)
+ )
+ (i32.const -2147483648)
+ )
+ )
+ (drop
+ (i32.eq
+ (i32.and
+ (get_local $x)
+ (i32.const 255)
+ )
+ (i32.const 127)
+ )
+ )
+ (drop
+ (i32.eq
+ (i32.and
+ (get_local $x)
+ (i32.const 255)
+ )
+ (i32.const -2147483648)
+ )
+ )
+ (drop
+ (i32.eq
+ (i32.and
+ (get_local $x)
+ (i32.const 255)
+ )
+ (i32.const -2147483648)
+ )
+ )
+ (drop
+ (i32.eq
+ (i32.and
+ (get_local $x)
+ (i32.const 255)
+ )
+ (i32.const -2147483648)
+ )
+ )
+ (drop
+ (i32.eq
+ (i32.and
+ (get_local $x)
+ (i32.const 255)
+ )
+ (i32.const 252)
+ )
+ )
+ )
)
diff --git a/test/passes/optimize-instructions.wast b/test/passes/optimize-instructions.wast
index 8ef6f67a5..eccbf1268 100644
--- a/test/passes/optimize-instructions.wast
+++ b/test/passes/optimize-instructions.wast
@@ -491,7 +491,19 @@
)
(i32.const 24)
)
- (i32.const 32767) ;; non-zero and bigger than the mask
+ (i32.const 32767) ;; non-zero and bigger than the mask, with sign bit
+ )
+ )
+ (drop
+ (i32.eq
+ (i32.shr_s
+ (i32.shl
+ (get_local $0)
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ (i32.const -149) ;; non-zero and bigger than the mask, without sign bit
)
)
;; eq of two sign-ext, can both be a zext
@@ -1370,6 +1382,30 @@
)
(i32.const 24)
)
+ (i32.const 64872) ;; no sign bit
+ )
+ )
+ (drop
+ (i32.ne
+ (i32.shr_s
+ (i32.shl
+ (get_local $0)
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ (i32.const -149) ;; no sign bit, not all ones
+ )
+ )
+ (drop
+ (i32.ne
+ (i32.shr_s
+ (i32.shl
+ (get_local $0)
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
(i32.const 111)
)
)
@@ -2181,4 +2217,90 @@
)
)
)
+ (func $fuzz-comp-impossible (param $x i32)
+ (drop
+ (i32.eq
+ (i32.shr_s
+ (i32.shl
+ (get_local $x)
+ (i32.const 16)
+ )
+ (i32.const 16)
+ )
+ (i32.const 65535) ;; impossible to be equal, the effective sign bit is set, but not the higher bits, which the sign-ext will set on the non-const value
+ )
+ )
+ (drop
+ (i32.eq
+ (i32.shr_s
+ (i32.shl
+ (get_local $x)
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ (i32.const 255)
+ )
+ )
+ (drop
+ (i32.eq
+ (i32.shr_s
+ (i32.shl
+ (get_local $x)
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ (i32.const 127) ;; safe
+ )
+ )
+ (drop
+ (i32.eq
+ (i32.shr_s
+ (i32.shl
+ (get_local $x)
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ (i32.const 128) ;; unsafe again
+ )
+ )
+ (drop
+ (i32.eq
+ (i32.shr_s
+ (i32.shl
+ (get_local $x)
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ (i32.const 4223) ;; more big bits, so sign bit though
+ )
+ )
+ (drop
+ (i32.eq
+ (i32.shr_s
+ (i32.shl
+ (get_local $x)
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ (i32.const 4224) ;; more big bits
+ )
+ )
+ (drop
+ (i32.eq
+ (i32.shr_s
+ (i32.shl
+ (get_local $x)
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ (i32.const -4) ;; safe even with more big bits, as they are all 1s
+ )
+ )
+ )
)