summaryrefslogtreecommitdiff
path: root/test/passes/pick-load-signs.wast
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2017-02-14 15:31:40 -0800
committerAlon Zakai (kripken) <alonzakai@gmail.com>2017-02-16 22:45:41 -0800
commit63230c06a8d98f4326de5d1a2ef6e908ed6a5945 (patch)
treee42ea7610317dacfa12d2d4d62e25c36cf863e7d /test/passes/pick-load-signs.wast
parent13f9265b9632f887e6c22a024c4c4d8ded187dd1 (diff)
downloadbinaryen-63230c06a8d98f4326de5d1a2ef6e908ed6a5945.tar.gz
binaryen-63230c06a8d98f4326de5d1a2ef6e908ed6a5945.tar.bz2
binaryen-63230c06a8d98f4326de5d1a2ef6e908ed6a5945.zip
finish PickLoadSigns pass
Diffstat (limited to 'test/passes/pick-load-signs.wast')
-rw-r--r--test/passes/pick-load-signs.wast260
1 files changed, 260 insertions, 0 deletions
diff --git a/test/passes/pick-load-signs.wast b/test/passes/pick-load-signs.wast
new file mode 100644
index 000000000..49105e497
--- /dev/null
+++ b/test/passes/pick-load-signs.wast
@@ -0,0 +1,260 @@
+(module
+ (func $a ;; load 8s, but use is 8u, so load should be signed
+ (local $y i32)
+ (set_local $y
+ (i32.load8_s
+ (i32.const 1024)
+ )
+ )
+ (drop
+ (i32.and
+ (get_local $y)
+ (i32.const 255)
+ )
+ )
+ )
+ (func $b ;; load 16s, but use is 16u, so load should be signed
+ (local $y i32)
+ (set_local $y
+ (i32.load16_s
+ (i32.const 1024)
+ )
+ )
+ (drop
+ (i32.and
+ (get_local $y)
+ (i32.const 65535)
+ )
+ )
+ )
+ (func $c ;; load 8u, keep
+ (local $y i32)
+ (set_local $y
+ (i32.load8_u
+ (i32.const 1024)
+ )
+ )
+ (drop
+ (i32.and
+ (get_local $y)
+ (i32.const 255)
+ )
+ )
+ )
+ (func $d ;; load 16u, keep
+ (local $y i32)
+ (set_local $y
+ (i32.load16_u
+ (i32.const 1024)
+ )
+ )
+ (drop
+ (i32.and
+ (get_local $y)
+ (i32.const 65535)
+ )
+ )
+ )
+ (func $one-of-each ;; prefer the signed, potential code removal is bigger
+ (local $y i32)
+ (set_local $y
+ (i32.load8_s
+ (i32.const 1024)
+ )
+ )
+ (drop
+ (i32.and
+ (get_local $y)
+ (i32.const 255)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (get_local $y)
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ )
+ (func $more-of-one ;; prefer the signed even if 2x more unsigned
+ (local $y i32)
+ (set_local $y
+ (i32.load8_s
+ (i32.const 1024)
+ )
+ )
+ (drop
+ (i32.and
+ (get_local $y)
+ (i32.const 255)
+ )
+ )
+ (drop
+ (i32.and
+ (get_local $y)
+ (i32.const 255)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (get_local $y)
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ )
+ (func $many-more-of-one ;; but not 3x
+ (local $y i32)
+ (set_local $y
+ (i32.load8_s
+ (i32.const 1024)
+ )
+ )
+ (drop
+ (i32.and
+ (get_local $y)
+ (i32.const 255)
+ )
+ )
+ (drop
+ (i32.and
+ (get_local $y)
+ (i32.const 255)
+ )
+ )
+ (drop
+ (i32.and
+ (get_local $y)
+ (i32.const 255)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (get_local $y)
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ )
+ (func $a-sign ;; load 8s, use is s, so keep
+ (local $y i32)
+ (set_local $y
+ (i32.load8_s
+ (i32.const 1024)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (get_local $y)
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ )
+ (func $multivar
+ (local $x i32)
+ (local $y i32)
+ (set_local $x
+ (i32.load8_s
+ (i32.const 1024)
+ )
+ )
+ (drop
+ (i32.and
+ (get_local $x)
+ (i32.const 255)
+ )
+ )
+ (set_local $y
+ (i32.load8_s
+ (i32.const 1024)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (get_local $y)
+ (i32.const 24)
+ )
+ (i32.const 24)
+ )
+ )
+ )
+ (func $corners
+ (local $y i32)
+ (drop
+ (i32.load8_s ;; not sent into a set_local
+ (i32.const 1024)
+ )
+ )
+ (drop
+ (i32.load8_u ;; not sent into a set_local
+ (i32.const 1024)
+ )
+ )
+ (set_local $y
+ (i32.const 1024) ;; not a load
+ )
+ )
+ (func $wrong-size ;; load 8s, but use is 16
+ (local $y i32)
+ (set_local $y
+ (i32.load8_s
+ (i32.const 1024)
+ )
+ )
+ (drop
+ (i32.and
+ (get_local $y)
+ (i32.const 65535)
+ )
+ )
+ )
+ (func $wrong-size_s ;; load 8s, but use is 16
+ (local $y i32)
+ (set_local $y
+ (i32.load8_u
+ (i32.const 1024)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (get_local $y)
+ (i32.const 16)
+ )
+ (i32.const 16)
+ )
+ )
+ )
+ (func $non-sign-or-unsigned-use
+ (local $y i32)
+ (set_local $y
+ (i32.load8_s
+ (i32.const 1024)
+ )
+ )
+ (drop
+ (i32.and
+ (get_local $y)
+ (i32.const 255)
+ )
+ )
+ (drop
+ (get_local $y)
+ )
+ )
+ (func $toplevel-load (result i32)
+ (i32.load8_s
+ (i32.const 1024)
+ )
+ )
+)