summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/wasm-builder.h10
-rw-r--r--test/lit/passes/coalesce-locals-gc.wast21
2 files changed, 25 insertions, 6 deletions
diff --git a/src/wasm-builder.h b/src/wasm-builder.h
index bb739af89..fabaac22a 100644
--- a/src/wasm-builder.h
+++ b/src/wasm-builder.h
@@ -1040,9 +1040,8 @@ public:
iff->condition = makeUnary(EqZInt32, iff->condition);
}
- // returns a replacement with the precise same type, and with
- // minimal contents. as a replacement, this may reuse the
- // input node
+ // Returns a replacement with the precise same type, and with minimal contents
+ // as best we can. As a replacement, this may reuse the input node.
template<typename T> Expression* replaceWithIdenticalType(T* curr) {
if (curr->type.isTuple()) {
return makeConstantExpression(Literal::makeZeros(curr->type));
@@ -1050,13 +1049,12 @@ public:
if (curr->type.isNullable()) {
return ExpressionManipulator::refNull(curr, curr->type);
}
- if (curr->type.isFunction()) {
+ if (curr->type.isFunction() || !curr->type.isBasic()) {
// We can't do any better, keep the original.
return curr;
}
Literal value;
// TODO: reuse node conditionally when possible for literals
- TODO_SINGLE_COMPOUND(curr->type);
switch (curr->type.getBasic()) {
case Type::i32:
value = Literal(int32_t(0));
@@ -1085,7 +1083,7 @@ public:
case Type::i31ref:
return makeI31New(makeConst(0));
case Type::dataref:
- WASM_UNREACHABLE("TODO: dataref");
+ return curr;
case Type::none:
return ExpressionManipulator::nop(curr);
case Type::unreachable:
diff --git a/test/lit/passes/coalesce-locals-gc.wast b/test/lit/passes/coalesce-locals-gc.wast
new file mode 100644
index 000000000..5bad35001
--- /dev/null
+++ b/test/lit/passes/coalesce-locals-gc.wast
@@ -0,0 +1,21 @@
+;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.
+;; RUN: wasm-opt %s --coalesce-locals -all -S -o - \
+;; RUN: | filecheck %s
+
+(module
+ ;; CHECK: (func $test-dead-get-non-nullable (param $0 dataref)
+ ;; CHECK-NEXT: (unreachable)
+ ;; CHECK-NEXT: (drop
+ ;; CHECK-NEXT: (local.get $0)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ (func $test-dead-get-non-nullable (param $func (ref data))
+ (unreachable)
+ (drop
+ ;; A useless get (that does not read from any set, or from the inputs to the
+ ;; function). Normally we replace such gets with nops as best we can, but in
+ ;; this case the type is non-nullable, so we must leave it alone.
+ (local.get $func)
+ )
+ )
+)