diff --git a/src/passes/Heap2Local2.cpp b/src/passes/Heap2Local2.cpp index 1673574cac8..74aaa7d009d 100644 --- a/src/passes/Heap2Local2.cpp +++ b/src/passes/Heap2Local2.cpp @@ -20,14 +20,14 @@ // // Phase 1 builds a dataflow graph over reference expressions in a function, // collecting candidate StructNew, fixed-size ArrayNew, and ArrayNewFixed -// allocations alongside identity edges and escaping uses. +// allocations alongside identity and cast edges and escaping uses. // // Phase 2 solves a smallest fixed point over Flat origins (i.e. the // flat lattice of all allocation sites) across all candidate allocations // simultaneously: // - Top: unknown / nullable / multiple merged allocations. // - Val(a): definitely non-null reference to a single allocation `a`. -// - Bot: unreachable. +// - Bot: unreachable or statically trapping cast output. // // Phase 3 marks allocations escaped from escaping uses and identity-edge mixes // (Val(a) flowing into Top). @@ -111,10 +111,14 @@ struct AnalysisState { std::vector allocs; // Maps tracked reference-typed expressions to their dataflow NodeId. std::unordered_map exprNodes; + // Maps each NodeId back to its Expression* (nullptr for TopNode). + std::vector nodeExprs; // Current lattice value for each dataflow node, indexed by NodeId. std::vector origins; - // Directed edges (from, to) along which reference values flow unchanged. - std::vector> identityEdges; + // Directed dataflow edges (from, to) between tracked nodes. Edges into + // RefCast nodes trigger cast re-evaluation; all other edges propagate + // reference values unchanged. + std::vector> edges; // Nodes whose values flow into contexts that escape the function or alias // heap memory. std::vector escapingNodes; @@ -124,6 +128,7 @@ struct AnalysisState { // representing expressions absent from exprNodes that can never produce a // candidate allocation (e.g. call, global.get, struct.get, or ref.null). origins.push_back(originLattice.getTop()); + nodeExprs.push_back(nullptr); } NodeId getNode(Expression* curr) { @@ -132,6 +137,7 @@ struct AnalysisState { auto [it, inserted] = exprNodes.emplace(curr, NodeId(origins.size())); if (inserted) { origins.push_back(originLattice.getBottom()); + nodeExprs.push_back(curr); } return it->second; } @@ -143,34 +149,38 @@ struct AnalysisState { return it != exprNodes.end() ? it->second : TopNode; } + const Origin& getOrigin(Expression* curr) const { + return origins[getNodeOrTop(curr)]; + } + void join(Expression* curr, Origin val) { originLattice.join(origins[getNode(curr)], val); } void joinTop(Expression* curr) { join(curr, originLattice.getTop()); } - void addIdentityEdge(NodeId fromNode, NodeId toNode) { + void addEdge(NodeId fromNode, NodeId toNode) { if (fromNode == TopNode) { originLattice.join(origins[toNode], originLattice.getTop()); } else { - identityEdges.emplace_back(fromNode, toNode); + edges.emplace_back(fromNode, toNode); } } - void addIdentityEdge(Expression* from, NodeId toNode) { + void addEdge(Expression* from, NodeId toNode) { // Since we are building up the graph via a post-order traversal, we will // have visited a child node (i.e. `from`) before its parent (i.e. // `toNode`). If the child is not already in the graph, then it must be // something we can't analyze, so we represent it as Top. - addIdentityEdge(getNodeOrTop(from), toNode); + addEdge(getNodeOrTop(from), toNode); } - void addIdentityEdge(NodeId fromNode, Expression* to) { - addIdentityEdge(fromNode, getNode(to)); + void addEdge(NodeId fromNode, Expression* to) { + addEdge(fromNode, getNode(to)); } - void addIdentityEdge(Expression* from, Expression* to) { - addIdentityEdge(getNodeOrTop(from), getNode(to)); + void addEdge(Expression* from, Expression* to) { + addEdge(getNodeOrTop(from), getNode(to)); } void escapeIfRef(Expression* curr) { @@ -219,7 +229,7 @@ struct GraphBuilder state.joinTop(get); } else { assert(set->value->type.isRef() && "unexpected unreachable set"); - state.addIdentityEdge(set->value, get); + state.addEdge(set->value, get); } } } @@ -314,7 +324,7 @@ struct GraphBuilder if (curr->type.isRef()) { assert(!curr->list.empty()); if (curr->list.back()->type.isRef()) { - state.addIdentityEdge(curr->list.back(), curr); + state.addEdge(curr->list.back(), curr); } } } @@ -322,7 +332,7 @@ struct GraphBuilder void visitLoop(Loop* curr) { if (curr->type.isRef()) { if (curr->body->type.isRef()) { - state.addIdentityEdge(curr->body, curr); + state.addEdge(curr->body, curr); } } } @@ -332,10 +342,10 @@ struct GraphBuilder assert(curr->ifFalse); NodeId outNode = state.getNode(curr); if (curr->ifTrue->type.isRef()) { - state.addIdentityEdge(curr->ifTrue, outNode); + state.addEdge(curr->ifTrue, outNode); } if (curr->ifFalse->type.isRef()) { - state.addIdentityEdge(curr->ifFalse, outNode); + state.addEdge(curr->ifFalse, outNode); } } } @@ -345,8 +355,8 @@ struct GraphBuilder assert(curr->ifTrue->type.isRef()); assert(curr->ifFalse->type.isRef()); NodeId outNode = state.getNode(curr); - state.addIdentityEdge(curr->ifTrue, outNode); - state.addIdentityEdge(curr->ifFalse, outNode); + state.addEdge(curr->ifTrue, outNode); + state.addEdge(curr->ifFalse, outNode); } } @@ -356,11 +366,11 @@ struct GraphBuilder assert(target); assert(target->type.isRef()); NodeId valNode = state.getNodeOrTop(curr->value); - state.addIdentityEdge(valNode, target); + state.addEdge(valNode, target); // Reachable ref-typed br_if also returns its value (unconditional br has // unreachable type). if (curr->type.isRef()) { - state.addIdentityEdge(valNode, curr); + state.addEdge(valNode, curr); } } } @@ -372,7 +382,7 @@ struct GraphBuilder auto* target = findBreakTarget(name); assert(target); assert(target->type.isRef()); - state.addIdentityEdge(valNode, target); + state.addEdge(valNode, target); } } } @@ -384,7 +394,7 @@ struct GraphBuilder // fallthrough value flows to its parent expression via this identity // edge. if (curr->isTee() && curr->value->type.isRef()) { - state.addIdentityEdge(curr->value, curr); + state.addEdge(curr->value, curr); } } @@ -399,13 +409,39 @@ struct GraphBuilder if (curr->op == RefAsNonNull) { if (curr->type.isRef()) { assert(curr->value->type.isRef()); - state.addIdentityEdge(curr->value, curr); + state.addEdge(curr->value, curr); } } else { visitExpression(curr); } } + void visitRefCast(RefCast* curr) { + // Neither ref nor desc escapes through ref.cast{,_desc_eq}; if the cast + // is already unreachable, Optimizer will skip it. + if (curr->type.isRef()) { + assert(curr->ref->type.isRef()); + NodeId refNode = state.getNodeOrTop(curr->ref); + if (refNode == TopNode) { + // We already know this cast is not optimizable, so we don't need to + // consider it further. + return; + } + NodeId outNode = state.getNode(curr); + state.addEdge(refNode, outNode); + if (curr->desc) { + assert(curr->desc->type.isRef()); + NodeId descNode = state.getNodeOrTop(curr->desc); + if (descNode != TopNode) { + // Only add edges from tracked descriptors; a Top descriptor must + // not join Top into outNode because the cast result originates from + // ref. + state.addEdge(descNode, outNode); + } + } + } + } + // These instructions only inspect or consume their reference operands without // letting them escape; overriding them prevents visitExpression from marking // their reference children as escaping. @@ -446,11 +482,10 @@ struct GraphBuilder void computeOrigins(AnalysisState& state) { size_t numNodes = state.origins.size(); // Build a compressed-sparse-row (CSR) forward-adjacency table from - // state.identityEdges: first count outgoing edges per node and compute prefix - // sums in outOffsets so node u's targets live in [outOffsets[u], - // outOffsets[u + 1]). + // state.edges: first count outgoing edges per node and compute prefix sums in + // outOffsets so node u's targets live in [outOffsets[u], outOffsets[u + 1]). std::vector outOffsets(numNodes + 1, 0); - for (const auto& [u, v] : state.identityEdges) { + for (const auto& [u, v] : state.edges) { ++outOffsets[u + 1]; } for (size_t u = 0; u < numNodes; ++u) { @@ -460,14 +495,14 @@ void computeOrigins(AnalysisState& state) { // at outOffsets[u] and advances as targets of u are written, tracking the // next slot to fill (i.e. outOffsets[u] plus the number of targets populated // for u so far). - std::vector outTargets(state.identityEdges.size()); + std::vector outTargets(state.edges.size()); std::vector nextTargetIdx(outOffsets.begin(), outOffsets.begin() + numNodes); - for (const auto& [u, v] : state.identityEdges) { + for (const auto& [u, v] : state.edges) { outTargets[nextTargetIdx[u]++] = v; } - // Skip sink nodes that have no outgoing identity edges to propagate into. + // Skip sink nodes that have no outgoing edges to propagate into. std::vector inWorklist(numNodes, false); std::vector worklist; auto pushNode = [&](NodeId u) { @@ -494,7 +529,25 @@ void computeOrigins(AnalysisState& state) { Origin uOrigin = state.origins[u]; for (NodeId i = outOffsets[u], end = outOffsets[u + 1]; i < end; ++i) { NodeId v = outTargets[i]; - if (state.originLattice.join(state.origins[v], uOrigin)) { + Origin out = uOrigin; + if (auto* cast = state.nodeExprs[v]->dynCast()) { + // The cast flows through the reference value, unless we know it will + // fail, in which case we don't need to update the output at all. + out = state.getOrigin(cast->ref); + // Check failure due to missing descriptor. + // TODO: Consider the specific descriptor allocation once we can do + // better than always considering it to have escaped. + if (cast->desc && state.getOrigin(cast->desc).isBottom()) { + continue; + } + // Check failure due to type mismatch. + if (const auto* alloc = out.getVal()) { + if (!Type::isSubType(state.allocs[*alloc].expr->type, cast->type)) { + continue; + } + } + } + if (state.originLattice.join(state.origins[v], out)) { pushNode(v); } } @@ -512,7 +565,12 @@ bool computeEscapes(AnalysisState& state) { // Mixing check: if an allocation flows into an identity edge whose target // became Top (e.g. mixed with null or another allocation), mark it escaped. - for (const auto& [u, v] : state.identityEdges) { + // Edges into RefCast nodes are excluded because a descriptor operand does not + // flow to the cast's output, so RefCast can never cause mixing. + for (const auto& [u, v] : state.edges) { + if (state.nodeExprs[v]->is()) { + continue; + } if (const auto* alloc = state.origins[u].getVal()) { if (state.origins[v].isTop()) { state.allocs[*alloc].escaped = true; @@ -768,6 +826,91 @@ struct Optimizer : public PostWalker { } } + void visitRefCast(RefCast* curr) { + if (curr->type == Type::unreachable) { + return; + } + auto refAlloc = getOptimizedAlloc(curr->ref); + auto descAlloc = curr->desc ? getOptimizedAlloc(curr->desc) : std::nullopt; + if (!refAlloc && !descAlloc) { + return; + } + + auto descTrap = [&]() { + assert(curr->desc); + replaceCurrent(builder.makeBlock({builder.makeDrop(curr->ref), + builder.makeDrop(curr->desc), + builder.makeUnreachable()})); + }; + + if (refAlloc && descAlloc) { + // An allocation's descriptor is currently always marked as escaping, so a + // non-escaping `desc` cannot match `ref`'s descriptor, and `ref` is + // non-null, so the cast always traps. + descTrap(); + return; + } + + if (refAlloc) { + const auto& info = state.allocs[*refAlloc]; + if (!curr->desc) { + // Without a descriptor operand, the cast depends only on the static + // type of the non-null allocation. + if (Type::isSubType(info.expr->type, curr->type)) { + replaceCurrent(curr->ref); + } else { + replaceCurrent(builder.makeSequence(builder.makeDrop(curr->ref), + builder.makeUnreachable())); + } + return; + } + // `ref` is an optimized allocation while `desc` is not optimized. If + // origin propagation left the cast output Bot (either because the target + // type is incompatible or `desc` never produces a value), fold to a trap; + // otherwise check `desc` against the allocation's stored descriptor local + // at runtime. + auto outIt = state.exprNodes.find(curr); + assert(outIt != state.exprNodes.end()); + if (state.origins[outIt->second].isBottom()) { + descTrap(); + return; + } + assert(Type::isSubType(info.expr->type, curr->type)); + assert(info.getDescHeapType().has_value()); + replaceCurrent(builder.makeSequence( + builder.makeDrop(curr->ref), + builder.makeIf( + builder.makeRefEq( + curr->desc, + builder.makeLocalGet(*info.descLocal, info.getDescLocalType())), + makeOptimizedNull(*refAlloc), + builder.makeUnreachable()))); + return; + } + + assert(descAlloc); + // `desc` is an optimized non-escaping allocation and `ref` is not + // optimized, so no non-null `ref` can have `desc` as its descriptor. A + // nullable cast can still succeed if `ref` is null, unless `curr->ref` was + // already rewritten to unreachable earlier in the post-order walk (before + // ReFinalize updates `curr->type`). + if (curr->type.isNullableRef() && curr->ref->type != Type::unreachable) { + // Stash `ref` in a scratch local before evaluating `desc` to preserve + // operand evaluation order while keeping only a null check on `ref`. + Type refType = curr->ref->type; + Index scratch = builder.addVar(func, refType); + replaceCurrent( + builder.makeBlock({builder.makeLocalSet(scratch, curr->ref), + builder.makeDrop(curr->desc), + curr})); + curr->desc = nullptr; + curr->type = curr->type.with(curr->type.getHeapType().getBottom()); + curr->ref = builder.makeLocalGet(scratch, refType); + return; + } + descTrap(); + } + void visitRefGetDesc(RefGetDesc* curr) { if (auto alloc = getOptimizedAlloc(curr->ref)) { const auto& info = state.allocs[*alloc]; diff --git a/test/lit/passes/heap2local-desc.wast b/test/lit/passes/heap2local-desc.wast index d99a6c35bc9..11125af99c9 100644 --- a/test/lit/passes/heap2local-desc.wast +++ b/test/lit/passes/heap2local-desc.wast @@ -54,9 +54,25 @@ ;; CHECK: (type $14 (func (param (ref null (exact $chain-descriptor))))) - ;; CHECK: (type $15 (func (result (ref (exact $super))))) + ;; CHECK: (type $15 (func (result anyref))) - ;; CHECK: (type $16 (func (result (ref (exact $super.desc))))) + ;; CHECK: (type $16 (func (result (ref null (exact $super.desc))))) + + ;; CHECK: (type $17 (func (result (ref (exact $super))))) + + ;; CHECK: (type $18 (func (result (ref (exact $super.desc))))) + + ;; CHECK: (type $19 (func (param (ref (exact $super.desc))) (result (ref (exact $super))))) + + ;; CHECK: (type $20 (func (param (ref (exact $sub.desc))))) + + ;; CHECK: (type $21 (func (param i32) (result eqref))) + + ;; CHECK: (type $22 (func (param (ref null (exact $super)) (ref null (exact $super.desc))))) + + ;; CHECK: (type $23 (func (param (ref (exact $sub.desc)) (ref null $super.desc)))) + + ;; CHECK: (type $24 (func (param (ref (exact $sub.desc)) (ref null (exact $super.desc))) (result (ref (exact $super))))) ;; CHECK: (import "" "" (func $effect (type $10))) ;; HP2L2: (type $10 (func)) @@ -69,12 +85,34 @@ ;; HP2L2: (type $14 (func (param (ref null (exact $chain-descriptor))))) - ;; HP2L2: (type $15 (func (result (ref (exact $super))))) + ;; HP2L2: (type $15 (func (result anyref))) + + ;; HP2L2: (type $16 (func (result (ref null (exact $super.desc))))) + + ;; HP2L2: (type $17 (func (result (ref (exact $super))))) + + ;; HP2L2: (type $18 (func (result (ref (exact $super.desc))))) + + ;; HP2L2: (type $19 (func (param (ref (exact $super.desc))) (result (ref (exact $super))))) + + ;; HP2L2: (type $20 (func (param (ref (exact $sub.desc))))) + + ;; HP2L2: (type $21 (func (param i32) (result eqref))) + + ;; HP2L2: (type $22 (func (param (ref null (exact $super)) (ref null (exact $super.desc))))) + + ;; HP2L2: (type $23 (func (param (ref (exact $sub.desc)) (ref null $super.desc)))) - ;; HP2L2: (type $16 (func (result (ref (exact $super.desc))))) + ;; HP2L2: (type $24 (func (param (ref (exact $sub.desc)) (ref null (exact $super.desc))) (result (ref (exact $super))))) ;; HP2L2: (import "" "" (func $effect (type $10))) (import "" "" (func $effect)) + ;; CHECK: (import "" "any" (func $import-any (type $15) (result anyref))) + ;; HP2L2: (import "" "any" (func $import-any (type $15) (result anyref))) + (import "" "any" (func $import-any (result anyref))) + ;; CHECK: (import "" "desc" (func $import-desc (type $16) (result (ref null (exact $super.desc))))) + ;; HP2L2: (import "" "desc" (func $import-desc (type $16) (result (ref null (exact $super.desc))))) + (import "" "desc" (func $import-desc (result (ref null (exact $super.desc))))) ;; CHECK: (global $desc (ref null (exact $descriptor)) (ref.null none)) ;; HP2L2: (global $desc (ref null (exact $descriptor)) (ref.null none)) @@ -434,15 +472,38 @@ ;; CHECK-NEXT: ) ;; HP2L2: (func $cast-desc-eq-success (type $10) ;; HP2L2-NEXT: (local $desc (ref null (exact $super.desc))) + ;; HP2L2-NEXT: (local $1 (ref (exact $super.desc))) + ;; HP2L2-NEXT: (local $2 (ref (exact $super.desc))) ;; HP2L2-NEXT: (local.set $desc ;; HP2L2-NEXT: (struct.new_default $super.desc) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: (drop - ;; HP2L2-NEXT: (ref.cast_desc_eq (ref (exact $super)) - ;; HP2L2-NEXT: (struct.new_default_desc $super - ;; HP2L2-NEXT: (local.get $desc) + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (local.set $2 + ;; HP2L2-NEXT: (ref.as_non_null + ;; HP2L2-NEXT: (local.get $desc) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (local.set $1 + ;; HP2L2-NEXT: (local.get $2) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (if (result nullref) + ;; HP2L2-NEXT: (ref.eq + ;; HP2L2-NEXT: (local.get $desc) + ;; HP2L2-NEXT: (local.get $1) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (then + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (else + ;; HP2L2-NEXT: (unreachable) + ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) - ;; HP2L2-NEXT: (local.get $desc) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) @@ -493,12 +554,33 @@ ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; HP2L2: (func $cast-desc-eq-fail (type $11) (param $desc (ref null (exact $super.desc))) + ;; HP2L2-NEXT: (local $1 (ref (exact $super.desc))) + ;; HP2L2-NEXT: (local $2 (ref (exact $super.desc))) ;; HP2L2-NEXT: (drop - ;; HP2L2-NEXT: (ref.cast_desc_eq (ref (exact $super)) - ;; HP2L2-NEXT: (struct.new_default_desc $super - ;; HP2L2-NEXT: (struct.new_default $super.desc) + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (local.set $2 + ;; HP2L2-NEXT: (struct.new_default $super.desc) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (local.set $1 + ;; HP2L2-NEXT: (local.get $2) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (if (result nullref) + ;; HP2L2-NEXT: (ref.eq + ;; HP2L2-NEXT: (local.get $desc) + ;; HP2L2-NEXT: (local.get $1) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (then + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (else + ;; HP2L2-NEXT: (unreachable) + ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) - ;; HP2L2-NEXT: (local.get $desc) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) @@ -554,12 +636,29 @@ ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; HP2L2: (func $cast-desc-eq-fail-reverse (type $11) (param $desc (ref null (exact $super.desc))) + ;; HP2L2-NEXT: (local $1 (ref (exact $super.desc))) + ;; HP2L2-NEXT: (local $2 (ref (exact $super.desc))) ;; HP2L2-NEXT: (drop - ;; HP2L2-NEXT: (ref.cast_desc_eq (ref (exact $super)) - ;; HP2L2-NEXT: (struct.new_default_desc $super - ;; HP2L2-NEXT: (local.get $desc) + ;; HP2L2-NEXT: (block + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (local.set $2 + ;; HP2L2-NEXT: (ref.as_non_null + ;; HP2L2-NEXT: (local.get $desc) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (local.set $1 + ;; HP2L2-NEXT: (local.get $2) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) - ;; HP2L2-NEXT: (struct.new_default $super.desc) + ;; HP2L2-NEXT: (unreachable) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) @@ -595,9 +694,16 @@ ;; CHECK-NEXT: ) ;; HP2L2: (func $cast-desc-eq-fail-param (type $12) (param $ref (ref null (exact $super))) ;; HP2L2-NEXT: (drop - ;; HP2L2-NEXT: (ref.cast_desc_eq (ref (exact $super)) - ;; HP2L2-NEXT: (local.get $ref) - ;; HP2L2-NEXT: (struct.new_default $super.desc) + ;; HP2L2-NEXT: (block + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (local.get $ref) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (unreachable) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) @@ -635,15 +741,22 @@ ;; CHECK-NEXT: ) ;; HP2L2: (func $cast-desc-eq-fail-param-effect (type $12) (param $ref (ref null (exact $super))) ;; HP2L2-NEXT: (drop - ;; HP2L2-NEXT: (ref.cast_desc_eq (ref (exact $super)) - ;; HP2L2-NEXT: (block (result (ref null (exact $super))) - ;; HP2L2-NEXT: (call $effect) - ;; HP2L2-NEXT: (local.get $ref) + ;; HP2L2-NEXT: (block + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result (ref null (exact $super))) + ;; HP2L2-NEXT: (call $effect) + ;; HP2L2-NEXT: (local.get $ref) + ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) - ;; HP2L2-NEXT: (block (result (ref (exact $super.desc))) - ;; HP2L2-NEXT: (call $effect) - ;; HP2L2-NEXT: (struct.new_default $super.desc) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (call $effect) + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (unreachable) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) @@ -682,10 +795,20 @@ ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; HP2L2: (func $cast-desc-eq-fail-param-nullable (type $12) (param $ref (ref null (exact $super))) + ;; HP2L2-NEXT: (local $1 (ref null (exact $super))) ;; HP2L2-NEXT: (drop - ;; HP2L2-NEXT: (ref.cast_desc_eq (ref null (exact $super)) - ;; HP2L2-NEXT: (local.get $ref) - ;; HP2L2-NEXT: (struct.new_default $super.desc) + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (local.set $1 + ;; HP2L2-NEXT: (local.get $ref) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (ref.cast nullref + ;; HP2L2-NEXT: (local.get $1) + ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) @@ -724,15 +847,25 @@ ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; HP2L2: (func $cast-desc-eq-fail-param-nullable-effect (type $12) (param $ref (ref null (exact $super))) + ;; HP2L2-NEXT: (local $1 (ref null (exact $super))) ;; HP2L2-NEXT: (drop - ;; HP2L2-NEXT: (ref.cast_desc_eq (ref null (exact $super)) - ;; HP2L2-NEXT: (block (result (ref null (exact $super))) - ;; HP2L2-NEXT: (call $effect) - ;; HP2L2-NEXT: (local.get $ref) + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (local.set $1 + ;; HP2L2-NEXT: (block (result (ref null (exact $super))) + ;; HP2L2-NEXT: (call $effect) + ;; HP2L2-NEXT: (local.get $ref) + ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) - ;; HP2L2-NEXT: (block (result (ref (exact $super.desc))) - ;; HP2L2-NEXT: (call $effect) - ;; HP2L2-NEXT: (struct.new_default $super.desc) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (call $effect) + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (ref.cast nullref + ;; HP2L2-NEXT: (local.get $1) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) @@ -777,13 +910,21 @@ ;; HP2L2: (func $cast-desc-eq-fail-became-unreachable-nullable (type $10) ;; HP2L2-NEXT: (local $desc (ref null (exact $super.desc))) ;; HP2L2-NEXT: (drop - ;; HP2L2-NEXT: (ref.cast_desc_eq (ref null (exact $super)) - ;; HP2L2-NEXT: (ref.cast nullref - ;; HP2L2-NEXT: (local.tee $desc - ;; HP2L2-NEXT: (struct.new_default $super.desc) + ;; HP2L2-NEXT: (block + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (unreachable) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) - ;; HP2L2-NEXT: (local.get $desc) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (unreachable) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) @@ -821,9 +962,16 @@ ;; CHECK-NEXT: ) ;; HP2L2: (func $cast-no-desc (type $11) (param $desc (ref null (exact $super.desc))) ;; HP2L2-NEXT: (drop - ;; HP2L2-NEXT: (ref.cast_desc_eq (ref (exact $super)) - ;; HP2L2-NEXT: (struct.new_default $no-desc) - ;; HP2L2-NEXT: (local.get $desc) + ;; HP2L2-NEXT: (block + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (local.get $desc) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (unreachable) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) @@ -860,15 +1008,22 @@ ;; CHECK-NEXT: ) ;; HP2L2: (func $cast-no-desc-effect (type $11) (param $desc (ref null (exact $super.desc))) ;; HP2L2-NEXT: (drop - ;; HP2L2-NEXT: (ref.cast_desc_eq (ref (exact $super)) - ;; HP2L2-NEXT: (block (result (ref (exact $no-desc))) - ;; HP2L2-NEXT: (call $effect) - ;; HP2L2-NEXT: (struct.new_default $no-desc) + ;; HP2L2-NEXT: (block + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (call $effect) + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) - ;; HP2L2-NEXT: (block (result (ref null (exact $super.desc))) - ;; HP2L2-NEXT: (call $effect) - ;; HP2L2-NEXT: (local.get $desc) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result (ref null (exact $super.desc))) + ;; HP2L2-NEXT: (call $effect) + ;; HP2L2-NEXT: (local.get $desc) + ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (unreachable) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) @@ -905,9 +1060,16 @@ ;; CHECK-NEXT: ) ;; HP2L2: (func $cast-no-desc-nullable (type $11) (param $desc (ref null (exact $super.desc))) ;; HP2L2-NEXT: (drop - ;; HP2L2-NEXT: (ref.cast_desc_eq (ref (exact $super)) - ;; HP2L2-NEXT: (struct.new_default $no-desc) - ;; HP2L2-NEXT: (local.get $desc) + ;; HP2L2-NEXT: (block + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (local.get $desc) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (unreachable) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) @@ -946,15 +1108,22 @@ ;; CHECK-NEXT: ) ;; HP2L2: (func $cast-no-desc-nullable-effect (type $11) (param $desc (ref null (exact $super.desc))) ;; HP2L2-NEXT: (drop - ;; HP2L2-NEXT: (ref.cast_desc_eq (ref (exact $super)) - ;; HP2L2-NEXT: (block (result (ref (exact $no-desc))) - ;; HP2L2-NEXT: (call $effect) - ;; HP2L2-NEXT: (struct.new_default $no-desc) + ;; HP2L2-NEXT: (block + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (call $effect) + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) - ;; HP2L2-NEXT: (block (result (ref null (exact $super.desc))) - ;; HP2L2-NEXT: (call $effect) - ;; HP2L2-NEXT: (local.get $desc) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result (ref null (exact $super.desc))) + ;; HP2L2-NEXT: (call $effect) + ;; HP2L2-NEXT: (local.get $desc) + ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (unreachable) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) @@ -1005,15 +1174,30 @@ ;; CHECK-NEXT: ) ;; HP2L2: (func $cast-desc-eq-and-ref (type $14) (param $desc (ref null (exact $chain-descriptor))) ;; HP2L2-NEXT: (local $middle (ref null (exact $chain-middle))) - ;; HP2L2-NEXT: (local.set $middle - ;; HP2L2-NEXT: (struct.new_default_desc $chain-middle - ;; HP2L2-NEXT: (local.get $desc) + ;; HP2L2-NEXT: (local $2 (ref (exact $chain-descriptor))) + ;; HP2L2-NEXT: (local $3 (ref (exact $chain-descriptor))) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (local.set $3 + ;; HP2L2-NEXT: (ref.as_non_null + ;; HP2L2-NEXT: (local.get $desc) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (local.set $2 + ;; HP2L2-NEXT: (local.get $3) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (ref.null none) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: (drop - ;; HP2L2-NEXT: (ref.cast_desc_eq (ref (exact $chain-described)) - ;; HP2L2-NEXT: (local.get $middle) - ;; HP2L2-NEXT: (local.get $middle) + ;; HP2L2-NEXT: (block + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (unreachable) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) @@ -1067,15 +1251,30 @@ ;; CHECK-NEXT: ) ;; HP2L2: (func $cast-desc-eq-and-ref-nullable (type $14) (param $desc (ref null (exact $chain-descriptor))) ;; HP2L2-NEXT: (local $middle (ref null (exact $chain-middle))) - ;; HP2L2-NEXT: (local.set $middle - ;; HP2L2-NEXT: (struct.new_default_desc $chain-middle - ;; HP2L2-NEXT: (local.get $desc) + ;; HP2L2-NEXT: (local $2 (ref (exact $chain-descriptor))) + ;; HP2L2-NEXT: (local $3 (ref (exact $chain-descriptor))) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (local.set $3 + ;; HP2L2-NEXT: (ref.as_non_null + ;; HP2L2-NEXT: (local.get $desc) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (local.set $2 + ;; HP2L2-NEXT: (local.get $3) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (ref.null none) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: (drop - ;; HP2L2-NEXT: (ref.cast_desc_eq (ref null (exact $chain-described)) - ;; HP2L2-NEXT: (local.get $middle) - ;; HP2L2-NEXT: (local.get $middle) + ;; HP2L2-NEXT: (block + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (unreachable) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) @@ -1114,11 +1313,16 @@ ;; HP2L2: (func $cast-desc-eq-and-ref-tee (type $10) ;; HP2L2-NEXT: (local $desc (ref null (exact $super.desc))) ;; HP2L2-NEXT: (drop - ;; HP2L2-NEXT: (ref.cast_desc_eq (ref (exact $super)) - ;; HP2L2-NEXT: (local.tee $desc - ;; HP2L2-NEXT: (struct.new_default $super.desc) + ;; HP2L2-NEXT: (block + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) - ;; HP2L2-NEXT: (local.get $desc) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (unreachable) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) @@ -1155,11 +1359,16 @@ ;; HP2L2: (func $cast-desc-eq-and-ref-tee-nullable (type $10) ;; HP2L2-NEXT: (local $desc (ref null (exact $super.desc))) ;; HP2L2-NEXT: (drop - ;; HP2L2-NEXT: (ref.cast_desc_eq (ref null (exact $super)) - ;; HP2L2-NEXT: (local.tee $desc - ;; HP2L2-NEXT: (struct.new_default $super.desc) + ;; HP2L2-NEXT: (block + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) - ;; HP2L2-NEXT: (local.get $desc) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (unreachable) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) @@ -1176,7 +1385,7 @@ ) ) - ;; CHECK: (func $cast-desc-eq-stale-parent (type $15) (result (ref (exact $super))) + ;; CHECK: (func $cast-desc-eq-stale-parent (type $17) (result (ref (exact $super))) ;; CHECK-NEXT: (drop ;; CHECK-NEXT: (block (result nullref) ;; CHECK-NEXT: (ref.null none) @@ -1192,14 +1401,21 @@ ;; CHECK-NEXT: ) ;; CHECK-NEXT: (unreachable) ;; CHECK-NEXT: ) - ;; HP2L2: (func $cast-desc-eq-stale-parent (type $15) (result (ref (exact $super))) - ;; HP2L2-NEXT: (ref.cast_desc_eq (ref (exact $super)) - ;; HP2L2-NEXT: (struct.new_default $no-desc) - ;; HP2L2-NEXT: (block (result (ref (exact $super.desc))) + ;; HP2L2: (func $cast-desc-eq-stale-parent (type $17) (result (ref (exact $super))) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) ;; HP2L2-NEXT: (call $effect) - ;; HP2L2-NEXT: (struct.new_default $super.desc) + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (unreachable) ;; HP2L2-NEXT: ) (func $cast-desc-eq-stale-parent (result (ref (exact $super))) (ref.cast_desc_eq (ref (exact $super)) @@ -1215,7 +1431,7 @@ ) ) - ;; CHECK: (func $cast-desc-eq-stale-parent-escape (type $16) (result (ref (exact $super.desc))) + ;; CHECK: (func $cast-desc-eq-stale-parent-escape (type $18) (result (ref (exact $super.desc))) ;; CHECK-NEXT: (local $desc (ref null (exact $super.desc))) ;; CHECK-NEXT: (drop ;; CHECK-NEXT: (block @@ -1236,14 +1452,21 @@ ;; CHECK-NEXT: (local.get $desc) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) - ;; HP2L2: (func $cast-desc-eq-stale-parent-escape (type $16) (result (ref (exact $super.desc))) + ;; HP2L2: (func $cast-desc-eq-stale-parent-escape (type $18) (result (ref (exact $super.desc))) ;; HP2L2-NEXT: (local $desc (ref (exact $super.desc))) ;; HP2L2-NEXT: (drop - ;; HP2L2-NEXT: (ref.cast_desc_eq (ref (exact $super)) - ;; HP2L2-NEXT: (struct.new_default $no-desc) - ;; HP2L2-NEXT: (local.tee $desc - ;; HP2L2-NEXT: (struct.new_default $super.desc) + ;; HP2L2-NEXT: (block + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (local.tee $desc + ;; HP2L2-NEXT: (struct.new_default $super.desc) + ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (unreachable) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: (local.get $desc) @@ -1264,20 +1487,536 @@ (local.get $desc) ) - ;; CHECK: (func $get-desc-unreachable (type $10) - ;; CHECK-NEXT: (drop - ;; CHECK-NEXT: (block (result nullref) - ;; CHECK-NEXT: (ref.null none) - ;; CHECK-NEXT: ) - ;; CHECK-NEXT: ) + ;; CHECK: (func $cast-desc-bot (type $10) + ;; CHECK-NEXT: (local $0 (ref (exact $super.desc))) + ;; CHECK-NEXT: (local $1 (ref (exact $super.desc))) ;; CHECK-NEXT: (drop - ;; CHECK-NEXT: (block ;; (replaces unreachable RefGetDesc we can't emit) + ;; CHECK-NEXT: (block + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (block (result nullref) + ;; CHECK-NEXT: (local.set $1 + ;; CHECK-NEXT: (struct.new_default $super.desc) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (local.set $0 + ;; CHECK-NEXT: (local.get $1) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (ref.null none) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (block + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (block (result nullref) + ;; CHECK-NEXT: (ref.null none) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (unreachable) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (unreachable) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; HP2L2: (func $cast-desc-bot (type $10) + ;; HP2L2-NEXT: (local $0 (ref (exact $super.desc))) + ;; HP2L2-NEXT: (local $1 (ref (exact $super.desc))) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (local.set $1 + ;; HP2L2-NEXT: (struct.new_default $super.desc) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (local.set $0 + ;; HP2L2-NEXT: (local.get $1) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (unreachable) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (unreachable) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + (func $cast-desc-bot + ;; Failing inner cast in the descriptor operand yields an unreachable origin + ;; during origin propagation, so the outer cast traps too. + (drop + (ref.cast_desc_eq (ref (exact $sub)) + (struct.new_default_desc $super + (struct.new_default $super.desc) + ) + (ref.cast (ref (exact $sub.desc)) + (struct.new_default $super.desc) + ) + ) + ) + ) + + ;; CHECK: (func $cast-desc-eq-dead-desc (type $19) (param $desc (ref (exact $super.desc))) (result (ref (exact $super))) + ;; CHECK-NEXT: (local.set $desc + ;; CHECK-NEXT: (local.get $desc) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (ref.cast_desc_eq (ref (exact $super)) + ;; CHECK-NEXT: (struct.new_default_desc $super + ;; CHECK-NEXT: (local.get $desc) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (block (result (ref (exact $super.desc))) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (loop (result (ref none)) + ;; CHECK-NEXT: (unreachable) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (local.get $desc) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; HP2L2: (func $cast-desc-eq-dead-desc (type $19) (param $desc (ref (exact $super.desc))) (result (ref (exact $super))) + ;; HP2L2-NEXT: (local $1 (ref (exact $super.desc))) + ;; HP2L2-NEXT: (local $2 (ref (exact $super.desc))) + ;; HP2L2-NEXT: (local.set $desc + ;; HP2L2-NEXT: (local.get $desc) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (block + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (local.set $2 + ;; HP2L2-NEXT: (local.get $desc) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (local.set $1 + ;; HP2L2-NEXT: (local.get $2) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result (ref (exact $super.desc))) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (loop + ;; HP2L2-NEXT: (unreachable) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (local.get $desc) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (unreachable) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + (func $cast-desc-eq-dead-desc (param $desc (ref (exact $super.desc))) (result (ref (exact $super))) + ;; A descriptor block after an unreachable typed loop gets an unreachable + ;; origin during origin propagation when the local has a reachable set, even + ;; though the block retains its concrete result type, so the outer cast folds + ;; to a trap instead of emitting a nullable result. + (local.set $desc + (local.get $desc) + ) + (ref.cast_desc_eq (ref (exact $super)) + (struct.new_default_desc $super + (local.get $desc) + ) + (block (result (ref (exact $super.desc))) + (drop + (loop (result (ref none)) + (unreachable) + ) + ) + (local.get $desc) + ) + ) + ) + + ;; CHECK: (func $cast-desc-wrong-subtype (type $20) (param $desc (ref (exact $sub.desc))) + ;; CHECK-NEXT: (local $1 (ref (exact $super.desc))) + ;; CHECK-NEXT: (local $2 (ref (exact $super.desc))) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (block + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (block (result nullref) + ;; CHECK-NEXT: (local.set $2 + ;; CHECK-NEXT: (struct.new_default $super.desc) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (local.set $1 + ;; CHECK-NEXT: (local.get $2) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (ref.null none) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (local.get $desc) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (unreachable) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; HP2L2: (func $cast-desc-wrong-subtype (type $20) (param $desc (ref (exact $sub.desc))) + ;; HP2L2-NEXT: (local $1 (ref (exact $super.desc))) + ;; HP2L2-NEXT: (local $2 (ref (exact $super.desc))) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (local.set $2 + ;; HP2L2-NEXT: (struct.new_default $super.desc) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (local.set $1 + ;; HP2L2-NEXT: (local.get $2) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (local.get $desc) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (unreachable) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + (func $cast-desc-wrong-subtype (param $desc (ref (exact $sub.desc))) + ;; Cast fails because $super is not a subtype of $sub. + (drop + (ref.cast_desc_eq (ref (exact $sub)) + (struct.new_default_desc $super + (struct.new_default $super.desc) + ) + (local.get $desc) + ) + ) + ) + + ;; CHECK: (func $get-desc-unreachable (type $10) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (block (result nullref) + ;; CHECK-NEXT: (ref.null none) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (block ;; (replaces unreachable RefGetDesc we can't emit) ;; CHECK-NEXT: (drop ;; CHECK-NEXT: (unreachable) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (unreachable) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; HP2L2: (func $get-desc-unreachable (type $10) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block ;; (replaces unreachable RefGetDesc we can't emit) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (unreachable) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (unreachable) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + (func $get-desc-unreachable + ;; Unreachable ref.get_desc should be left untouched. + (drop + (struct.new_default $no-desc) + ) + (drop + (ref.get_desc $super + (unreachable) + ) + ) + ) + + ;; CHECK: (func $worklist-repeat (type $21) (param $p i32) (result eqref) + ;; CHECK-NEXT: (local $d (ref null (exact $super.desc))) + ;; CHECK-NEXT: (ref.as_non_null + ;; CHECK-NEXT: (block $V (result eqref) + ;; CHECK-NEXT: (local.set $d + ;; CHECK-NEXT: (br_if $V + ;; CHECK-NEXT: (struct.new_default $super.desc) + ;; CHECK-NEXT: (local.get $p) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (ref.cast_desc_eq (ref (exact $super)) + ;; CHECK-NEXT: (struct.new_default_desc $super + ;; CHECK-NEXT: (call $import-desc) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (local.get $d) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; HP2L2: (func $worklist-repeat (type $21) (param $p i32) (result eqref) + ;; HP2L2-NEXT: (local $d (ref null (exact $super.desc))) + ;; HP2L2-NEXT: (ref.as_non_null + ;; HP2L2-NEXT: (block $V (result eqref) + ;; HP2L2-NEXT: (local.set $d + ;; HP2L2-NEXT: (br_if $V + ;; HP2L2-NEXT: (struct.new_default $super.desc) + ;; HP2L2-NEXT: (local.get $p) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (ref.cast_desc_eq (ref (exact $super)) + ;; HP2L2-NEXT: (struct.new_default_desc $super + ;; HP2L2-NEXT: (call $import-desc) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (local.get $d) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + (func $worklist-repeat (param $p i32) (result eqref) + (local $d (ref null (exact $super.desc))) + ;; The allocation flows both directly to $V via br_if and through $d into + ;; ref.cast_desc_eq, merging an unknown cast result into $V during origin + ;; propagation so the allocation escapes. + (ref.as_non_null + (block $V (result eqref) + (local.set $d + (br_if $V + (struct.new_default $super.desc) + (local.get $p) + ) + ) + (ref.cast_desc_eq (ref null $super) + (struct.new_default_desc $super + (call $import-desc) + ) + (local.get $d) + ) + ) + ) + ) + + ;; CHECK: (func $cast-null-ref-candidate-desc (type $10) + ;; CHECK-NEXT: (local $0 nullref) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (block (result nullref) + ;; CHECK-NEXT: (local.set $0 + ;; CHECK-NEXT: (ref.null none) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (block (result nullref) + ;; CHECK-NEXT: (ref.null none) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (ref.cast nullref + ;; CHECK-NEXT: (local.get $0) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; HP2L2: (func $cast-null-ref-candidate-desc (type $10) + ;; HP2L2-NEXT: (local $0 nullref) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (local.set $0 + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (ref.cast nullref + ;; HP2L2-NEXT: (local.get $0) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + (func $cast-null-ref-candidate-desc + ;; A null ref in ref.cast_desc_eq is not a candidate allocation, while the + ;; descriptor allocation still optimizes because it does not escape. + (drop + (ref.cast_desc_eq (ref null $super) + (ref.null none) + (struct.new_default $super.desc) + ) + ) + ) + + ;; CHECK: (func $cast-desc-eq-neither-optimized (type $22) (param $ref (ref null (exact $super))) (param $desc (ref null (exact $super.desc))) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (block (result nullref) + ;; CHECK-NEXT: (ref.null none) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (ref.cast_desc_eq (ref null (exact $super)) + ;; CHECK-NEXT: (local.get $ref) + ;; CHECK-NEXT: (local.get $desc) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; HP2L2: (func $cast-desc-eq-neither-optimized (type $22) (param $ref (ref null (exact $super))) (param $desc (ref null (exact $super.desc))) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (ref.cast_desc_eq (ref null (exact $super)) + ;; HP2L2-NEXT: (local.get $ref) + ;; HP2L2-NEXT: (local.get $desc) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + (func $cast-desc-eq-neither-optimized (param $ref (ref null (exact $super))) (param $desc (ref null (exact $super.desc))) + ;; Neither operand is an optimized allocation, alongside another optimized allocation. + (drop + (struct.new_default $no-desc) + ) + (drop + (ref.cast_desc_eq (ref null $super) + (local.get $ref) + (local.get $desc) + ) + ) + ) + + ;; CHECK: (func $cast-desc-eq-subtype (type $23) (param $sub-desc (ref (exact $sub.desc))) (param $desc (ref null $super.desc)) + ;; CHECK-NEXT: (local $2 (ref (exact $sub.desc))) + ;; CHECK-NEXT: (local $3 (ref (exact $sub.desc))) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (block (result nullref) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (block (result nullref) + ;; CHECK-NEXT: (local.set $3 + ;; CHECK-NEXT: (local.get $sub-desc) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (local.set $2 + ;; CHECK-NEXT: (local.get $3) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (ref.null none) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (if (result nullref) + ;; CHECK-NEXT: (ref.eq + ;; CHECK-NEXT: (local.get $desc) + ;; CHECK-NEXT: (local.get $2) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (then + ;; CHECK-NEXT: (ref.null none) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (else + ;; CHECK-NEXT: (unreachable) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; HP2L2: (func $cast-desc-eq-subtype (type $23) (param $sub-desc (ref (exact $sub.desc))) (param $desc (ref null $super.desc)) + ;; HP2L2-NEXT: (local $2 (ref (exact $sub.desc))) + ;; HP2L2-NEXT: (local $3 (ref (exact $sub.desc))) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (local.set $3 + ;; HP2L2-NEXT: (local.get $sub-desc) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (local.set $2 + ;; HP2L2-NEXT: (local.get $3) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (if (result nullref) + ;; HP2L2-NEXT: (ref.eq + ;; HP2L2-NEXT: (local.get $desc) + ;; HP2L2-NEXT: (local.get $2) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (then + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (else + ;; HP2L2-NEXT: (unreachable) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + (func $cast-desc-eq-subtype (param $sub-desc (ref (exact $sub.desc))) (param $desc (ref null $super.desc)) + ;; Subtype $sub optimizes through an inexact supertype ref.cast_desc_eq. + (drop + (ref.cast_desc_eq (ref $super) + (struct.new_default_desc $sub + (local.get $sub-desc) + ) + (local.get $desc) + ) + ) + ) + + ;; CHECK: (func $cast-desc-eq-inexact-fail (type $24) (param $sub-desc (ref (exact $sub.desc))) (param $desc (ref null (exact $super.desc))) (result (ref (exact $super))) + ;; CHECK-NEXT: (local $2 (ref (exact $sub.desc))) + ;; CHECK-NEXT: (local $3 (ref (exact $sub.desc))) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (block (result nullref) + ;; CHECK-NEXT: (local.set $3 + ;; CHECK-NEXT: (local.get $sub-desc) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (local.set $2 + ;; CHECK-NEXT: (local.get $3) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (ref.null none) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (local.get $desc) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (unreachable) + ;; CHECK-NEXT: ) + ;; HP2L2: (func $cast-desc-eq-inexact-fail (type $24) (param $sub-desc (ref (exact $sub.desc))) (param $desc (ref null (exact $super.desc))) (result (ref (exact $super))) + ;; HP2L2-NEXT: (local $2 (ref (exact $sub.desc))) + ;; HP2L2-NEXT: (local $3 (ref (exact $sub.desc))) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (local.set $3 + ;; HP2L2-NEXT: (local.get $sub-desc) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (local.set $2 + ;; HP2L2-NEXT: (local.get $3) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (local.get $desc) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (unreachable) + ;; HP2L2-NEXT: ) + (func $cast-desc-eq-inexact-fail (param $sub-desc (ref (exact $sub.desc))) (param $desc (ref null (exact $super.desc))) (result (ref (exact $super))) + ;; Exact supertype cast fails for subtype $sub allocation and traps. + (ref.cast_desc_eq (ref (exact $super)) + (struct.new_default_desc $sub + (local.get $sub-desc) + ) + (local.get $desc) + ) + ) + + ;; CHECK: (func $cast-unknown-ref-and-desc (type $10) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (ref.cast (ref $super) + ;; CHECK-NEXT: (call $import-any) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (ref.cast_desc_eq (ref (exact $super)) + ;; CHECK-NEXT: (struct.new_default_desc $super + ;; CHECK-NEXT: (call $import-desc) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (call $import-desc) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) ;; CHECK-NEXT: (if ;; CHECK-NEXT: (i32.const 0) ;; CHECK-NEXT: (then @@ -1292,18 +2031,41 @@ ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) - ;; HP2L2: (func $get-desc-unreachable (type $10) + ;; HP2L2: (func $cast-unknown-ref-and-desc (type $10) + ;; HP2L2-NEXT: (local $0 (ref (exact $super.desc))) + ;; HP2L2-NEXT: (local $1 (ref (exact $super.desc))) ;; HP2L2-NEXT: (drop - ;; HP2L2-NEXT: (block (result nullref) - ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: (ref.cast (ref $super) + ;; HP2L2-NEXT: (call $import-any) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: (drop - ;; HP2L2-NEXT: (block ;; (replaces unreachable RefGetDesc we can't emit) + ;; HP2L2-NEXT: (block (result nullref) ;; HP2L2-NEXT: (drop - ;; HP2L2-NEXT: (unreachable) + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (local.set $1 + ;; HP2L2-NEXT: (ref.as_non_null + ;; HP2L2-NEXT: (call $import-desc) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (local.set $0 + ;; HP2L2-NEXT: (local.get $1) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (if (result nullref) + ;; HP2L2-NEXT: (ref.eq + ;; HP2L2-NEXT: (call $import-desc) + ;; HP2L2-NEXT: (local.get $0) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (then + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (else + ;; HP2L2-NEXT: (unreachable) + ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) - ;; HP2L2-NEXT: (unreachable) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: (if @@ -1320,15 +2082,21 @@ ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) - (func $get-desc-unreachable - ;; Unreachable ref.get_desc and struct.new_default_desc should be left - ;; untouched. + (func $cast-unknown-ref-and-desc + ;; Exercise unknown (imported) ref and descriptor operands in ref.cast and + ;; ref.cast_desc_eq alongside a candidate allocation, plus an unreachable + ;; struct.new_default_desc. (drop - (struct.new_default $no-desc) + (ref.cast (ref $super) + (call $import-any) + ) ) (drop - (ref.get_desc $super - (unreachable) + (ref.cast_desc_eq (ref $super) + (struct.new_default_desc $super + (call $import-desc) + ) + (call $import-desc) ) ) (if @@ -1553,12 +2321,25 @@ ;; HP2L2: (type $4 (func (result (ref $A)))) ;; HP2L2: (func $A (type $4) (result (ref $A)) - ;; HP2L2-NEXT: (ref.cast_desc_eq (ref (exact $A)) - ;; HP2L2-NEXT: (struct.new_default_desc $A2 - ;; HP2L2-NEXT: (struct.new_default $B2) + ;; HP2L2-NEXT: (local $0 (ref (exact $B2))) + ;; HP2L2-NEXT: (local $1 (ref (exact $B2))) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (local.set $1 + ;; HP2L2-NEXT: (struct.new_default $B2) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (local.set $0 + ;; HP2L2-NEXT: (local.get $1) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (ref.null none) ;; HP2L2-NEXT: ) - ;; HP2L2-NEXT: (struct.new_default $B) ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (unreachable) ;; HP2L2-NEXT: ) (func $A (result (ref $A)) (ref.cast_desc_eq (ref $A) @@ -1714,25 +2495,41 @@ ;; HP2L2: (func $test (type $2) ;; HP2L2-NEXT: (local $B (ref null $B)) ;; HP2L2-NEXT: (local $v v128) + ;; HP2L2-NEXT: (local $2 v128) + ;; HP2L2-NEXT: (local $3 (ref (exact $B))) + ;; HP2L2-NEXT: (local $4 (ref (exact $B))) ;; HP2L2-NEXT: (drop - ;; HP2L2-NEXT: (ref.as_non_null - ;; HP2L2-NEXT: (local.tee $B - ;; HP2L2-NEXT: (struct.new_default $B) - ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (ref.null none) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: (local.set $v - ;; HP2L2-NEXT: (struct.get $A 0 - ;; HP2L2-NEXT: (ref.cast_desc_eq (ref $A) - ;; HP2L2-NEXT: (struct.new_default_desc $A - ;; HP2L2-NEXT: (ref.as_non_null + ;; HP2L2-NEXT: (block (result v128) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (local.set $4 + ;; HP2L2-NEXT: (ref.as_non_null + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (local.set $2 + ;; HP2L2-NEXT: (v128.const i32x4 0x00000000 0x00000000 0x00000000 0x00000000) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (local.set $3 + ;; HP2L2-NEXT: (local.get $4) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (drop ;; HP2L2-NEXT: (ref.null none) ;; HP2L2-NEXT: ) - ;; HP2L2-NEXT: ) - ;; HP2L2-NEXT: (ref.as_non_null - ;; HP2L2-NEXT: (local.get $B) + ;; HP2L2-NEXT: (unreachable) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (local.get $2) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) @@ -1832,17 +2629,31 @@ ;; HP2L2: (func $test (type $3) (result (ref (shared any))) ;; HP2L2-NEXT: (local $temp (ref $C)) - ;; HP2L2-NEXT: (local.set $temp - ;; HP2L2-NEXT: (struct.new_default $C) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result (ref null (shared none))) + ;; HP2L2-NEXT: (ref.null (shared none)) + ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) - ;; HP2L2-NEXT: (ref.cast_desc_eq (ref (exact $B)) - ;; HP2L2-NEXT: (ref.cast_desc_eq (ref $B) - ;; HP2L2-NEXT: (struct.new_default_desc $B + ;; HP2L2-NEXT: (block + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (struct.new_default_desc $B + ;; HP2L2-NEXT: (ref.null (shared none)) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (ref.null (shared none)) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (unreachable) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result (ref null (shared none))) ;; HP2L2-NEXT: (ref.null (shared none)) ;; HP2L2-NEXT: ) - ;; HP2L2-NEXT: (local.get $temp) ;; HP2L2-NEXT: ) - ;; HP2L2-NEXT: (struct.new_default $C) + ;; HP2L2-NEXT: (unreachable) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) (func $test (result (ref (shared any))) @@ -1913,16 +2724,34 @@ ;; HP2L2: (func $test (type $2) (result i32) ;; HP2L2-NEXT: (local $desc (ref $desc)) - ;; HP2L2-NEXT: (local.set $desc - ;; HP2L2-NEXT: (struct.new_default $desc) + ;; HP2L2-NEXT: (local $1 (ref (exact $desc))) + ;; HP2L2-NEXT: (local $2 (ref (exact $desc))) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) - ;; HP2L2-NEXT: (ref.is_null - ;; HP2L2-NEXT: (ref.cast_desc_eq (ref $struct) - ;; HP2L2-NEXT: (struct.new_default_desc $struct - ;; HP2L2-NEXT: (struct.new_default $desc) + ;; HP2L2-NEXT: (block (result i32) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (local.set $2 + ;; HP2L2-NEXT: (struct.new_default $desc) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (local.set $1 + ;; HP2L2-NEXT: (local.get $2) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (unreachable) ;; HP2L2-NEXT: ) - ;; HP2L2-NEXT: (local.get $desc) ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (i32.const 0) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) (func $test (result i32) @@ -2010,18 +2839,40 @@ ;; HP2L2: (func $test (type $2) ;; HP2L2-NEXT: (local $desc (ref $desc)) ;; HP2L2-NEXT: (local $func funcref) - ;; HP2L2-NEXT: (local.set $desc - ;; HP2L2-NEXT: (struct.new_default $desc) + ;; HP2L2-NEXT: (local $2 funcref) + ;; HP2L2-NEXT: (local $3 (ref (exact $desc))) + ;; HP2L2-NEXT: (local $4 (ref (exact $desc))) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (local.set $2 + ;; HP2L2-NEXT: (ref.null nofunc) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: (local.set $func ;; HP2L2-NEXT: (struct.get $desc 0 - ;; HP2L2-NEXT: (ref.get_desc $struct - ;; HP2L2-NEXT: (ref.cast_desc_eq (ref $struct) - ;; HP2L2-NEXT: (struct.new_default_desc $struct - ;; HP2L2-NEXT: (struct.new_default $desc) + ;; HP2L2-NEXT: (block (result (ref (exact $desc))) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (local.set $4 + ;; HP2L2-NEXT: (struct.new_default $desc) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (local.set $3 + ;; HP2L2-NEXT: (local.get $4) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (unreachable) ;; HP2L2-NEXT: ) - ;; HP2L2-NEXT: (local.get $desc) ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (local.get $3) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) @@ -2103,19 +2954,37 @@ ;; HP2L2: (func $test (type $2) ;; HP2L2-NEXT: (local $temp (ref $desc)) - ;; HP2L2-NEXT: (local.set $temp - ;; HP2L2-NEXT: (struct.new_default $desc) + ;; HP2L2-NEXT: (local $1 (ref (exact $desc))) + ;; HP2L2-NEXT: (local $2 (ref (exact $desc))) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: (drop - ;; HP2L2-NEXT: (ref.test (ref none) - ;; HP2L2-NEXT: (ref.cast_desc_eq (ref $struct) - ;; HP2L2-NEXT: (struct.new_default_desc $struct - ;; HP2L2-NEXT: (ref.as_non_null + ;; HP2L2-NEXT: (block (result i32) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (local.set $2 + ;; HP2L2-NEXT: (ref.as_non_null + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (local.set $1 + ;; HP2L2-NEXT: (local.get $2) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (drop ;; HP2L2-NEXT: (ref.null none) ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (unreachable) ;; HP2L2-NEXT: ) - ;; HP2L2-NEXT: (local.get $temp) ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (i32.const 0) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) diff --git a/test/lit/passes/heap2local.wast b/test/lit/passes/heap2local.wast index 7a3e583d15a..9e4f9264d39 100644 --- a/test/lit/passes/heap2local.wast +++ b/test/lit/passes/heap2local.wast @@ -3332,14 +3332,28 @@ ;; CHECK-NEXT: (local.get $0) ;; CHECK-NEXT: ) ;; HP2L2: (func $ref-cast (type $4) (result i32) - ;; HP2L2-NEXT: (struct.get $struct.A 0 - ;; HP2L2-NEXT: (ref.cast (ref (exact $struct.A)) - ;; HP2L2-NEXT: (struct.new $struct.A + ;; HP2L2-NEXT: (local $0 i32) + ;; HP2L2-NEXT: (local $1 f64) + ;; HP2L2-NEXT: (local $2 i32) + ;; HP2L2-NEXT: (local $3 f64) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (local.set $2 ;; HP2L2-NEXT: (i32.const 0) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (local.set $3 ;; HP2L2-NEXT: (f64.const 0) ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (local.set $0 + ;; HP2L2-NEXT: (local.get $2) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (local.set $1 + ;; HP2L2-NEXT: (local.get $3) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (ref.null none) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (local.get $0) ;; HP2L2-NEXT: ) (func $ref-cast (result i32) (struct.get $struct.A 0 @@ -5367,6 +5381,8 @@ ;; CHECK: (type $1 (func (result anyref))) ;; CHECK: (type $B (sub $A (struct (field (ref $A)) (field i32)))) + ;; HP2L2: (type $1 (func (result anyref))) + ;; HP2L2: (type $B (sub $A (struct (field (ref $A)) (field i32)))) (type $B (sub $A (struct (field (ref $A)) (field i32)))) @@ -5403,11 +5419,9 @@ ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) - ;; HP2L2: (type $2 (func (result anyref))) - ;; HP2L2: (type $3 (func (result i32))) - ;; HP2L2: (func $func (type $2) (result anyref) + ;; HP2L2: (func $func (type $1) (result anyref) ;; HP2L2-NEXT: (local $a (ref $A)) ;; HP2L2-NEXT: (local $1 (ref $A)) ;; HP2L2-NEXT: (local $2 i32) @@ -5485,17 +5499,31 @@ ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.get $0) ;; CHECK-NEXT: ) - ;; HP2L2: (func $cast-success (type $2) (result anyref) - ;; HP2L2-NEXT: (struct.get $B 0 - ;; HP2L2-NEXT: (ref.cast (ref (exact $B)) - ;; HP2L2-NEXT: (struct.new $B + ;; HP2L2: (func $cast-success (type $1) (result anyref) + ;; HP2L2-NEXT: (local $0 (ref $A)) + ;; HP2L2-NEXT: (local $1 i32) + ;; HP2L2-NEXT: (local $2 (ref $A)) + ;; HP2L2-NEXT: (local $3 i32) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (local.set $2 ;; HP2L2-NEXT: (struct.new $A ;; HP2L2-NEXT: (ref.null none) ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (local.set $3 ;; HP2L2-NEXT: (i32.const 1) ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (local.set $0 + ;; HP2L2-NEXT: (local.get $2) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (local.set $1 + ;; HP2L2-NEXT: (local.get $3) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (ref.null none) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (local.get $0) ;; HP2L2-NEXT: ) (func $cast-success (result anyref) (struct.get $A 0 @@ -5534,15 +5562,26 @@ ;; CHECK-NEXT: (unreachable) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) - ;; HP2L2: (func $cast-failure (type $2) (result anyref) + ;; HP2L2: (func $cast-failure (type $1) (result anyref) + ;; HP2L2-NEXT: (local $0 (ref null $A)) + ;; HP2L2-NEXT: (local $1 (ref null $A)) ;; HP2L2-NEXT: (block ;; (replaces unreachable StructGet we can't emit) ;; HP2L2-NEXT: (drop - ;; HP2L2-NEXT: (ref.cast (ref none) - ;; HP2L2-NEXT: (struct.new $A - ;; HP2L2-NEXT: (struct.new $A + ;; HP2L2-NEXT: (block + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (local.set $1 + ;; HP2L2-NEXT: (struct.new $A + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (local.set $0 + ;; HP2L2-NEXT: (local.get $1) + ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: (ref.null none) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (unreachable) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: (unreachable) @@ -5589,14 +5628,25 @@ ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; HP2L2: (func $cast-failure-nofield (type $3) (result i32) + ;; HP2L2-NEXT: (local $0 (ref null $A)) + ;; HP2L2-NEXT: (local $1 (ref null $A)) ;; HP2L2-NEXT: (block ;; (replaces unreachable StructGet we can't emit) ;; HP2L2-NEXT: (drop - ;; HP2L2-NEXT: (ref.cast (ref none) - ;; HP2L2-NEXT: (struct.new $A - ;; HP2L2-NEXT: (struct.new $A + ;; HP2L2-NEXT: (block + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (local.set $1 + ;; HP2L2-NEXT: (struct.new $A + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (local.set $0 + ;; HP2L2-NEXT: (local.get $1) + ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: (ref.null none) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (unreachable) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: (unreachable) @@ -5618,14 +5668,18 @@ ) (module + ;; CHECK: (type $A (sub (struct (field (mut i32))))) ;; HP2L2: (type $A (sub (struct (field (mut i32))))) (type $A (sub (struct (field (mut i32))))) + ;; CHECK: (type $B (sub $A (struct (field (mut i32))))) ;; HP2L2: (type $B (sub $A (struct (field (mut i32))))) (type $B (sub $A (struct (field (mut i32))))) - ;; CHECK: (type $0 (func)) + ;; CHECK: (type $2 (func)) - ;; CHECK: (func $func (type $0) + ;; CHECK: (type $3 (func (param i32 i32))) + + ;; CHECK: (func $func (type $2) ;; CHECK-NEXT: (local $0 i32) ;; CHECK-NEXT: (local $1 i32) ;; CHECK-NEXT: (drop @@ -5646,14 +5700,22 @@ ;; CHECK-NEXT: ) ;; HP2L2: (type $2 (func)) + ;; HP2L2: (type $3 (func (param i32 i32))) + ;; HP2L2: (func $func (type $2) + ;; HP2L2-NEXT: (local $0 i32) + ;; HP2L2-NEXT: (local $1 i32) ;; HP2L2-NEXT: (drop - ;; HP2L2-NEXT: (block (result (ref $B)) - ;; HP2L2-NEXT: (ref.cast (ref $B) - ;; HP2L2-NEXT: (block (result (ref $A)) - ;; HP2L2-NEXT: (struct.new $B + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (local.set $1 ;; HP2L2-NEXT: (i32.const 0) ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (local.set $0 + ;; HP2L2-NEXT: (local.get $1) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (ref.null none) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) @@ -5677,6 +5739,105 @@ ) ) ) + + ;; CHECK: (func $cast-revisit-in-worklist (type $3) (param $p i32) (param $q i32) + ;; CHECK-NEXT: (local $y (ref null $A)) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (ref.as_non_null + ;; CHECK-NEXT: (block $V (result (ref null $A)) + ;; CHECK-NEXT: (if + ;; CHECK-NEXT: (local.get $q) + ;; CHECK-NEXT: (then + ;; CHECK-NEXT: (local.set $y + ;; CHECK-NEXT: (br_if $V + ;; CHECK-NEXT: (struct.new $B + ;; CHECK-NEXT: (i32.const 1) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (local.get $p) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (else + ;; CHECK-NEXT: (local.set $y + ;; CHECK-NEXT: (struct.new $A + ;; CHECK-NEXT: (i32.const 2) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (ref.cast (ref $B) + ;; CHECK-NEXT: (local.get $y) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; HP2L2: (func $cast-revisit-in-worklist (type $3) (param $p i32) (param $q i32) + ;; HP2L2-NEXT: (local $y (ref null $A)) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (ref.as_non_null + ;; HP2L2-NEXT: (block $V (result (ref null $A)) + ;; HP2L2-NEXT: (if + ;; HP2L2-NEXT: (local.get $q) + ;; HP2L2-NEXT: (then + ;; HP2L2-NEXT: (local.set $y + ;; HP2L2-NEXT: (br_if $V + ;; HP2L2-NEXT: (struct.new $B + ;; HP2L2-NEXT: (i32.const 1) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (local.get $p) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (else + ;; HP2L2-NEXT: (local.set $y + ;; HP2L2-NEXT: (struct.new $A + ;; HP2L2-NEXT: (i32.const 2) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (ref.cast (ref $B) + ;; HP2L2-NEXT: (local.get $y) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: ) + (func $cast-revisit-in-worklist (param $p i32) (param $q i32) + (local $y (ref null $A)) + ;; Test ref.cast over a local merging two candidate allocations alongside a + ;; conditional br_if into $V. + (drop + (ref.as_non_null + (block $V (result (ref null $A)) + (if + (local.get $q) + (then + (local.set $y + (br_if $V + (struct.new $B + (i32.const 1) + ) + (local.get $p) + ) + ) + ) + (else + (local.set $y + (struct.new $A + (i32.const 2) + ) + ) + ) + ) + (ref.cast (ref $B) + (local.get $y) + ) + ) + ) + ) + ) ) (module @@ -6438,18 +6599,26 @@ ;; CHECK-NEXT: ) ;; HP2L2: (func $array.local.super (type $1) ;; HP2L2-NEXT: (local $temp anyref) - ;; HP2L2-NEXT: (local.set $temp - ;; HP2L2-NEXT: (array.new $array - ;; HP2L2-NEXT: (i32.const 42) - ;; HP2L2-NEXT: (i32.const 1) + ;; HP2L2-NEXT: (local $1 i32) + ;; HP2L2-NEXT: (local $2 i32) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (local.set $2 + ;; HP2L2-NEXT: (i32.const 42) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (local.set $1 + ;; HP2L2-NEXT: (local.get $2) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (ref.null none) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) - ;; HP2L2-NEXT: (array.set $array - ;; HP2L2-NEXT: (ref.cast (ref $array) - ;; HP2L2-NEXT: (local.get $temp) + ;; HP2L2-NEXT: (block + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (local.set $1 + ;; HP2L2-NEXT: (i32.const 100) ;; HP2L2-NEXT: ) - ;; HP2L2-NEXT: (i32.const 0) - ;; HP2L2-NEXT: (i32.const 100) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) (func $array.local.super @@ -8399,8 +8568,6 @@ ;; CHECK: (type $1 (func)) ;; CHECK: (type $0 (func (result (ref struct)))) - ;; HP2L2: (type $array (array i8)) - ;; HP2L2: (type $1 (func)) ;; HP2L2: (type $0 (func (result (ref struct)))) @@ -8410,6 +8577,11 @@ ;; CHECK: (type $4 (func (result (ref array)))) ;; CHECK: (type $array (array i8)) + ;; HP2L2: (type $3 (func (result structref))) + + ;; HP2L2: (type $4 (func (result (ref array)))) + + ;; HP2L2: (type $array (array i8)) (type $array (array i8)) ;; CHECK: (func $array.cast.struct (type $0) (result (ref struct)) @@ -8421,17 +8593,14 @@ ;; CHECK-NEXT: ) ;; CHECK-NEXT: (unreachable) ;; CHECK-NEXT: ) - ;; HP2L2: (type $3 (func (result structref))) - - ;; HP2L2: (type $4 (func (result (ref array)))) - ;; HP2L2: (func $array.cast.struct (type $0) (result (ref struct)) ;; HP2L2-NEXT: (local $eq (ref eq)) - ;; HP2L2-NEXT: (ref.cast (ref struct) - ;; HP2L2-NEXT: (local.tee $eq - ;; HP2L2-NEXT: (array.new_fixed $array 0) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (ref.null none) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (unreachable) ;; HP2L2-NEXT: ) (func $array.cast.struct (result (ref struct)) (local $eq (ref eq)) @@ -8457,11 +8626,12 @@ ;; CHECK-NEXT: ) ;; HP2L2: (func $array.cast.struct.null (type $3) (result structref) ;; HP2L2-NEXT: (local $eq (ref eq)) - ;; HP2L2-NEXT: (ref.cast (ref struct) - ;; HP2L2-NEXT: (local.tee $eq - ;; HP2L2-NEXT: (array.new_fixed $array 0) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (ref.null none) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (unreachable) ;; HP2L2-NEXT: ) (func $array.cast.struct.null (result (ref null struct)) (local $eq (ref eq)) @@ -8512,11 +8682,9 @@ ;; HP2L2: (func $array.cast.array.set (type $1) ;; HP2L2-NEXT: (local $eq (ref eq)) ;; HP2L2-NEXT: (local $array (ref array)) - ;; HP2L2-NEXT: (local.set $array - ;; HP2L2-NEXT: (ref.cast (ref array) - ;; HP2L2-NEXT: (local.tee $eq - ;; HP2L2-NEXT: (array.new_fixed $array 0) - ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (ref.null none) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) @@ -8552,10 +8720,13 @@ ;; HP2L2-NEXT: (local $eq (ref eq)) ;; HP2L2-NEXT: (local $struct (ref struct)) ;; HP2L2-NEXT: (local.set $struct - ;; HP2L2-NEXT: (ref.cast (ref struct) - ;; HP2L2-NEXT: (local.tee $eq - ;; HP2L2-NEXT: (array.new_fixed $array 0) + ;; HP2L2-NEXT: (block + ;; HP2L2-NEXT: (drop + ;; HP2L2-NEXT: (block (result nullref) + ;; HP2L2-NEXT: (ref.null none) + ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) + ;; HP2L2-NEXT: (unreachable) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: ) ;; HP2L2-NEXT: )