Repository: dotnet/runtime
File: src/coreclr/jit/fgwasm.cpp (C++)

Code before:
        // Now see where block branches to...
        //
        WasmSuccessorEnumerator successors(this, block, /* useProfile */ true);
        for (BasicBlock* const succ : successors)
        {
            unsigned const succNum = succ->bbPreorderNum;

            // We ignore back edges; they don't inspire blocks.
            //
            if (succNum <= cursor)
            {
                JITDUMP("Backedge " FMT_BB "[%u] -> " FMT_BB "[%u]\n", block->bbNum, cursor, succ->bbNum, succNum);

                // The backedge target should be a loop header.
                // (TODO: scan loop stack to verify the loop is on the stack?)
                //
                // Note we currently bail out way above if there are any irreducible loops.
                //
                assert(loops->GetLoopByHeader(succ) != nullptr);
                continue;
            }

            // Branch to next needs no block, unless this is a switch
            //
            if ((succNum == (cursor + 1)) && !block->KindIs(BBJ_SWITCH))
            {
                continue;
            }

            // Branch to cold block needs no block (presumably something EH related).
            // Eventually we need to case these out and handle them better.
            //
            if (succNum >= numBlocks)
            {
                continue;
            }

            // See if we already have a block that ends at this point and starts before.
            //
            WasmInterval* const existingBlock = scratch[succNum];

            if (existingBlock != nullptr)
            {
                // If so we don't need to track this branch.
                //
                JITDUMP("Subsumed " FMT_BB "[%u] -> " FMT_BB "[%u]\n", block->bbNum, cursor, succ->bbNum, succNum);
                assert(existingBlock->Start() <= cursor);
                continue;
            }

            // Non-contiguous, non-subsumed forward branch

Review comment (refactor):
We could also use `fgIsThrowHlpBlk` here, though I'm not sure what our style preference is between checking flags directly vs. using our helpers?

Code after:
        // Now see where block branches to...
        //
        WasmSuccessorEnumerator successors(this, block, /* useProfile */ true);
        for (BasicBlock* const succ : successors)
        {
            unsigned const succNum = succ->bbPreorderNum;

            // We ignore back edges; they don't inspire blocks.
            //
            if (succNum <= cursor)
            {
                JITDUMP("Backedge " FMT_BB "[%u] -> " FMT_BB "[%u]\n", block->bbNum, cursor, succ->bbNum, succNum);

                // The backedge target should be a loop header.
                // (TODO: scan loop stack to verify the loop is on the stack?)
                //
                // Note we currently bail out way above if there are any irreducible loops.
                //
                assert(loops->GetLoopByHeader(succ) != nullptr);
                continue;
            }

            // Branch to next needs no block, unless this is a switch or next is a throw helper.
            // We may need to branch to a throw helper mid-block, so can't always fall through.
            //
            if ((succNum == (cursor + 1)) && !block->KindIs(BBJ_SWITCH) && !(succ->HasFlag(BBF_THROW_HELPER)))
            {
                continue;
            }

            // Branch to cold block needs no block (presumably something EH related).
            // Eventually we need to case these out and handle them better.
            //
            if (succNum >= numBlocks)
            {
                continue;
            }

            // See if we already have a block that ends at this point and starts before.
            //
            WasmInterval* const existingBlock = scratch[succNum];

            if (existingBlock != nullptr)
            {
                // If so we don't need to track this branch.
                //
                JITDUMP("Subsumed " FMT_BB "[%u] -> " FMT_BB "[%u]\n", block->bbNum, cursor, succ->bbNum, succNum);
                assert(existingBlock->Start() <= cursor);
                continue;
            }