Skip to content

Commit

Permalink
JIT: fix another case of early flow graph divergence (#85873)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AndyAyersMS authored May 7, 2023
1 parent 3b88700 commit d7c94a8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -9407,9 +9407,11 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
return IsInstrumented() && jitFlags->IsSet(JitFlags::JIT_FLAG_BBOPT);
}

bool IsInstrumentedOrOptimized() const
bool CanBeInstrumentedOrIsOptimized() const
{
return IsInstrumented() || jitFlags->IsSet(JitFlags::JIT_FLAG_BBOPT);
return IsInstrumented() || (jitFlags->IsSet(JitFlags::JIT_FLAG_TIER0) &&
jitFlags->IsSet(JitFlags::JIT_FLAG_BBINSTR_IF_LOOPS)) ||
jitFlags->IsSet(JitFlags::JIT_FLAG_BBOPT);
}

// true if we should use the PINVOKE_{BEGIN,END} helpers instead of generating
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/fgbasic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1826,7 +1826,7 @@ void Compiler::fgFindJumpTargets(const BYTE* codeAddr, IL_OFFSET codeSize, Fixed

if ((jmpDist == 0) &&
(opcode == CEE_LEAVE || opcode == CEE_LEAVE_S || opcode == CEE_BR || opcode == CEE_BR_S) &&
opts.IsInstrumentedOrOptimized())
opts.CanBeInstrumentedOrIsOptimized())
{
break; /* NOP */
}
Expand Down Expand Up @@ -2975,7 +2975,7 @@ unsigned Compiler::fgMakeBasicBlocks(const BYTE* codeAddr, IL_OFFSET codeSize, F

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

if ((jmpDist == 0) && (opcode == CEE_BR || opcode == CEE_BR_S) && opts.IsInstrumentedOrOptimized())
if ((jmpDist == 0) && (opcode == CEE_BR || opcode == CEE_BR_S) && opts.CanBeInstrumentedOrIsOptimized())
{
continue; /* NOP */
}
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7476,7 +7476,7 @@ void Compiler::impImportBlockCode(BasicBlock* block)
case CEE_BR_S:
jmpDist = (sz == 1) ? getI1LittleEndian(codeAddr) : getI4LittleEndian(codeAddr);

if ((jmpDist == 0) && opts.IsInstrumentedOrOptimized())
if ((jmpDist == 0) && opts.CanBeInstrumentedOrIsOptimized())
{
break; /* NOP */
}
Expand Down

0 comments on commit d7c94a8

Please sign in to comment.