summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2021-03-16 11:17:03 -0700
committerGitHub <noreply@github.com>2021-03-16 11:17:03 -0700
commit5fea332e1e6cf2b00334b617bb1bf399e9394592 (patch)
treefc3672c176024fcebae22155a432f014e7dacf31
parentc68c656798daa65f380176394993f301091078b1 (diff)
downloadbinaryen-5fea332e1e6cf2b00334b617bb1bf399e9394592.tar.gz
binaryen-5fea332e1e6cf2b00334b617bb1bf399e9394592.tar.bz2
binaryen-5fea332e1e6cf2b00334b617bb1bf399e9394592.zip
[Wasm GC] Optimize array.set stored values (#3690)
Same as we already do for struct.set.
-rw-r--r--src/passes/OptimizeInstructions.cpp7
-rw-r--r--test/lit/passes/optimize-instructions-gc.wast18
-rw-r--r--test/passes/Oz_fuzz-exec_all-features.txt2
3 files changed, 26 insertions, 1 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp
index 7f02eb283..7e6b00212 100644
--- a/src/passes/OptimizeInstructions.cpp
+++ b/src/passes/OptimizeInstructions.cpp
@@ -998,6 +998,13 @@ struct OptimizeInstructions
}
}
+ void visitArraySet(ArraySet* curr) {
+ if (curr->ref->type != Type::unreachable && curr->value->type.isInteger()) {
+ auto element = curr->ref->type.getHeapType().getArray().element;
+ optimizeStoredValue(curr->value, element.getByteSize());
+ }
+ }
+
Index getMaxBitsForLocal(LocalGet* get) {
// check what we know about the local
return localInfo[get->index].maxBits;
diff --git a/test/lit/passes/optimize-instructions-gc.wast b/test/lit/passes/optimize-instructions-gc.wast
index 6a0341856..96cd19583 100644
--- a/test/lit/passes/optimize-instructions-gc.wast
+++ b/test/lit/passes/optimize-instructions-gc.wast
@@ -12,6 +12,8 @@
(field $i64 (mut i64))
))
+ (type $array (array (mut i8)))
+
;; 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)
@@ -72,4 +74,20 @@
)
)
)
+
+ ;; Similar, but for arrays.
+ ;; CHECK: (func $store-trunc2 (param $x (ref null $array))
+ ;; CHECK-NEXT: (array.set $array
+ ;; CHECK-NEXT: (local.get $x)
+ ;; CHECK-NEXT: (i32.const 0)
+ ;; CHECK-NEXT: (i32.const 35)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ (func $store-trunc2 (param $x (ref null $array))
+ (array.set $array
+ (local.get $x)
+ (i32.const 0)
+ (i32.const 0x123) ;; data over 0xff is unnecessary
+ )
+ )
)
diff --git a/test/passes/Oz_fuzz-exec_all-features.txt b/test/passes/Oz_fuzz-exec_all-features.txt
index 377d936fd..54b204163 100644
--- a/test/passes/Oz_fuzz-exec_all-features.txt
+++ b/test/passes/Oz_fuzz-exec_all-features.txt
@@ -106,7 +106,7 @@
(array.set $bytes
(local.get $0)
(i32.const 10)
- (i32.const 65408)
+ (i32.const 128)
)
(call $log
(array.get_u $bytes