From 69bbdb8869b781f1d86434a340a6ba4b391338f0 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Tue, 12 Dec 2023 08:40:56 +0100 Subject: [PATCH] JIT: Fix OSR DFS assert, and update entry BB for try regions (#95871) There is nothing that stops an edge into the original entry BB from existing, so this assert is overzealous. The asserting case, however, was because of `fgNormalizeEH` not taking care to update `fgEntryBB`; also fix that. --- src/coreclr/jit/compiler.hpp | 1 - src/coreclr/jit/jiteh.cpp | 6 ++++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/coreclr/jit/compiler.hpp b/src/coreclr/jit/compiler.hpp index 9d48c66a9795a..e761d3f0bee2b 100644 --- a/src/coreclr/jit/compiler.hpp +++ b/src/coreclr/jit/compiler.hpp @@ -4976,7 +4976,6 @@ unsigned Compiler::fgRunDfs(VisitPreorder visitPreorder, VisitPostorder visitPos // patchpoint, but during morph we may transform to something that // requires the original entry (fgEntryBB). assert(opts.IsOSR()); - assert((fgEntryBB->bbRefs == 1) && (fgEntryBB->bbPreds == nullptr)); dfsFrom(fgEntryBB); } diff --git a/src/coreclr/jit/jiteh.cpp b/src/coreclr/jit/jiteh.cpp index 04985af018f41..846bf7032e202 100644 --- a/src/coreclr/jit/jiteh.cpp +++ b/src/coreclr/jit/jiteh.cpp @@ -2168,6 +2168,12 @@ bool Compiler::fgNormalizeEHCase2() newTryStart->bbRefs++; } + // Same for OSR's protected entry BB. + if (insertBeforeBlk == fgEntryBB) + { + fgEntryBB = newTryStart; + } + JITDUMP("'try' begin for EH#%u and EH#%u are same block; inserted new " FMT_BB " before " FMT_BB " " "as new 'try' begin for EH#%u.\n",