Skip to content

Commit fd5a270

Browse files
committed
JIT: do early block merging in more cases
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 (dotnet#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 dotnet#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 dotnet#86125.
1 parent 1b56e96 commit fd5a270

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

src/coreclr/jit/compiler.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9387,11 +9387,9 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
93879387
return IsInstrumented() && jitFlags->IsSet(JitFlags::JIT_FLAG_BBOPT);
93889388
}
93899389

9390-
bool CanBeInstrumentedOrIsOptimized() const
9390+
bool DoEarlyBlockMerging() const
93919391
{
9392-
return IsInstrumented() || (jitFlags->IsSet(JitFlags::JIT_FLAG_TIER0) &&
9393-
jitFlags->IsSet(JitFlags::JIT_FLAG_BBINSTR_IF_LOOPS)) ||
9394-
jitFlags->IsSet(JitFlags::JIT_FLAG_BBOPT);
9392+
return IsInstrumented() || jitFlags->IsSet(JitFlags::JIT_FLAG_TIER0) || jitFlags->IsSet(JitFlags::JIT_FLAG_BBOPT);
93959393
}
93969394

93979395
// 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
@@ -1826,7 +1826,7 @@ void Compiler::fgFindJumpTargets(const BYTE* codeAddr, IL_OFFSET codeSize, Fixed
18261826

18271827
if ((jmpDist == 0) &&
18281828
(opcode == CEE_LEAVE || opcode == CEE_LEAVE_S || opcode == CEE_BR || opcode == CEE_BR_S) &&
1829-
opts.CanBeInstrumentedOrIsOptimized())
1829+
opts.DoEarlyBlockMerging())
18301830
{
18311831
break; /* NOP */
18321832
}
@@ -2975,7 +2975,7 @@ unsigned Compiler::fgMakeBasicBlocks(const BYTE* codeAddr, IL_OFFSET codeSize, F
29752975

29762976
jmpDist = (sz == 1) ? getI1LittleEndian(codeAddr) : getI4LittleEndian(codeAddr);
29772977

2978-
if ((jmpDist == 0) && (opcode == CEE_BR || opcode == CEE_BR_S) && opts.CanBeInstrumentedOrIsOptimized())
2978+
if ((jmpDist == 0) && (opcode == CEE_BR || opcode == CEE_BR_S) && opts.DoEarlyBlockMerging())
29792979
{
29802980
continue; /* NOP */
29812981
}

src/coreclr/jit/importer.cpp

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

7478-
if ((jmpDist == 0) && opts.CanBeInstrumentedOrIsOptimized())
7478+
if ((jmpDist == 0) && opts.DoEarlyBlockMerging())
74797479
{
74807480
break; /* NOP */
74817481
}

0 commit comments

Comments
 (0)