Skip to content

Commit aa38055

Browse files
authored
JIT: do early block merging in more cases (#86157)
OSR and PGO both rely on the fact that the early flowgraph the JIT builds is the same flowgraph as the one seen in a previous JIT complation of that method, since there is metadata (patchpoint offset, pgo schema) that refers to the flowgraph. Previous work here (#85860) didn't ensure this for enough cases. In particular if Tier0 does not do early block merging, but OSR does, it's possible for the OSR entry point to fall within a merged block range, which the JIT is not prepared to handle. This lead to the asserts seen in #86125. The fix is to enable early block merging unless we're truly in a minopts or debug codegen mode (previous to this Tier0 would not merge unless it also was instrumenting; now it will always merge). An alternative fix would be to find the block containing the OSR entry IL offset, scan its statements, and split the block at the right spot, but that seemed more involved. Fixes #86125.
1 parent ff65075 commit aa38055

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

src/coreclr/jit/compiler.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9393,11 +9393,19 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
93939393
return IsInstrumented() && jitFlags->IsSet(JitFlags::JIT_FLAG_BBOPT);
93949394
}
93959395

9396-
bool CanBeInstrumentedOrIsOptimized() const
9396+
bool DoEarlyBlockMerging() const
93979397
{
9398-
return IsInstrumented() || (jitFlags->IsSet(JitFlags::JIT_FLAG_TIER0) &&
9399-
jitFlags->IsSet(JitFlags::JIT_FLAG_BBINSTR_IF_LOOPS)) ||
9400-
jitFlags->IsSet(JitFlags::JIT_FLAG_BBOPT);
9398+
if (jitFlags->IsSet(JitFlags::JIT_FLAG_DEBUG_EnC) || jitFlags->IsSet(JitFlags::JIT_FLAG_DEBUG_CODE))
9399+
{
9400+
return false;
9401+
}
9402+
9403+
if (jitFlags->IsSet(JitFlags::JIT_FLAG_MIN_OPT) && !jitFlags->IsSet(JitFlags::JIT_FLAG_TIER0))
9404+
{
9405+
return false;
9406+
}
9407+
9408+
return true;
94019409
}
94029410

94039411
// true if we should use the PINVOKE_{BEGIN,END} helpers instead of generating

src/coreclr/jit/fgbasic.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,7 +1840,7 @@ void Compiler::fgFindJumpTargets(const BYTE* codeAddr, IL_OFFSET codeSize, Fixed
18401840

18411841
if ((jmpDist == 0) &&
18421842
(opcode == CEE_LEAVE || opcode == CEE_LEAVE_S || opcode == CEE_BR || opcode == CEE_BR_S) &&
1843-
opts.CanBeInstrumentedOrIsOptimized())
1843+
opts.DoEarlyBlockMerging())
18441844
{
18451845
break; /* NOP */
18461846
}
@@ -2989,7 +2989,7 @@ unsigned Compiler::fgMakeBasicBlocks(const BYTE* codeAddr, IL_OFFSET codeSize, F
29892989

29902990
jmpDist = (sz == 1) ? getI1LittleEndian(codeAddr) : getI4LittleEndian(codeAddr);
29912991

2992-
if ((jmpDist == 0) && (opcode == CEE_BR || opcode == CEE_BR_S) && opts.CanBeInstrumentedOrIsOptimized())
2992+
if ((jmpDist == 0) && (opcode == CEE_BR || opcode == CEE_BR_S) && opts.DoEarlyBlockMerging())
29932993
{
29942994
continue; /* NOP */
29952995
}

src/coreclr/jit/importer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7420,7 +7420,7 @@ void Compiler::impImportBlockCode(BasicBlock* block)
74207420
case CEE_BR_S:
74217421
jmpDist = (sz == 1) ? getI1LittleEndian(codeAddr) : getI4LittleEndian(codeAddr);
74227422

7423-
if ((jmpDist == 0) && opts.CanBeInstrumentedOrIsOptimized())
7423+
if ((jmpDist == 0) && opts.DoEarlyBlockMerging())
74247424
{
74257425
break; /* NOP */
74267426
}

0 commit comments

Comments
 (0)