From 30155c51f741936deff9d006505bf9b209f1faa4 Mon Sep 17 00:00:00 2001 From: Andy Ayers Date: Thu, 2 Jul 2026 16:45:08 -0700 Subject: [PATCH 1/2] [Wasm/RyuJit] treat all try side-entries as try entries for throw helpers For Wasm DFS in graphs where try regions may have side entries (async), ensure the DFS will always eagerly visit (and first hence retreat from) any throw helper\ blocks in the region no matter which entry is visited first by DFS. This ensures the throw helper ends up last in the RPO, and hence is reachable by a forward branch from anywhere in the region. --- src/coreclr/jit/fgwasm.h | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/coreclr/jit/fgwasm.h b/src/coreclr/jit/fgwasm.h index c2eb4f843ee572..0cc01460bdf36b 100644 --- a/src/coreclr/jit/fgwasm.h +++ b/src/coreclr/jit/fgwasm.h @@ -404,6 +404,34 @@ class FgWasm template BasicBlockVisit FgWasm::VisitWasmSuccs(Compiler* comp, BasicBlock* block, TFunc func, bool useProfile) { + + // True if this block is a try entry or a try side-entry. + // + auto isGeneralizedTryEntry = [comp](BasicBlock* block) -> bool { + + EHblkDsc* const ehDsc = comp->ehGetBlockTryDsc(block); + + if (ehDsc == nullptr) + { + return false; + } + + if (comp->bbIsTryBeg(block)) + { + return true; + } + + for (BasicBlock* const blockPred : block->PredBlocks()) + { + if (blockPred->HasAnyFlag(BBF_ASYNC_RESUMPTION | BBF_CATCH_RESUMPTION)) + { + return true; + } + } + + return false; + }; + // Special case throw helper blocks that are not yet connected in the flow graph. // Compiler::AddCodeDscMap* const acdMap = comp->fgGetAddCodeDscMap(); @@ -411,7 +439,7 @@ BasicBlockVisit FgWasm::VisitWasmSuccs(Compiler* comp, BasicBlock* block, TFunc { // Behave as if these blocks have edges from their respective region entry blocks. // - if ((block == comp->fgFirstBB) || comp->bbIsFuncletBeg(block) || comp->bbIsTryBeg(block)) + if ((block == comp->fgFirstBB) || comp->bbIsFuncletBeg(block) || isGeneralizedTryEntry(block)) { Compiler::AcdKeyDesignator dsg; const unsigned blockData = comp->bbThrowIndex(block, &dsg); From 3d8f367b2c069f2fd730e8dc8d8f8fb29079cfee Mon Sep 17 00:00:00 2001 From: Andy Ayers Date: Thu, 2 Jul 2026 17:21:18 -0700 Subject: [PATCH 2/2] format --- src/coreclr/jit/fgwasm.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/coreclr/jit/fgwasm.h b/src/coreclr/jit/fgwasm.h index 0cc01460bdf36b..c5be5ccf3cd717 100644 --- a/src/coreclr/jit/fgwasm.h +++ b/src/coreclr/jit/fgwasm.h @@ -408,7 +408,6 @@ BasicBlockVisit FgWasm::VisitWasmSuccs(Compiler* comp, BasicBlock* block, TFunc // True if this block is a try entry or a try side-entry. // auto isGeneralizedTryEntry = [comp](BasicBlock* block) -> bool { - EHblkDsc* const ehDsc = comp->ehGetBlockTryDsc(block); if (ehDsc == nullptr)