summaryrefslogtreecommitdiff
path: root/test/lit/passes/optimize-instructions-gc.wast
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2021-03-12 06:46:14 -0800
committerGitHub <noreply@github.com>2021-03-12 06:46:14 -0800
commitb98dce24827e006e9527ec50642ba77dfada662a (patch)
tree9f546c1e6b35e4d85c27c2cdb2fead9a5acefb09 /test/lit/passes/optimize-instructions-gc.wast
parent32be343d217781045572da274eb4d63f4ead86c5 (diff)
downloadbinaryen-b98dce24827e006e9527ec50642ba77dfada662a.tar.gz
binaryen-b98dce24827e006e9527ec50642ba77dfada662a.tar.bz2
binaryen-b98dce24827e006e9527ec50642ba77dfada662a.zip
[Wasm GC] Optimize struct stores like stores to memory, ignore unneeded bits (#3680)
When storing to an i8, we can ignore any higher bits, etc. Adds a getByteSize utility to Field to make this convenient.
Diffstat (limited to 'test/lit/passes/optimize-instructions-gc.wast')
-rw-r--r--test/lit/passes/optimize-instructions-gc.wast42
1 files changed, 42 insertions, 0 deletions
diff --git a/test/lit/passes/optimize-instructions-gc.wast b/test/lit/passes/optimize-instructions-gc.wast
index 31ecd0f63..6a0341856 100644
--- a/test/lit/passes/optimize-instructions-gc.wast
+++ b/test/lit/passes/optimize-instructions-gc.wast
@@ -3,6 +3,15 @@
;; RUN: | filecheck %s
(module
+ (import "env" "get-i32" (func $get-i32 (result i32)))
+
+ (type $struct (struct
+ (field $i8 (mut i8))
+ (field $i16 (mut i16))
+ (field $i32 (mut i32))
+ (field $i64 (mut i64))
+ ))
+
;; These functions test if an `if` with subtyped arms is correctly folded
;; 1. if its `ifTrue` and `ifFalse` arms are identical (can fold)
;; CHECK: (func $if-arms-subtype-fold (result anyref)
@@ -30,4 +39,37 @@
(ref.null func)
)
)
+
+ ;; Stored values automatically truncate unneeded bytes.
+ ;; CHECK: (func $store-trunc (param $x (ref null $struct))
+ ;; CHECK-NEXT: (struct.set $struct $i8
+ ;; CHECK-NEXT: (local.get $x)
+ ;; CHECK-NEXT: (i32.const 35)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (struct.set $struct $i16
+ ;; CHECK-NEXT: (local.get $x)
+ ;; CHECK-NEXT: (i32.const 9029)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (struct.set $struct $i8
+ ;; CHECK-NEXT: (local.get $x)
+ ;; CHECK-NEXT: (call $get-i32)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ (func $store-trunc (param $x (ref null $struct))
+ (struct.set $struct $i8
+ (local.get $x)
+ (i32.const 0x123) ;; data over 0xff is unnecessary
+ )
+ (struct.set $struct $i16
+ (local.get $x)
+ (i32.const 0x12345) ;; data over 0xffff is unnecessary
+ )
+ (struct.set $struct $i8
+ (local.get $x)
+ (i32.and ;; truncating bits using an and is unnecessary
+ (call $get-i32)
+ (i32.const 0xff)
+ )
+ )
+ )
)