summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/literal.h8
-rw-r--r--src/wasm/literal.cpp3
-rw-r--r--test/lit/passes/rse-gc.wast49
3 files changed, 60 insertions, 0 deletions
diff --git a/src/literal.h b/src/literal.h
index 317839b72..9d7ac2222 100644
--- a/src/literal.h
+++ b/src/literal.h
@@ -769,6 +769,14 @@ template<> struct hash<wasm::Literal> {
wasm::rehash(digest, a.geti31(true));
return digest;
}
+ if (a.type.isString()) {
+ auto& values = a.getGCData()->values;
+ wasm::rehash(digest, values.size());
+ for (auto c : values) {
+ wasm::rehash(digest, c.getInteger());
+ }
+ return digest;
+ }
// other non-null reference type literals cannot represent concrete
// values, i.e. there is no concrete anyref or eqref other than null.
WASM_UNREACHABLE("unexpected type");
diff --git a/src/wasm/literal.cpp b/src/wasm/literal.cpp
index 016df2e18..2a7dd1bcf 100644
--- a/src/wasm/literal.cpp
+++ b/src/wasm/literal.cpp
@@ -432,6 +432,9 @@ bool Literal::operator==(const Literal& other) const {
assert(func.is() && other.func.is());
return func == other.func;
}
+ if (type.isString()) {
+ return gcData->values == other.gcData->values;
+ }
if (type.isData()) {
return gcData == other.gcData;
}
diff --git a/test/lit/passes/rse-gc.wast b/test/lit/passes/rse-gc.wast
index 66b8ee677..c74e92c5e 100644
--- a/test/lit/passes/rse-gc.wast
+++ b/test/lit/passes/rse-gc.wast
@@ -247,4 +247,53 @@
(local.get $nullable)
)
)
+
+ ;; CHECK: (func $string (type $none_=>_none)
+ ;; CHECK-NEXT: (local $s stringref)
+ ;; CHECK-NEXT: (local $t stringref)
+ ;; CHECK-NEXT: (drop
+ ;; CHECK-NEXT: (local.get $s)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (local.set $s
+ ;; CHECK-NEXT: (string.const "hello")
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (local.set $t
+ ;; CHECK-NEXT: (local.get $s)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (drop
+ ;; CHECK-NEXT: (local.get $s)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (local.set $t
+ ;; CHECK-NEXT: (string.const "world!")
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (local.set $t
+ ;; CHECK-NEXT: (local.get $s)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ (func $string
+ (local $s stringref)
+ (local $t stringref)
+ ;; This set is redundant (both are null).
+ (local.set $t
+ (local.get $s)
+ )
+ (local.set $s
+ (string.const "hello")
+ )
+ ;; This set is not (one is not null).
+ (local.set $t
+ (local.get $s)
+ )
+ ;; This set is redundant (both are "hello").
+ (local.set $t
+ (local.get $s)
+ )
+ (local.set $t
+ (string.const "world!")
+ )
+ ;; This set is not (one is "world!").
+ (local.set $t
+ (local.get $s)
+ )
+ )
)