From e75dd9c80e4f1c4ae2643236e444482aa6b3bbb9 Mon Sep 17 00:00:00 2001 From: Thomas Lively Date: Wed, 21 Oct 2026 23:22:52 -0700 Subject: [PATCH] [StackIR] Thread stack values into block params When multivalue is enabled, allow StackIROptimizer::local2Stack() to eliminate single-use local.set/local.get pairs across up to 3 enclosing BlockBegin boundaries by recording the eliminated sets on each crossed block scope and setting the block's input parameter types accordingly. --- src/wasm-stack.h | 5 + src/wasm/wasm-stack-opts.cpp | 152 ++- test/gtest/printing.cpp | 106 -- test/lit/passes/optimize-stack-ir.wast | 411 +++++++- .../lit/passes/stack-ir-roundtrip-params.wast | 908 ++++++++++++++++++ test/lit/passes/translate-to-exnref.wast | 10 +- 6 files changed, 1441 insertions(+), 151 deletions(-) create mode 100644 test/lit/passes/stack-ir-roundtrip-params.wast diff --git a/src/wasm-stack.h b/src/wasm-stack.h index 050de844136..bbcb561d9b2 100644 --- a/src/wasm-stack.h +++ b/src/wasm-stack.h @@ -658,6 +658,8 @@ class StackIRToBinaryWriter { }; // Stack IR optimizer +struct LazyLocalGraph; + class StackIROptimizer { Function* func; StackIR& insts; @@ -683,6 +685,9 @@ class StackIROptimizer { bool isControlFlow(StackInst* inst); void removeAt(Index i); Index getNumConsumedValues(StackInst* inst); + bool isSingleUseSetGetPair(Index setIndex, + Index getIndex, + LazyLocalGraph& localGraph); bool canRemoveSetGetPair(Index setIndex, Index getIndex); bool isConsumedBySymmetricOp(Index getIndex); std::unordered_set findStringViewDeferredGets(); diff --git a/src/wasm/wasm-stack-opts.cpp b/src/wasm/wasm-stack-opts.cpp index 82bc3fbb08f..2dfda1d9817 100644 --- a/src/wasm/wasm-stack-opts.cpp +++ b/src/wasm/wasm-stack-opts.cpp @@ -176,9 +176,30 @@ void StackIROptimizer::local2Stack() { // stack at that location. const Index null = -1; std::vector values; - // We also maintain a stack of values vectors for control flow, - // saving the stack as we enter and restoring it when we exit. - std::vector> savedValues; + // We also maintain a stack of active control-flow scopes, saving the outer + // value stack as we enter and restoring it when we exit, while recording any + // LocalSet values threaded across BlockBegin boundaries as block input + // parameters. + struct BlockScope { + // An outer LocalSet value threaded into this block as an input parameter. + struct ParamSet { + // Index into `insts` of the eliminated LocalSet, used to sort parameters + // into the order their values were pushed onto the stack. + Index setIndex; + // Value type of the parameter. + Type type; + }; + + // Index into `insts` of the control-flow begin instruction, used to test + // whether this scope was entered after a candidate LocalSet and to update + // `insts[beginInstIndex]->params` on exit. + Index beginInstIndex; + // Outer value stack saved on scope entry and restored on scope exit. + std::vector savedValues; + // Eliminated outer LocalSets threaded across this block boundary. + SmallVector paramSets; + }; + std::vector scopeStack; #if STACK_OPT_DEBUG std::cout << "func: " << func->name << '\n' << insts << '\n'; #endif @@ -214,13 +235,45 @@ void StackIROptimizer::local2Stack() { // After consuming, we can see what to do with this. First, handle // control flow. if (isControlFlowBegin(inst)) { - // Save the stack for when we end this control flow. - savedValues.push_back(values); // TODO: optimize copies - values.assign(inst->params.size(), null); + assert(inst->params == Type::none); + std::vector innerValues; + if (features.hasMultivalue() && inst->op == StackInst::BlockBegin) { + // Initialize `innerValues` with the contiguous suffix of candidate + // LocalSets at the top of the outer stack so inner LocalGets can thread + // them across `BlockBegin` as block input parameters. Stop at the first + // `null` (which represents an actual unnamed value already on the Wasm + // value stack) because block parameters are popped from the top of the + // stack at `BlockBegin` and cannot reach underneath an unconsumed stack + // value. + size_t start = values.size(); + while (start > 0 && values[start - 1] != null) { + start--; + } + innerValues.assign(values.begin() + start, values.end()); + } + scopeStack.push_back({instIndex, std::move(values), {}}); + values = std::move(innerValues); } else if (isControlFlowEnd(inst)) { - assert(!savedValues.empty()); - values = savedValues.back(); - savedValues.pop_back(); + assert(!scopeStack.empty()); + auto scope = std::move(scopeStack.back()); + scopeStack.pop_back(); + if (!scope.paramSets.empty()) { + // Inner LocalGets can be optimized in reverse stack order when consumed + // by a symmetric operation, so sort by `setIndex` to match the order + // the parameter values were pushed before `BlockBegin`. + std::sort(scope.paramSets.begin(), + scope.paramSets.end(), + [](const auto& lhs, const auto& rhs) { + return lhs.setIndex < rhs.setIndex; + }); + std::vector paramTypes; + paramTypes.reserve(scope.paramSets.size()); + for (const auto& param : scope.paramSets) { + paramTypes.push_back(param.type); + } + insts[scope.beginInstIndex]->params = Type(paramTypes); + } + values = std::move(scope.savedValues); } else if (isControlFlow(inst)) { // Otherwise, in the middle of control flow, just clear it values.clear(); @@ -262,34 +315,48 @@ void StackIROptimizer::local2Stack() { continue; } auto* set = insts[setIndex]->origin->cast(); - if (set->index == get->index) { - // This might be a proper set-get pair, where the set is - // used by this get and nothing else, check that. - auto& sets = localGraph.getSets(get); - if (sets.size() == 1 && *sets.begin() == set) { - auto& setInfluences = localGraph.getSetInfluences(set); - // If this has the proper value of 1, also do the potentially- - // expensive check of whether we can remove this pair at all. - if (setInfluences.size() == 1 && - canRemoveSetGetPair(setIndex, getIndex)) { - assert(*setInfluences.begin() == get); - // Do it! The set and the get can go away, the proper - // value is on the stack. + if (set->index == get->index && + isSingleUseSetGetPair(setIndex, getIndex, localGraph)) { + // Do it! The set and the get can go away, the proper + // value is on the stack. #if STACK_OPT_DEBUG - std::cout << " stackify the get\n"; + std::cout << " stackify the get\n"; #endif - insts[setIndex] = nullptr; - insts[getIndex] = nullptr; - // Continuing on from here, replace this on the stack - // with a null, representing a regular value. We - // keep possible values above us active - they may - // be optimized later, as they would be pushed after - // us, and used before us, so there is no conflict. - values[j] = null; - optimized = true; - break; + insts[setIndex] = nullptr; + insts[getIndex] = nullptr; + // Continuing on from here, replace this on the stack + // with a null, representing a regular value. We + // keep possible values above us active - they may + // be optimized later, as they would be pushed after + // us, and used before us, so there is no conflict. + values[j] = null; + // Record the new block parameter on each crossed block, scanning + // from innermost to outermost since `beginInstIndex` increases + // monotonically along `scopeStack`. + for (auto scopeIt = scopeStack.rbegin(); + scopeIt != scopeStack.rend() && + scopeIt->beginInstIndex > setIndex; + ++scopeIt) { + assert(insts[scopeIt->beginInstIndex]->op == + StackInst::BlockBegin); + scopeIt->paramSets.push_back({setIndex, get->type}); + auto savedIt = std::find(scopeIt->savedValues.begin(), + scopeIt->savedValues.end(), + setIndex); + if (savedIt != scopeIt->savedValues.end()) { + // `setIndex` is not necessarily at the back of `savedValues`: + // any candidate sets pushed after `setIndex` sit above this + // value on the outer stack at `BlockBegin` and would be + // consumed by the block if left on the stack, so erase + // `setIndex` and everything above it. (`savedIt` may already + // have been erased if an even deeper outer set was threaded + // earlier in this block.) + scopeIt->savedValues.erase(savedIt, + scopeIt->savedValues.end()); } } + optimized = true; + break; } // We failed here. Can we look some more? if (j == 0) { @@ -493,6 +560,25 @@ Index StackIROptimizer::getNumConsumedValues(StackInst* inst) { return ChildIterator(inst->origin).children.size(); } +// Check that `set` at `setIndex` and `get` at `getIndex` form a single-use +// def-use pair whose removal preserves non-nullable local validation. +bool StackIROptimizer::isSingleUseSetGetPair(Index setIndex, + Index getIndex, + LazyLocalGraph& localGraph) { + auto* set = insts[setIndex]->origin->cast(); + auto* get = insts[getIndex]->origin->cast(); + auto& sets = localGraph.getSets(get); + if (sets.size() != 1 || *sets.begin() != set) { + return false; + } + auto& setInfluences = localGraph.getSetInfluences(set); + if (setInfluences.size() != 1) { + return false; + } + assert(*setInfluences.begin() == get); + return canRemoveSetGetPair(setIndex, getIndex); +} + // Given a pair of a local.set and local.get, see if we can remove them // without breaking validation. Specifically, we must keep sets of non- // nullable locals that dominate a get until the end of the block, such as diff --git a/test/gtest/printing.cpp b/test/gtest/printing.cpp index 083d87edcc7..e6f519ea1e1 100644 --- a/test/gtest/printing.cpp +++ b/test/gtest/printing.cpp @@ -1,7 +1,6 @@ #include "ir/module-utils.h" #include "pass.h" #include "print-test.h" -#include "wasm-binary.h" #include "wasm-stack.h" #include "wasm.h" @@ -154,108 +153,3 @@ TEST_F(PrintingTest, StackIRParams) { EXPECT_TRUE(indexedTypes.indices.contains( Signature(Type({Type::i32, Type::f64}), Type::i32))); } - -TEST_F(PrintingTest, StackIRParamBinaryAndOptimizer) { - auto moduleText = R"wasm( - (module - (func $id (param $x i32) (result i32) - (local $tmp i32) - (local.set $tmp (local.get $x)) - (block $b (result i32) - (i32.add - (local.get $tmp) - (i32.const 1) - ) - ) - ) - ) - )wasm"; - - Module wasm; - wasm.features = FeatureSet::All; - parseWast(wasm, moduleText); - - PassOptions options; - options.optimizeLevel = 3; - ModuleStackIR moduleStackIR(wasm, options); - auto* func = wasm.getFunction("id"); - auto* stackIR = moduleStackIR.getStackIROrNull(func); - ASSERT_NE(stackIR, nullptr); - - // Build a StackIR sequence where $b takes an i32 param from the stack and - // adds it to a local.get inside the block: - // local.get $x - // local.set $tmp - // i32.const 10 ;; consumed as block param - // block $b (param i32) (result i32) - // local.get $tmp - // i32.add ;; consumes block param + $tmp - // i32.const 0 - // br_if $b - // end - Builder irBuilder(wasm); - auto* getX = irBuilder.makeLocalGet(0, Type::i32); - auto* setTmp = irBuilder.makeLocalSet(1, getX); - auto* c10 = irBuilder.makeConst(Literal(int32_t(10))); - auto* getTmp = irBuilder.makeLocalGet(1, Type::i32); - auto* add = irBuilder.makeBinary(AddInt32, c10, getTmp); - auto* c0 = irBuilder.makeConst(Literal(int32_t(0))); - auto* brIf = irBuilder.makeBreak("b", add, c0); - auto* block = irBuilder.makeBlock("b", {brIf}, Type::i32); - func->body = irBuilder.makeSequence(setTmp, block); - - auto makeInst = [&](StackInst::Op op, Expression* origin) { - auto* inst = wasm.allocator.alloc(); - inst->op = op; - inst->origin = origin; - inst->type = origin->type; - return inst; - }; - - auto* blockBegin = makeInst(StackInst::BlockBegin, block); - blockBegin->params = Type::i32; - auto* blockEnd = makeInst(StackInst::BlockEnd, block); - - *stackIR = { - makeInst(StackInst::Basic, getX), - makeInst(StackInst::Basic, setTmp), - makeInst(StackInst::Basic, c10), - blockBegin, - makeInst(StackInst::Basic, getTmp), - makeInst(StackInst::Basic, add), - makeInst(StackInst::Basic, c0), - makeInst(StackInst::Basic, brIf), - blockEnd, - }; - - // Run StackIROptimizer: local2Stack must see that blockBegin consumes c10 and - // pushes 1 parameter inside the block, so setTmp/getTmp cannot be eliminated - // across the block boundary, and i32.add consumes both the block param and - // getTmp without stack underflow. - StackIROptimizer optimizer(func, *stackIR, options, wasm.features); - optimizer.run(); - EXPECT_NE((*stackIR)[1], nullptr); - EXPECT_NE((*stackIR)[4], nullptr); - - // Also test binary emission via StackIRToBinaryWriter: the block header must - // emit the signature index for (param i32) (result i32). - BufferWithRandomAccess moduleBuf; - WasmBinaryWriter binaryWriter(&wasm, moduleBuf, options); - BufferWithRandomAccess funcBuf; - StackIRToBinaryWriter stackWriter(binaryWriter, funcBuf, func, *stackIR); - stackWriter.write(); - - // Verify the emitted bytes contain BinaryConsts::Block followed by the - // signature index of (param i32) (result i32). - auto sigIndex = - binaryWriter.getSignatureIndex(Signature(Type::i32, Type::i32)); - bool foundParameterizedBlock = false; - for (size_t i = 0; i + 1 < funcBuf.size(); ++i) { - if (funcBuf[i] == uint8_t(BinaryConsts::Block) && - funcBuf[i + 1] == uint8_t(sigIndex)) { - foundParameterizedBlock = true; - break; - } - } - EXPECT_TRUE(foundParameterizedBlock); -} diff --git a/test/lit/passes/optimize-stack-ir.wast b/test/lit/passes/optimize-stack-ir.wast index 0121312b2b5..fbac5f48cab 100644 --- a/test/lit/passes/optimize-stack-ir.wast +++ b/test/lit/passes/optimize-stack-ir.wast @@ -3,13 +3,15 @@ ;; RUN: wasm-opt %s -all --optimize-level=3 --generate-stack-ir --optimize-stack-ir --print-stack-ir | filecheck %s (module + ;; CHECK: (type $6 (func (param i32) (result i32))) + ;; CHECK: (type $FUNCSIG$v (func)) (type $FUNCSIG$v (func)) - ;; CHECK: (type $6 (func (param i32) (result i32))) - ;; CHECK: (type $5 (func (result i32))) + ;; CHECK: (type $3 (func (param i32 i32) (result i32))) + ;; CHECK: (type $FUNCSIG$vf (func (param f32))) (type $FUNCSIG$vf (func (param f32))) ;; CHECK: (type $4 (func (result f64))) @@ -20,6 +22,8 @@ ;; CHECK: (type $10 (func (param f32) (result f32))) + ;; CHECK: (type $11 (func (param i32))) + ;; CHECK: (type $FUNCSIG$id (func (param f64) (result i32))) (type $FUNCSIG$id (func (param f64) (result i32))) (type $FUNCSIG$ddd (func (param f64 f64) (result f64))) @@ -32,11 +36,19 @@ ;; CHECK: (type $9 (func (param i32 i64))) (type $9 (func (param i32 i64))) - ;; CHECK: (type $14 (func (param eqref) (result i32))) + ;; CHECK: (type $15 (func (param eqref) (result i32))) + + ;; CHECK: (type $16 (func (param eqref) (result eqref))) - ;; CHECK: (type $15 (func (param eqref) (result eqref))) + ;; CHECK: (type $17 (func (param stringref) (result i64))) - ;; CHECK: (type $16 (func (param stringref) (result i64))) + ;; CHECK: (type $18 (func (param i32 i64 f32) (result i32))) + + ;; CHECK: (type $19 (func (param i32 i32))) + + ;; CHECK: (type $20 (func (param i32 i64) (result i32))) + + ;; CHECK: (type $21 (func (param i32 f32) (result i32))) ;; CHECK: (import "env" "_emscripten_asm_const_vi" (func $_emscripten_asm_const_vi (type $FUNCSIG$v))) (import "env" "_emscripten_asm_const_vi" (func $_emscripten_asm_const_vi)) @@ -1488,7 +1500,7 @@ ) ;; A ref.eq with an intervening value: its operands can be swapped. - ;; CHECK: (func $local-to-stack-ref-eq (type $14) (param $x eqref) (result i32) + ;; CHECK: (func $local-to-stack-ref-eq (type $15) (param $x eqref) (result i32) ;; CHECK-NEXT: (local $temp eqref) ;; CHECK-NEXT: local.get $x ;; CHECK-NEXT: call $eqref-value @@ -1508,7 +1520,7 @@ ) ) - ;; CHECK: (func $eqref-value (type $15) (param $x eqref) (result eqref) + ;; CHECK: (func $eqref-value (type $16) (param $x eqref) (result eqref) ;; CHECK-NEXT: local.get $x ;; CHECK-NEXT: call $eqref-value ;; CHECK-NEXT: ) @@ -1609,7 +1621,7 @@ (local.get $y) ) - ;; CHECK: (func $null-string-encode (type $16) (param $str stringref) (result i64) + ;; CHECK: (func $null-string-encode (type $17) (param $str stringref) (result i64) ;; CHECK-NEXT: (local $y i64) ;; CHECK-NEXT: i64.const 1 ;; CHECK-NEXT: local.set $y @@ -1636,4 +1648,387 @@ ) (local.get $y) ) + + ;; CHECK: (func $local-to-stack-block-param-single (type $6) (param $cond i32) (result i32) + ;; CHECK-NEXT: (local $x i32) + ;; CHECK-NEXT: local.get $cond + ;; CHECK-NEXT: i32.const 10 + ;; CHECK-NEXT: i32.add + ;; CHECK-NEXT: block $b (type $6) (param i32) (result i32) + ;; CHECK-NEXT: i32.eqz + ;; CHECK-NEXT: if + ;; CHECK-NEXT: i32.const 42 + ;; CHECK-NEXT: br $b + ;; CHECK-NEXT: end + ;; CHECK-NEXT: i32.const 99 + ;; CHECK-NEXT: end + ;; CHECK-NEXT: ) + (func $local-to-stack-block-param-single (param $cond i32) (result i32) + (local $x i32) + ;; A single local.set before a targeted block can be threaded into the + ;; block as a block input parameter. + (local.set $x + (i32.add + (local.get $cond) + (i32.const 10) + ) + ) + (block $b (result i32) + (if + (i32.eqz + (local.get $x) + ) + (then + (br $b + (i32.const 42) + ) + ) + ) + (i32.const 99) + ) + ) + + ;; CHECK: (func $local-to-stack-block-param-two (type $3) (param $a i32) (param $b i32) (result i32) + ;; CHECK-NEXT: (local $x i32) + ;; CHECK-NEXT: (local $y i32) + ;; CHECK-NEXT: local.get $a + ;; CHECK-NEXT: i32.const 1 + ;; CHECK-NEXT: i32.add + ;; CHECK-NEXT: local.get $b + ;; CHECK-NEXT: i32.const 2 + ;; CHECK-NEXT: i32.add + ;; CHECK-NEXT: block $out (type $3) (param i32 i32) (result i32) + ;; CHECK-NEXT: block $in (type $19) (param i32 i32) + ;; CHECK-NEXT: i32.add + ;; CHECK-NEXT: br_if $in + ;; CHECK-NEXT: i32.const 7 + ;; CHECK-NEXT: br $out + ;; CHECK-NEXT: end + ;; CHECK-NEXT: i32.const 8 + ;; CHECK-NEXT: end + ;; CHECK-NEXT: ) + (func $local-to-stack-block-param-two (param $a i32) (param $b i32) (result i32) + (local $x i32) + (local $y i32) + ;; Two local.sets before nested targeted blocks can be threaded into both + ;; blocks as (param i32 i32). + (local.set $x + (i32.add + (local.get $a) + (i32.const 1) + ) + ) + (local.set $y + (i32.add + (local.get $b) + (i32.const 2) + ) + ) + (block $out (result i32) + (block $in + (br_if $in + (i32.add + (local.get $x) + (local.get $y) + ) + ) + (br $out + (i32.const 7) + ) + ) + (i32.const 8) + ) + ) + + ;; CHECK: (func $local-to-stack-block-param-reversed-symmetric (type $3) (param $a i32) (param $b i32) (result i32) + ;; CHECK-NEXT: (local $x i32) + ;; CHECK-NEXT: (local $y i32) + ;; CHECK-NEXT: local.get $a + ;; CHECK-NEXT: i32.const 1 + ;; CHECK-NEXT: i32.add + ;; CHECK-NEXT: local.get $b + ;; CHECK-NEXT: i32.const 2 + ;; CHECK-NEXT: i32.sub + ;; CHECK-NEXT: block $b (type $3) (param i32 i32) (result i32) + ;; CHECK-NEXT: i32.add + ;; CHECK-NEXT: if + ;; CHECK-NEXT: i32.const 10 + ;; CHECK-NEXT: br $b + ;; CHECK-NEXT: end + ;; CHECK-NEXT: i32.const 20 + ;; CHECK-NEXT: end + ;; CHECK-NEXT: ) + (func $local-to-stack-block-param-reversed-symmetric (param $a i32) (param $b i32) (result i32) + (local $x i32) + (local $y i32) + ;; Even when the gets inside the block are read in reverse order ($y then + ;; $x), a symmetric op (i32.add) allows threading both sets as block + ;; parameters in stack push order ($x then $y). + (local.set $x + (i32.add + (local.get $a) + (i32.const 1) + ) + ) + (local.set $y + (i32.sub + (local.get $b) + (i32.const 2) + ) + ) + (block $b (result i32) + (if + (i32.add + (local.get $y) + (local.get $x) + ) + (then + (br $b + (i32.const 10) + ) + ) + ) + (i32.const 20) + ) + ) + + ;; CHECK: (func $local-to-stack-block-param-outer-survives (type $3) (param $a i32) (param $b i32) (result i32) + ;; CHECK-NEXT: (local $z i32) + ;; CHECK-NEXT: (local $x i32) + ;; CHECK-NEXT: local.get $a + ;; CHECK-NEXT: i32.const 1 + ;; CHECK-NEXT: i32.add + ;; CHECK-NEXT: local.get $b + ;; CHECK-NEXT: i32.const 2 + ;; CHECK-NEXT: i32.add + ;; CHECK-NEXT: block $in (type $11) (param i32) + ;; CHECK-NEXT: br_if $in + ;; CHECK-NEXT: end + ;; CHECK-NEXT: ) + (func $local-to-stack-block-param-outer-survives (param $a i32) (param $b i32) (result i32) + (local $z i32) + (local $x i32) + ;; $z is pushed before $x. Threading $x into $in leaves $z underneath on + ;; the outer stack, so $z can still be moved to the stack after $in ends. + (local.set $z + (i32.add + (local.get $a) + (i32.const 1) + ) + ) + (local.set $x + (i32.add + (local.get $b) + (i32.const 2) + ) + ) + (block $in + (br_if $in + (local.get $x) + ) + ) + (local.get $z) + ) + + ;; CHECK: (func $local-to-stack-block-param-outer-blocked (type $3) (param $a i32) (param $b i32) (result i32) + ;; CHECK-NEXT: (local $x i32) + ;; CHECK-NEXT: (local $z i32) + ;; CHECK-NEXT: local.get $a + ;; CHECK-NEXT: i32.const 1 + ;; CHECK-NEXT: i32.add + ;; CHECK-NEXT: local.get $b + ;; CHECK-NEXT: i32.const 2 + ;; CHECK-NEXT: i32.add + ;; CHECK-NEXT: local.set $z + ;; CHECK-NEXT: block $in (type $11) (param i32) + ;; CHECK-NEXT: br_if $in + ;; CHECK-NEXT: end + ;; CHECK-NEXT: local.get $z + ;; CHECK-NEXT: ) + (func $local-to-stack-block-param-outer-blocked (param $a i32) (param $b i32) (result i32) + (local $x i32) + (local $z i32) + ;; $z is pushed after $x. Once $x is threaded into $in, $z cannot be left + ;; on the stack across $in (or it would sit above $x at BlockBegin and be + ;; consumed by $in instead of $x), so $z must remain in a local. + (local.set $x + (i32.add + (local.get $a) + (i32.const 1) + ) + ) + (local.set $z + (i32.add + (local.get $b) + (i32.const 2) + ) + ) + (block $in + (br_if $in + (local.get $x) + ) + ) + (local.get $z) + ) + + ;; CHECK: (func $local-to-stack-block-param-deep-nested (type $6) (param $a i32) (result i32) + ;; CHECK-NEXT: (local $x i32) + ;; CHECK-NEXT: local.get $a + ;; CHECK-NEXT: i32.const 1 + ;; CHECK-NEXT: i32.add + ;; CHECK-NEXT: block $b1 (type $6) (param i32) (result i32) + ;; CHECK-NEXT: block $b2 (type $6) (param i32) (result i32) + ;; CHECK-NEXT: block $b3 (type $6) (param i32) (result i32) + ;; CHECK-NEXT: block $b4 (type $6) (param i32) (result i32) + ;; CHECK-NEXT: if + ;; CHECK-NEXT: i32.const 1 + ;; CHECK-NEXT: br $b1 + ;; CHECK-NEXT: end + ;; CHECK-NEXT: local.get $a + ;; CHECK-NEXT: if + ;; CHECK-NEXT: i32.const 2 + ;; CHECK-NEXT: br $b2 + ;; CHECK-NEXT: end + ;; CHECK-NEXT: local.get $a + ;; CHECK-NEXT: if + ;; CHECK-NEXT: i32.const 3 + ;; CHECK-NEXT: br $b3 + ;; CHECK-NEXT: end + ;; CHECK-NEXT: i32.const 4 + ;; CHECK-NEXT: br $b4 + ;; CHECK-NEXT: end + ;; CHECK-NEXT: end + ;; CHECK-NEXT: end + ;; CHECK-NEXT: end + ;; CHECK-NEXT: ) + (func $local-to-stack-block-param-deep-nested (param $a i32) (result i32) + (local $x i32) + ;; A local.set can be threaded across an arbitrary chain of nested targeted + ;; blocks. + (local.set $x + (i32.add + (local.get $a) + (i32.const 1) + ) + ) + (block $b1 (result i32) + (block $b2 (result i32) + (block $b3 (result i32) + (block $b4 (result i32) + (if + (local.get $x) + (then + (br $b1 (i32.const 1)) + ) + ) + (if + (local.get $a) + (then + (br $b2 (i32.const 2)) + ) + ) + (if + (local.get $a) + (then + (br $b3 (i32.const 3)) + ) + ) + (br $b4 (i32.const 4)) + ) + ) + ) + ) + ) + + ;; CHECK: (func $local-to-stack-block-param-deep-varying (type $18) (param $a i32) (param $b i64) (param $c f32) (result i32) + ;; CHECK-NEXT: (local $x i32) + ;; CHECK-NEXT: (local $y i64) + ;; CHECK-NEXT: (local $z f32) + ;; CHECK-NEXT: local.get $a + ;; CHECK-NEXT: i32.const 1 + ;; CHECK-NEXT: i32.add + ;; CHECK-NEXT: block $b1 (type $6) (param i32) (result i32) + ;; CHECK-NEXT: local.get $b + ;; CHECK-NEXT: i64.const 2 + ;; CHECK-NEXT: i64.add + ;; CHECK-NEXT: block $b2 (type $20) (param i32 i64) (result i32) + ;; CHECK-NEXT: i32.wrap_i64 + ;; CHECK-NEXT: if + ;; CHECK-NEXT: i32.const 10 + ;; CHECK-NEXT: br $b2 + ;; CHECK-NEXT: end + ;; CHECK-NEXT: local.get $c + ;; CHECK-NEXT: f32.const 3 + ;; CHECK-NEXT: f32.add + ;; CHECK-NEXT: block $b3 (type $21) (param i32 f32) (result i32) + ;; CHECK-NEXT: f32.const 0 + ;; CHECK-NEXT: f32.gt + ;; CHECK-NEXT: if + ;; CHECK-NEXT: i32.const 20 + ;; CHECK-NEXT: br $b1 + ;; CHECK-NEXT: end + ;; CHECK-NEXT: if + ;; CHECK-NEXT: i32.const 30 + ;; CHECK-NEXT: br $b3 + ;; CHECK-NEXT: end + ;; CHECK-NEXT: i32.const 40 + ;; CHECK-NEXT: end + ;; CHECK-NEXT: end + ;; CHECK-NEXT: end + ;; CHECK-NEXT: ) + (func $local-to-stack-block-param-deep-varying (param $a i32) (param $b i64) (param $c f32) (result i32) + (local $x i32) + (local $y i64) + (local $z f32) + ;; Nested blocks receive different parameter lists as sets are pushed and + ;; consumed at intermediate depths. + (local.set $x + (i32.add + (local.get $a) + (i32.const 1) + ) + ) + (block $b1 (result i32) + (local.set $y + (i64.add + (local.get $b) + (i64.const 2) + ) + ) + (block $b2 (result i32) + (if + (i32.wrap_i64 + (local.get $y) + ) + (then + (br $b2 (i32.const 10)) + ) + ) + (local.set $z + (f32.add + (local.get $c) + (f32.const 3) + ) + ) + (block $b3 (result i32) + (if + (f32.gt + (local.get $z) + (f32.const 0) + ) + (then + (br $b1 (i32.const 20)) + ) + ) + (if + (local.get $x) + (then + (br $b3 (i32.const 30)) + ) + ) + (i32.const 40) + ) + ) + ) + ) ) diff --git a/test/lit/passes/stack-ir-roundtrip-params.wast b/test/lit/passes/stack-ir-roundtrip-params.wast new file mode 100644 index 00000000000..b523bad8f06 --- /dev/null +++ b/test/lit/passes/stack-ir-roundtrip-params.wast @@ -0,0 +1,908 @@ +;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. + +;; Check that block parameters emitted by StackIR round-trip cleanly through +;; IRBuilder without introducing extra scratch locals or wrapper blocks, and +;; that re-emitting StackIR after round-tripping reproduces the same +;; parameterized blocks. + +;; RUN: wasm-opt %s -all --optimize-level=3 --generate-stack-ir --optimize-stack-ir --print-stack-ir | filecheck %s --check-prefix=STACK-IR +;; RUN: wasm-opt %s -all --optimize-level=3 --generate-stack-ir --optimize-stack-ir --roundtrip -S -o - | filecheck %s --check-prefix=RTRIP-IR +;; RUN: wasm-opt %s -all --optimize-level=3 --generate-stack-ir --optimize-stack-ir --roundtrip --print-stack-ir | filecheck %s --check-prefix=RTRIP-STACK-IR + +(module + ;; STACK-IR: (type $0 (func (param i32 i32) (result i32))) + + ;; STACK-IR: (type $struct (struct)) + ;; RTRIP-IR: (type $struct (struct)) + ;; RTRIP-STACK-IR: (type $struct (struct)) + (type $struct (struct)) + ;; STACK-IR: (type $2 (func (param i32) (result i32))) + + ;; STACK-IR: (type $3 (func (param i32 i64) (result i32))) + + ;; STACK-IR: (type $4 (func (param i32 i64))) + + ;; STACK-IR: (type $5 (func (param (ref $struct) i32) (result (ref $struct)))) + + ;; STACK-IR: (type $6 (func (param i32 i64 f32) (result i32))) + + ;; STACK-IR: (type $7 (func (param i32))) + + ;; STACK-IR: (type $8 (func (param (ref $struct)) (result (ref $struct)))) + + ;; STACK-IR: (type $9 (func (param i32 f32) (result i32))) + + ;; STACK-IR: (func $single-block-param (type $2) (param $a i32) (result i32) + ;; STACK-IR-NEXT: (local $x i32) + ;; STACK-IR-NEXT: local.get $a + ;; STACK-IR-NEXT: i32.const 1 + ;; STACK-IR-NEXT: i32.add + ;; STACK-IR-NEXT: block $b (type $2) (param i32) (result i32) + ;; STACK-IR-NEXT: i32.eqz + ;; STACK-IR-NEXT: if + ;; STACK-IR-NEXT: i32.const 10 + ;; STACK-IR-NEXT: br $b + ;; STACK-IR-NEXT: end + ;; STACK-IR-NEXT: i32.const 20 + ;; STACK-IR-NEXT: end + ;; STACK-IR-NEXT: ) + ;; RTRIP-IR: (type $1 (func (param i32 i32) (result i32))) + + ;; RTRIP-IR: (type $2 (func (param i32) (result i32))) + + ;; RTRIP-IR: (type $3 (func (param i32 i64) (result i32))) + + ;; RTRIP-IR: (type $4 (func (param (ref $struct) i32) (result (ref $struct)))) + + ;; RTRIP-IR: (type $5 (func (param i32 i64 f32) (result i32))) + + ;; RTRIP-IR: (func $single-block-param (type $2) (param $a i32) (result i32) + ;; RTRIP-IR-NEXT: (local $x i32) + ;; RTRIP-IR-NEXT: (local $scratch i32) + ;; RTRIP-IR-NEXT: (local.set $scratch + ;; RTRIP-IR-NEXT: (i32.add + ;; RTRIP-IR-NEXT: (local.get $a) + ;; RTRIP-IR-NEXT: (i32.const 1) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: (block $b (result i32) + ;; RTRIP-IR-NEXT: (if + ;; RTRIP-IR-NEXT: (i32.eqz + ;; RTRIP-IR-NEXT: (local.get $scratch) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: (then + ;; RTRIP-IR-NEXT: (br $b + ;; RTRIP-IR-NEXT: (i32.const 10) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: (i32.const 20) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-STACK-IR: (type $1 (func (param i32 i32) (result i32))) + + ;; RTRIP-STACK-IR: (type $2 (func (param i32) (result i32))) + + ;; RTRIP-STACK-IR: (type $3 (func (param i32 i64) (result i32))) + + ;; RTRIP-STACK-IR: (type $4 (func (param i32 i64))) + + ;; RTRIP-STACK-IR: (type $5 (func (param (ref $struct) i32) (result (ref $struct)))) + + ;; RTRIP-STACK-IR: (type $6 (func (param i32 i64 f32) (result i32))) + + ;; RTRIP-STACK-IR: (type $7 (func (param i32))) + + ;; RTRIP-STACK-IR: (type $8 (func (param (ref $struct)) (result (ref $struct)))) + + ;; RTRIP-STACK-IR: (type $9 (func (param i32 f32) (result i32))) + + ;; RTRIP-STACK-IR: (func $single-block-param (type $2) (param $a i32) (result i32) + ;; RTRIP-STACK-IR-NEXT: (local $x i32) + ;; RTRIP-STACK-IR-NEXT: (local $scratch i32) + ;; RTRIP-STACK-IR-NEXT: local.get $a + ;; RTRIP-STACK-IR-NEXT: i32.const 1 + ;; RTRIP-STACK-IR-NEXT: i32.add + ;; RTRIP-STACK-IR-NEXT: block $b (type $2) (param i32) (result i32) + ;; RTRIP-STACK-IR-NEXT: i32.eqz + ;; RTRIP-STACK-IR-NEXT: if + ;; RTRIP-STACK-IR-NEXT: i32.const 10 + ;; RTRIP-STACK-IR-NEXT: br $b + ;; RTRIP-STACK-IR-NEXT: end + ;; RTRIP-STACK-IR-NEXT: i32.const 20 + ;; RTRIP-STACK-IR-NEXT: end + ;; RTRIP-STACK-IR-NEXT: ) + (func $single-block-param (param $a i32) (result i32) + ;; A single value threaded into a block parameter round-trips using a single + ;; scalar scratch local and re-emits the same parameterized block. + (local $x i32) + (local.set $x + (i32.add + (local.get $a) + (i32.const 1) + ) + ) + (block $b (result i32) + (if + (i32.eqz + (local.get $x) + ) + (then + (br $b + (i32.const 10) + ) + ) + ) + (i32.const 20) + ) + ) + + ;; STACK-IR: (func $nested-blocks-tunnel-two-params (type $3) (param $a i32) (param $b i64) (result i32) + ;; STACK-IR-NEXT: (local $x i32) + ;; STACK-IR-NEXT: (local $y i64) + ;; STACK-IR-NEXT: local.get $a + ;; STACK-IR-NEXT: i32.const 1 + ;; STACK-IR-NEXT: i32.add + ;; STACK-IR-NEXT: local.get $b + ;; STACK-IR-NEXT: i64.const 2 + ;; STACK-IR-NEXT: i64.add + ;; STACK-IR-NEXT: block $b1 (type $3) (param i32 i64) (result i32) + ;; STACK-IR-NEXT: block $b2 (type $4) (param i32 i64) + ;; STACK-IR-NEXT: block $b3 (type $4) (param i32 i64) + ;; STACK-IR-NEXT: i32.wrap_i64 + ;; STACK-IR-NEXT: i32.add + ;; STACK-IR-NEXT: br_if $b3 + ;; STACK-IR-NEXT: br $b2 + ;; STACK-IR-NEXT: end + ;; STACK-IR-NEXT: i32.const 10 + ;; STACK-IR-NEXT: br $b1 + ;; STACK-IR-NEXT: end + ;; STACK-IR-NEXT: i32.const 20 + ;; STACK-IR-NEXT: end + ;; STACK-IR-NEXT: ) + ;; RTRIP-IR: (func $nested-blocks-tunnel-two-params (type $3) (param $a i32) (param $b i64) (result i32) + ;; RTRIP-IR-NEXT: (local $x i32) + ;; RTRIP-IR-NEXT: (local $y i64) + ;; RTRIP-IR-NEXT: (local $scratch i32) + ;; RTRIP-IR-NEXT: (local $scratch_5 i64) + ;; RTRIP-IR-NEXT: (local.set $scratch + ;; RTRIP-IR-NEXT: (i32.add + ;; RTRIP-IR-NEXT: (local.get $a) + ;; RTRIP-IR-NEXT: (i32.const 1) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: (local.set $scratch_5 + ;; RTRIP-IR-NEXT: (i64.add + ;; RTRIP-IR-NEXT: (local.get $b) + ;; RTRIP-IR-NEXT: (i64.const 2) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: (block $b1 (result i32) + ;; RTRIP-IR-NEXT: (block $b2 + ;; RTRIP-IR-NEXT: (block $b3 + ;; RTRIP-IR-NEXT: (br_if $b3 + ;; RTRIP-IR-NEXT: (i32.add + ;; RTRIP-IR-NEXT: (local.get $scratch) + ;; RTRIP-IR-NEXT: (i32.wrap_i64 + ;; RTRIP-IR-NEXT: (local.get $scratch_5) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: (br $b2) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: (br $b1 + ;; RTRIP-IR-NEXT: (i32.const 10) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: (i32.const 20) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-STACK-IR: (func $nested-blocks-tunnel-two-params (type $3) (param $a i32) (param $b i64) (result i32) + ;; RTRIP-STACK-IR-NEXT: (local $x i32) + ;; RTRIP-STACK-IR-NEXT: (local $y i64) + ;; RTRIP-STACK-IR-NEXT: (local $scratch i32) + ;; RTRIP-STACK-IR-NEXT: (local $scratch_5 i64) + ;; RTRIP-STACK-IR-NEXT: local.get $a + ;; RTRIP-STACK-IR-NEXT: i32.const 1 + ;; RTRIP-STACK-IR-NEXT: i32.add + ;; RTRIP-STACK-IR-NEXT: local.get $b + ;; RTRIP-STACK-IR-NEXT: i64.const 2 + ;; RTRIP-STACK-IR-NEXT: i64.add + ;; RTRIP-STACK-IR-NEXT: block $b1 (type $3) (param i32 i64) (result i32) + ;; RTRIP-STACK-IR-NEXT: block $b2 (type $4) (param i32 i64) + ;; RTRIP-STACK-IR-NEXT: block $b3 (type $4) (param i32 i64) + ;; RTRIP-STACK-IR-NEXT: i32.wrap_i64 + ;; RTRIP-STACK-IR-NEXT: i32.add + ;; RTRIP-STACK-IR-NEXT: br_if $b3 + ;; RTRIP-STACK-IR-NEXT: br $b2 + ;; RTRIP-STACK-IR-NEXT: end + ;; RTRIP-STACK-IR-NEXT: i32.const 10 + ;; RTRIP-STACK-IR-NEXT: br $b1 + ;; RTRIP-STACK-IR-NEXT: end + ;; RTRIP-STACK-IR-NEXT: i32.const 20 + ;; RTRIP-STACK-IR-NEXT: end + ;; RTRIP-STACK-IR-NEXT: ) + (func $nested-blocks-tunnel-two-params (param $a i32) (param $b i64) (result i32) + ;; Multiple values threaded through nested blocks round-trip using one + ;; scalar scratch local per input (no tuple locals or per-block copies) by + ;; tunneling the outer scratch locals through the inner blocks. + (local $x i32) + (local $y i64) + (local.set $x + (i32.add + (local.get $a) + (i32.const 1) + ) + ) + (local.set $y + (i64.add + (local.get $b) + (i64.const 2) + ) + ) + (block $b1 (result i32) + (block $b2 + (block $b3 + (br_if $b3 + (i32.add + (local.get $x) + (i32.wrap_i64 + (local.get $y) + ) + ) + ) + (br $b2) + ) + (br $b1 + (i32.const 10) + ) + ) + (i32.const 20) + ) + ) + + ;; STACK-IR: (func $nested-blocks-hoist-across-none (type $0) (param $a i32) (param $b i32) (result i32) + ;; STACK-IR-NEXT: (local $x i32) + ;; STACK-IR-NEXT: (local $y i32) + ;; STACK-IR-NEXT: local.get $a + ;; STACK-IR-NEXT: i32.const 1 + ;; STACK-IR-NEXT: i32.add + ;; STACK-IR-NEXT: local.get $b + ;; STACK-IR-NEXT: i32.const 2 + ;; STACK-IR-NEXT: i32.add + ;; STACK-IR-NEXT: block $b1 (type $0) (param i32 i32) (result i32) + ;; STACK-IR-NEXT: local.get $a + ;; STACK-IR-NEXT: if + ;; STACK-IR-NEXT: i32.const 10 + ;; STACK-IR-NEXT: br $b1 + ;; STACK-IR-NEXT: end + ;; STACK-IR-NEXT: block $b2 (type $0) (param i32 i32) (result i32) + ;; STACK-IR-NEXT: local.get $b + ;; STACK-IR-NEXT: if + ;; STACK-IR-NEXT: i32.const 20 + ;; STACK-IR-NEXT: br $b2 + ;; STACK-IR-NEXT: end + ;; STACK-IR-NEXT: block $b3 (type $0) (param i32 i32) (result i32) + ;; STACK-IR-NEXT: local.get $a + ;; STACK-IR-NEXT: i32.eqz + ;; STACK-IR-NEXT: if + ;; STACK-IR-NEXT: i32.const 30 + ;; STACK-IR-NEXT: br $b3 + ;; STACK-IR-NEXT: end + ;; STACK-IR-NEXT: i32.add + ;; STACK-IR-NEXT: end + ;; STACK-IR-NEXT: end + ;; STACK-IR-NEXT: end + ;; STACK-IR-NEXT: ) + ;; RTRIP-IR: (func $nested-blocks-hoist-across-none (type $1) (param $a i32) (param $b i32) (result i32) + ;; RTRIP-IR-NEXT: (local $x i32) + ;; RTRIP-IR-NEXT: (local $y i32) + ;; RTRIP-IR-NEXT: (local $scratch i32) + ;; RTRIP-IR-NEXT: (local $scratch_5 i32) + ;; RTRIP-IR-NEXT: (local.set $scratch + ;; RTRIP-IR-NEXT: (i32.add + ;; RTRIP-IR-NEXT: (local.get $a) + ;; RTRIP-IR-NEXT: (i32.const 1) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: (local.set $scratch_5 + ;; RTRIP-IR-NEXT: (i32.add + ;; RTRIP-IR-NEXT: (local.get $b) + ;; RTRIP-IR-NEXT: (i32.const 2) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: (block $b1 (result i32) + ;; RTRIP-IR-NEXT: (if + ;; RTRIP-IR-NEXT: (local.get $a) + ;; RTRIP-IR-NEXT: (then + ;; RTRIP-IR-NEXT: (br $b1 + ;; RTRIP-IR-NEXT: (i32.const 10) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: (block $b2 (result i32) + ;; RTRIP-IR-NEXT: (if + ;; RTRIP-IR-NEXT: (local.get $b) + ;; RTRIP-IR-NEXT: (then + ;; RTRIP-IR-NEXT: (br $b2 + ;; RTRIP-IR-NEXT: (i32.const 20) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: (block $b3 (result i32) + ;; RTRIP-IR-NEXT: (if + ;; RTRIP-IR-NEXT: (i32.eqz + ;; RTRIP-IR-NEXT: (local.get $a) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: (then + ;; RTRIP-IR-NEXT: (br $b3 + ;; RTRIP-IR-NEXT: (i32.const 30) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: (i32.add + ;; RTRIP-IR-NEXT: (local.get $scratch) + ;; RTRIP-IR-NEXT: (local.get $scratch_5) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-STACK-IR: (func $nested-blocks-hoist-across-none (type $1) (param $a i32) (param $b i32) (result i32) + ;; RTRIP-STACK-IR-NEXT: (local $x i32) + ;; RTRIP-STACK-IR-NEXT: (local $y i32) + ;; RTRIP-STACK-IR-NEXT: (local $scratch i32) + ;; RTRIP-STACK-IR-NEXT: (local $scratch_5 i32) + ;; RTRIP-STACK-IR-NEXT: local.get $a + ;; RTRIP-STACK-IR-NEXT: i32.const 1 + ;; RTRIP-STACK-IR-NEXT: i32.add + ;; RTRIP-STACK-IR-NEXT: local.get $b + ;; RTRIP-STACK-IR-NEXT: i32.const 2 + ;; RTRIP-STACK-IR-NEXT: i32.add + ;; RTRIP-STACK-IR-NEXT: block $b1 (type $1) (param i32 i32) (result i32) + ;; RTRIP-STACK-IR-NEXT: local.get $a + ;; RTRIP-STACK-IR-NEXT: if + ;; RTRIP-STACK-IR-NEXT: i32.const 10 + ;; RTRIP-STACK-IR-NEXT: br $b1 + ;; RTRIP-STACK-IR-NEXT: end + ;; RTRIP-STACK-IR-NEXT: block $b2 (type $1) (param i32 i32) (result i32) + ;; RTRIP-STACK-IR-NEXT: local.get $b + ;; RTRIP-STACK-IR-NEXT: if + ;; RTRIP-STACK-IR-NEXT: i32.const 20 + ;; RTRIP-STACK-IR-NEXT: br $b2 + ;; RTRIP-STACK-IR-NEXT: end + ;; RTRIP-STACK-IR-NEXT: block $b3 (type $1) (param i32 i32) (result i32) + ;; RTRIP-STACK-IR-NEXT: local.get $a + ;; RTRIP-STACK-IR-NEXT: i32.eqz + ;; RTRIP-STACK-IR-NEXT: if + ;; RTRIP-STACK-IR-NEXT: i32.const 30 + ;; RTRIP-STACK-IR-NEXT: br $b3 + ;; RTRIP-STACK-IR-NEXT: end + ;; RTRIP-STACK-IR-NEXT: i32.add + ;; RTRIP-STACK-IR-NEXT: end + ;; RTRIP-STACK-IR-NEXT: end + ;; RTRIP-STACK-IR-NEXT: end + ;; RTRIP-STACK-IR-NEXT: ) + (func $nested-blocks-hoist-across-none (param $a i32) (param $b i32) (result i32) + ;; None-typed instructions before nested parameterized blocks or before + ;; consuming block inputs hoist the input local.gets directly without + ;; allocating extra scratch locals or synthetic wrapper blocks. + (local $x i32) + (local $y i32) + (local.set $x + (i32.add + (local.get $a) + (i32.const 1) + ) + ) + (local.set $y + (i32.add + (local.get $b) + (i32.const 2) + ) + ) + (block $b1 (result i32) + (if + (local.get $a) + (then + (br $b1 + (i32.const 10) + ) + ) + ) + (block $b2 (result i32) + (if + (local.get $b) + (then + (br $b2 + (i32.const 20) + ) + ) + ) + (block $b3 (result i32) + (if + (i32.eqz + (local.get $a) + ) + (then + (br $b3 + (i32.const 30) + ) + ) + ) + (i32.add + (local.get $x) + (local.get $y) + ) + ) + ) + ) + ) + + ;; STACK-IR: (func $nested-blocks-partial-tunnel (type $0) (param $a i32) (param $b i32) (result i32) + ;; STACK-IR-NEXT: (local $x i32) + ;; STACK-IR-NEXT: (local $y i32) + ;; STACK-IR-NEXT: local.get $a + ;; STACK-IR-NEXT: i32.const 1 + ;; STACK-IR-NEXT: i32.add + ;; STACK-IR-NEXT: local.get $b + ;; STACK-IR-NEXT: i32.const 2 + ;; STACK-IR-NEXT: i32.add + ;; STACK-IR-NEXT: block $b1 (type $0) (param i32 i32) (result i32) + ;; STACK-IR-NEXT: if + ;; STACK-IR-NEXT: i32.const 10 + ;; STACK-IR-NEXT: br $b1 + ;; STACK-IR-NEXT: end + ;; STACK-IR-NEXT: block $b2 (type $2) (param i32) (result i32) + ;; STACK-IR-NEXT: if + ;; STACK-IR-NEXT: i32.const 20 + ;; STACK-IR-NEXT: br $b2 + ;; STACK-IR-NEXT: end + ;; STACK-IR-NEXT: i32.const 30 + ;; STACK-IR-NEXT: end + ;; STACK-IR-NEXT: end + ;; STACK-IR-NEXT: ) + ;; RTRIP-IR: (func $nested-blocks-partial-tunnel (type $1) (param $a i32) (param $b i32) (result i32) + ;; RTRIP-IR-NEXT: (local $x i32) + ;; RTRIP-IR-NEXT: (local $y i32) + ;; RTRIP-IR-NEXT: (local $scratch i32) + ;; RTRIP-IR-NEXT: (local $scratch_5 i32) + ;; RTRIP-IR-NEXT: (local.set $scratch + ;; RTRIP-IR-NEXT: (i32.add + ;; RTRIP-IR-NEXT: (local.get $a) + ;; RTRIP-IR-NEXT: (i32.const 1) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: (local.set $scratch_5 + ;; RTRIP-IR-NEXT: (i32.add + ;; RTRIP-IR-NEXT: (local.get $b) + ;; RTRIP-IR-NEXT: (i32.const 2) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: (block $b1 (result i32) + ;; RTRIP-IR-NEXT: (if + ;; RTRIP-IR-NEXT: (local.get $scratch_5) + ;; RTRIP-IR-NEXT: (then + ;; RTRIP-IR-NEXT: (br $b1 + ;; RTRIP-IR-NEXT: (i32.const 10) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: (block $b2 (result i32) + ;; RTRIP-IR-NEXT: (if + ;; RTRIP-IR-NEXT: (local.get $scratch) + ;; RTRIP-IR-NEXT: (then + ;; RTRIP-IR-NEXT: (br $b2 + ;; RTRIP-IR-NEXT: (i32.const 20) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: (i32.const 30) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-STACK-IR: (func $nested-blocks-partial-tunnel (type $1) (param $a i32) (param $b i32) (result i32) + ;; RTRIP-STACK-IR-NEXT: (local $x i32) + ;; RTRIP-STACK-IR-NEXT: (local $y i32) + ;; RTRIP-STACK-IR-NEXT: (local $scratch i32) + ;; RTRIP-STACK-IR-NEXT: (local $scratch_5 i32) + ;; RTRIP-STACK-IR-NEXT: local.get $a + ;; RTRIP-STACK-IR-NEXT: i32.const 1 + ;; RTRIP-STACK-IR-NEXT: i32.add + ;; RTRIP-STACK-IR-NEXT: local.get $b + ;; RTRIP-STACK-IR-NEXT: i32.const 2 + ;; RTRIP-STACK-IR-NEXT: i32.add + ;; RTRIP-STACK-IR-NEXT: block $b1 (type $1) (param i32 i32) (result i32) + ;; RTRIP-STACK-IR-NEXT: if + ;; RTRIP-STACK-IR-NEXT: i32.const 10 + ;; RTRIP-STACK-IR-NEXT: br $b1 + ;; RTRIP-STACK-IR-NEXT: end + ;; RTRIP-STACK-IR-NEXT: block $b2 (type $2) (param i32) (result i32) + ;; RTRIP-STACK-IR-NEXT: if + ;; RTRIP-STACK-IR-NEXT: i32.const 20 + ;; RTRIP-STACK-IR-NEXT: br $b2 + ;; RTRIP-STACK-IR-NEXT: end + ;; RTRIP-STACK-IR-NEXT: i32.const 30 + ;; RTRIP-STACK-IR-NEXT: end + ;; RTRIP-STACK-IR-NEXT: end + ;; RTRIP-STACK-IR-NEXT: ) + (func $nested-blocks-partial-tunnel (param $a i32) (param $b i32) (result i32) + ;; When an outer block consumes its top parameter ($y) in a none-typed + ;; instruction and threads its deeper parameter ($x) into an inner block, + ;; round-tripping hoists and tunnels $x without extra scratch locals. + (local $x i32) + (local $y i32) + (local.set $x + (i32.add + (local.get $a) + (i32.const 1) + ) + ) + (local.set $y + (i32.add + (local.get $b) + (i32.const 2) + ) + ) + (block $b1 (result i32) + (if + (local.get $y) + (then + (br $b1 + (i32.const 10) + ) + ) + ) + (block $b2 (result i32) + (if + (local.get $x) + (then + (br $b2 + (i32.const 20) + ) + ) + ) + (i32.const 30) + ) + ) + ) + + ;; STACK-IR: (func $outer-stack-survives (type $0) (param $a i32) (param $b i32) (result i32) + ;; STACK-IR-NEXT: (local $z i32) + ;; STACK-IR-NEXT: (local $x i32) + ;; STACK-IR-NEXT: local.get $a + ;; STACK-IR-NEXT: i32.const 1 + ;; STACK-IR-NEXT: i32.add + ;; STACK-IR-NEXT: local.get $b + ;; STACK-IR-NEXT: i32.const 2 + ;; STACK-IR-NEXT: i32.add + ;; STACK-IR-NEXT: block $in (type $7) (param i32) + ;; STACK-IR-NEXT: br_if $in + ;; STACK-IR-NEXT: end + ;; STACK-IR-NEXT: ) + ;; RTRIP-IR: (func $outer-stack-survives (type $1) (param $a i32) (param $b i32) (result i32) + ;; RTRIP-IR-NEXT: (local $z i32) + ;; RTRIP-IR-NEXT: (local $x i32) + ;; RTRIP-IR-NEXT: (local $scratch i32) + ;; RTRIP-IR-NEXT: (local $scratch_5 i32) + ;; RTRIP-IR-NEXT: (local.set $scratch_5 + ;; RTRIP-IR-NEXT: (i32.add + ;; RTRIP-IR-NEXT: (local.get $a) + ;; RTRIP-IR-NEXT: (i32.const 1) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: (local.set $scratch + ;; RTRIP-IR-NEXT: (i32.add + ;; RTRIP-IR-NEXT: (local.get $b) + ;; RTRIP-IR-NEXT: (i32.const 2) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: (block $in + ;; RTRIP-IR-NEXT: (br_if $in + ;; RTRIP-IR-NEXT: (local.get $scratch) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: (local.get $scratch_5) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-STACK-IR: (func $outer-stack-survives (type $1) (param $a i32) (param $b i32) (result i32) + ;; RTRIP-STACK-IR-NEXT: (local $z i32) + ;; RTRIP-STACK-IR-NEXT: (local $x i32) + ;; RTRIP-STACK-IR-NEXT: (local $scratch i32) + ;; RTRIP-STACK-IR-NEXT: (local $scratch_5 i32) + ;; RTRIP-STACK-IR-NEXT: local.get $a + ;; RTRIP-STACK-IR-NEXT: i32.const 1 + ;; RTRIP-STACK-IR-NEXT: i32.add + ;; RTRIP-STACK-IR-NEXT: local.get $b + ;; RTRIP-STACK-IR-NEXT: i32.const 2 + ;; RTRIP-STACK-IR-NEXT: i32.add + ;; RTRIP-STACK-IR-NEXT: block $in (type $7) (param i32) + ;; RTRIP-STACK-IR-NEXT: br_if $in + ;; RTRIP-STACK-IR-NEXT: end + ;; RTRIP-STACK-IR-NEXT: ) + (func $outer-stack-survives (param $a i32) (param $b i32) (result i32) + ;; A value left on the outer stack underneath a none-typed parameterized + ;; block round-trips without clobbering the outer value. + (local $z i32) + (local $x i32) + (local.set $z + (i32.add + (local.get $a) + (i32.const 1) + ) + ) + (local.set $x + (i32.add + (local.get $b) + (i32.const 2) + ) + ) + (block $in + (br_if $in + (local.get $x) + ) + ) + (local.get $z) + ) + + ;; STACK-IR: (func $non-nullable-ref-param (type $5) (param $a (ref $struct)) (param $c i32) (result (ref $struct)) + ;; STACK-IR-NEXT: (local $x (ref $struct)) + ;; STACK-IR-NEXT: local.get $a + ;; STACK-IR-NEXT: block $b (type $8) (param (ref $struct)) (result (ref $struct)) + ;; STACK-IR-NEXT: local.get $c + ;; STACK-IR-NEXT: if + ;; STACK-IR-NEXT: struct.new_default $struct + ;; STACK-IR-NEXT: br $b + ;; STACK-IR-NEXT: end + ;; STACK-IR-NEXT: end + ;; STACK-IR-NEXT: ) + ;; RTRIP-IR: (func $non-nullable-ref-param (type $4) (param $a (ref $struct)) (param $c i32) (result (ref $struct)) + ;; RTRIP-IR-NEXT: (local $x (ref $struct)) + ;; RTRIP-IR-NEXT: (local $scratch (ref $struct)) + ;; RTRIP-IR-NEXT: (local.set $scratch + ;; RTRIP-IR-NEXT: (local.get $a) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: (block $b (result (ref $struct)) + ;; RTRIP-IR-NEXT: (if + ;; RTRIP-IR-NEXT: (local.get $c) + ;; RTRIP-IR-NEXT: (then + ;; RTRIP-IR-NEXT: (br $b + ;; RTRIP-IR-NEXT: (struct.new_default $struct) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: (local.get $scratch) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-STACK-IR: (func $non-nullable-ref-param (type $5) (param $a (ref $struct)) (param $c i32) (result (ref $struct)) + ;; RTRIP-STACK-IR-NEXT: (local $x (ref $struct)) + ;; RTRIP-STACK-IR-NEXT: (local $scratch (ref $struct)) + ;; RTRIP-STACK-IR-NEXT: local.get $a + ;; RTRIP-STACK-IR-NEXT: block $b (type $8) (param (ref $struct)) (result (ref $struct)) + ;; RTRIP-STACK-IR-NEXT: local.get $c + ;; RTRIP-STACK-IR-NEXT: if + ;; RTRIP-STACK-IR-NEXT: struct.new_default $struct + ;; RTRIP-STACK-IR-NEXT: br $b + ;; RTRIP-STACK-IR-NEXT: end + ;; RTRIP-STACK-IR-NEXT: end + ;; RTRIP-STACK-IR-NEXT: ) + (func $non-nullable-ref-param (param $a (ref $struct)) (param $c i32) (result (ref $struct)) + ;; A non-nullable reference threaded into a block parameter round-trips + ;; using a dominating non-nullable scratch local without ref.as_non_null. + (local $x (ref $struct)) + (local.set $x + (local.get $a) + ) + (block $b (result (ref $struct)) + (if + (local.get $c) + (then + (br $b + (struct.new_default $struct) + ) + ) + ) + (local.get $x) + ) + ) + + ;; STACK-IR: (func $nested-blocks-varying-params (type $6) (param $a i32) (param $b i64) (param $c f32) (result i32) + ;; STACK-IR-NEXT: (local $x i32) + ;; STACK-IR-NEXT: (local $y i64) + ;; STACK-IR-NEXT: (local $z f32) + ;; STACK-IR-NEXT: local.get $a + ;; STACK-IR-NEXT: i32.const 1 + ;; STACK-IR-NEXT: i32.add + ;; STACK-IR-NEXT: block $b1 (type $2) (param i32) (result i32) + ;; STACK-IR-NEXT: local.get $b + ;; STACK-IR-NEXT: i64.const 2 + ;; STACK-IR-NEXT: i64.add + ;; STACK-IR-NEXT: block $b2 (type $3) (param i32 i64) (result i32) + ;; STACK-IR-NEXT: i32.wrap_i64 + ;; STACK-IR-NEXT: if + ;; STACK-IR-NEXT: i32.const 10 + ;; STACK-IR-NEXT: br $b2 + ;; STACK-IR-NEXT: end + ;; STACK-IR-NEXT: local.get $c + ;; STACK-IR-NEXT: f32.const 3 + ;; STACK-IR-NEXT: f32.add + ;; STACK-IR-NEXT: block $b3 (type $9) (param i32 f32) (result i32) + ;; STACK-IR-NEXT: f32.const 0 + ;; STACK-IR-NEXT: f32.gt + ;; STACK-IR-NEXT: if + ;; STACK-IR-NEXT: i32.const 20 + ;; STACK-IR-NEXT: br $b1 + ;; STACK-IR-NEXT: end + ;; STACK-IR-NEXT: if + ;; STACK-IR-NEXT: i32.const 30 + ;; STACK-IR-NEXT: br $b3 + ;; STACK-IR-NEXT: end + ;; STACK-IR-NEXT: i32.const 40 + ;; STACK-IR-NEXT: end + ;; STACK-IR-NEXT: end + ;; STACK-IR-NEXT: end + ;; STACK-IR-NEXT: ) + ;; RTRIP-IR: (func $nested-blocks-varying-params (type $5) (param $a i32) (param $b i64) (param $c f32) (result i32) + ;; RTRIP-IR-NEXT: (local $x i32) + ;; RTRIP-IR-NEXT: (local $y i64) + ;; RTRIP-IR-NEXT: (local $z f32) + ;; RTRIP-IR-NEXT: (local $scratch i32) + ;; RTRIP-IR-NEXT: (local $scratch_7 i64) + ;; RTRIP-IR-NEXT: (local $scratch_8 f32) + ;; RTRIP-IR-NEXT: (local.set $scratch + ;; RTRIP-IR-NEXT: (i32.add + ;; RTRIP-IR-NEXT: (local.get $a) + ;; RTRIP-IR-NEXT: (i32.const 1) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: (block $b1 (result i32) + ;; RTRIP-IR-NEXT: (local.set $scratch_7 + ;; RTRIP-IR-NEXT: (i64.add + ;; RTRIP-IR-NEXT: (local.get $b) + ;; RTRIP-IR-NEXT: (i64.const 2) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: (block $b2 (result i32) + ;; RTRIP-IR-NEXT: (local.set $scratch_8 + ;; RTRIP-IR-NEXT: (block (result f32) + ;; RTRIP-IR-NEXT: (if + ;; RTRIP-IR-NEXT: (i32.wrap_i64 + ;; RTRIP-IR-NEXT: (local.get $scratch_7) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: (then + ;; RTRIP-IR-NEXT: (br $b2 + ;; RTRIP-IR-NEXT: (i32.const 10) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: (f32.add + ;; RTRIP-IR-NEXT: (local.get $c) + ;; RTRIP-IR-NEXT: (f32.const 3) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: (block $b3 (result i32) + ;; RTRIP-IR-NEXT: (if + ;; RTRIP-IR-NEXT: (f32.gt + ;; RTRIP-IR-NEXT: (local.get $scratch_8) + ;; RTRIP-IR-NEXT: (f32.const 0) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: (then + ;; RTRIP-IR-NEXT: (br $b1 + ;; RTRIP-IR-NEXT: (i32.const 20) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: (if + ;; RTRIP-IR-NEXT: (local.get $scratch) + ;; RTRIP-IR-NEXT: (then + ;; RTRIP-IR-NEXT: (br $b3 + ;; RTRIP-IR-NEXT: (i32.const 30) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: (i32.const 40) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-IR-NEXT: ) + ;; RTRIP-STACK-IR: (func $nested-blocks-varying-params (type $6) (param $a i32) (param $b i64) (param $c f32) (result i32) + ;; RTRIP-STACK-IR-NEXT: (local $x i32) + ;; RTRIP-STACK-IR-NEXT: (local $y i64) + ;; RTRIP-STACK-IR-NEXT: (local $z f32) + ;; RTRIP-STACK-IR-NEXT: (local $scratch i32) + ;; RTRIP-STACK-IR-NEXT: (local $scratch_7 i64) + ;; RTRIP-STACK-IR-NEXT: (local $scratch_8 f32) + ;; RTRIP-STACK-IR-NEXT: local.get $a + ;; RTRIP-STACK-IR-NEXT: i32.const 1 + ;; RTRIP-STACK-IR-NEXT: i32.add + ;; RTRIP-STACK-IR-NEXT: block $b1 (type $2) (param i32) (result i32) + ;; RTRIP-STACK-IR-NEXT: local.get $b + ;; RTRIP-STACK-IR-NEXT: i64.const 2 + ;; RTRIP-STACK-IR-NEXT: i64.add + ;; RTRIP-STACK-IR-NEXT: block $b2 (type $3) (param i32 i64) (result i32) + ;; RTRIP-STACK-IR-NEXT: i32.wrap_i64 + ;; RTRIP-STACK-IR-NEXT: if + ;; RTRIP-STACK-IR-NEXT: i32.const 10 + ;; RTRIP-STACK-IR-NEXT: br $b2 + ;; RTRIP-STACK-IR-NEXT: end + ;; RTRIP-STACK-IR-NEXT: local.get $c + ;; RTRIP-STACK-IR-NEXT: f32.const 3 + ;; RTRIP-STACK-IR-NEXT: f32.add + ;; RTRIP-STACK-IR-NEXT: block $b3 (type $9) (param i32 f32) (result i32) + ;; RTRIP-STACK-IR-NEXT: f32.const 0 + ;; RTRIP-STACK-IR-NEXT: f32.gt + ;; RTRIP-STACK-IR-NEXT: if + ;; RTRIP-STACK-IR-NEXT: i32.const 20 + ;; RTRIP-STACK-IR-NEXT: br $b1 + ;; RTRIP-STACK-IR-NEXT: end + ;; RTRIP-STACK-IR-NEXT: if + ;; RTRIP-STACK-IR-NEXT: i32.const 30 + ;; RTRIP-STACK-IR-NEXT: br $b3 + ;; RTRIP-STACK-IR-NEXT: end + ;; RTRIP-STACK-IR-NEXT: i32.const 40 + ;; RTRIP-STACK-IR-NEXT: end + ;; RTRIP-STACK-IR-NEXT: end + ;; RTRIP-STACK-IR-NEXT: end + ;; RTRIP-STACK-IR-NEXT: ) + (func $nested-blocks-varying-params (param $a i32) (param $b i64) (param $c f32) (result i32) + ;; Nested blocks whose parameter lists both grow and replace entries across + ;; depths round-trip and re-emit the same distinct block signatures. + (local $x i32) + (local $y i64) + (local $z f32) + (local.set $x + (i32.add + (local.get $a) + (i32.const 1) + ) + ) + (block $b1 (result i32) + (local.set $y + (i64.add + (local.get $b) + (i64.const 2) + ) + ) + (block $b2 (result i32) + (if + (i32.wrap_i64 + (local.get $y) + ) + (then + (br $b2 + (i32.const 10) + ) + ) + ) + (local.set $z + (f32.add + (local.get $c) + (f32.const 3) + ) + ) + (block $b3 (result i32) + (if + (f32.gt + (local.get $z) + (f32.const 0) + ) + (then + (br $b1 + (i32.const 20) + ) + ) + ) + (if + (local.get $x) + (then + (br $b3 + (i32.const 30) + ) + ) + ) + (i32.const 40) + ) + ) + ) + ) +) diff --git a/test/lit/passes/translate-to-exnref.wast b/test/lit/passes/translate-to-exnref.wast index 60497857a9c..728646eff6a 100644 --- a/test/lit/passes/translate-to-exnref.wast +++ b/test/lit/passes/translate-to-exnref.wast @@ -33,6 +33,10 @@ ;; STACKIR-OPT: (type $6 (func (param i32 i64))) + ;; STACKIR-OPT: (type $7 (func (param exnref))) + + ;; STACKIR-OPT: (type $8 (func (param exnref) (result (ref exn)))) + ;; STACKIR-OPT: (tag $e-empty (type $1)) (tag $e-empty) ;; CHECK: (tag $e-i32 (type $5) (param i32)) @@ -1556,16 +1560,14 @@ ;; STACKIR-OPT-NEXT: end ;; STACKIR-OPT-NEXT: br $outer3 ;; STACKIR-OPT-NEXT: end - ;; STACKIR-OPT-NEXT: local.set $0 - ;; STACKIR-OPT-NEXT: block $outer0 - ;; STACKIR-OPT-NEXT: block $catch2 (result (ref exn)) + ;; STACKIR-OPT-NEXT: block $outer0 (type $7) (param exnref) + ;; STACKIR-OPT-NEXT: block $catch2 (type $8) (param exnref) (result (ref exn)) ;; STACKIR-OPT-NEXT: block $catch1 ;; STACKIR-OPT-NEXT: try_table (catch $e-empty $catch1) (catch_ref $e-empty $catch2) ;; STACKIR-OPT-NEXT: call $foo ;; STACKIR-OPT-NEXT: end ;; STACKIR-OPT-NEXT: br $outer0 ;; STACKIR-OPT-NEXT: end - ;; STACKIR-OPT-NEXT: local.get $0 ;; STACKIR-OPT-NEXT: throw_ref ;; STACKIR-OPT-NEXT: end ;; STACKIR-OPT-NEXT: throw_ref