Skip to content

Commit d7c94a8

Browse files
authored
JIT: fix another case of early flow graph divergence (#85873)
The JIT will sometimes decide to instrument a Tier0 method even if `BBINSTR` is not passed by the VM (this is enabled when the VM passes `BBINSTR_IF_LOOPS` so that we can provide some PGO data to OSR methods). In such cases we build the flow graph and then decide to instrument, so the flow graph shape may differ from the case where we know up front that we are going to instrument or optimize. Remedy this by also running the early branch to next flow graph opt when a Tier0 JIT is passed `BBINSTR_IF_LOOPS`. Addresses another case of #85856.
1 parent 3b88700 commit d7c94a8

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

src/coreclr/jit/compiler.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9407,9 +9407,11 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
94079407
return IsInstrumented() && jitFlags->IsSet(JitFlags::JIT_FLAG_BBOPT);
94089408
}
94099409

9410-
bool IsInstrumentedOrOptimized() const
9410+
bool CanBeInstrumentedOrIsOptimized() const
94119411
{
9412-
return IsInstrumented() || jitFlags->IsSet(JitFlags::JIT_FLAG_BBOPT);
9412+
return IsInstrumented() || (jitFlags->IsSet(JitFlags::JIT_FLAG_TIER0) &&
9413+
jitFlags->IsSet(JitFlags::JIT_FLAG_BBINSTR_IF_LOOPS)) ||
9414+
jitFlags->IsSet(JitFlags::JIT_FLAG_BBOPT);
94139415
}
94149416

94159417
// 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.IsInstrumentedOrOptimized())
1829+
opts.CanBeInstrumentedOrIsOptimized())
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.IsInstrumentedOrOptimized())
2978+
if ((jmpDist == 0) && (opcode == CEE_BR || opcode == CEE_BR_S) && opts.CanBeInstrumentedOrIsOptimized())
29792979
{
29802980
continue; /* NOP */
29812981
}

src/coreclr/jit/importer.cpp

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

7479-
if ((jmpDist == 0) && opts.IsInstrumentedOrOptimized())
7479+
if ((jmpDist == 0) && opts.CanBeInstrumentedOrIsOptimized())
74807480
{
74817481
break; /* NOP */
74827482
}

0 commit comments

Comments
 (0)