Skip to content

Commit ae1be12

Browse files
authored
JIT: produce consistent flow graph when producing or consuming profile data (#85860)
Always try and merge "branch to next" blocks when building the intial flow graph if BBINSTR or BBOPT is set. Fixes #85856.
1 parent 798f9ef commit ae1be12

File tree

5 files changed

+16
-10
lines changed

5 files changed

+16
-10
lines changed

src/coreclr/jit/compiler.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9471,9 +9471,14 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
94719471
return jitFlags->IsSet(JitFlags::JIT_FLAG_BBINSTR);
94729472
}
94739473

9474-
bool IsInstrumentedOptimized() const
9474+
bool IsInstrumentedAndOptimized() const
94759475
{
9476-
return IsInstrumented() && jitFlags->IsSet(JitFlags::JIT_FLAG_TIER1);
9476+
return IsInstrumented() && jitFlags->IsSet(JitFlags::JIT_FLAG_BBOPT);
9477+
}
9478+
9479+
bool IsInstrumentedOrOptimized() const
9480+
{
9481+
return IsInstrumented() || jitFlags->IsSet(JitFlags::JIT_FLAG_BBOPT);
94779482
}
94789483

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

src/coreclr/jit/fgbasic.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,8 +1824,9 @@ void Compiler::fgFindJumpTargets(const BYTE* codeAddr, IL_OFFSET codeSize, Fixed
18241824
// Compute jump target address
18251825
signed jmpDist = (sz == 1) ? getI1LittleEndian(codeAddr) : getI4LittleEndian(codeAddr);
18261826

1827-
if (compIsForInlining() && jmpDist == 0 &&
1828-
(opcode == CEE_LEAVE || opcode == CEE_LEAVE_S || opcode == CEE_BR || opcode == CEE_BR_S))
1827+
if ((jmpDist == 0) &&
1828+
(opcode == CEE_LEAVE || opcode == CEE_LEAVE_S || opcode == CEE_BR || opcode == CEE_BR_S) &&
1829+
opts.IsInstrumentedOrOptimized())
18291830
{
18301831
break; /* NOP */
18311832
}
@@ -2974,7 +2975,7 @@ unsigned Compiler::fgMakeBasicBlocks(const BYTE* codeAddr, IL_OFFSET codeSize, F
29742975

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

2977-
if (compIsForInlining() && jmpDist == 0 && (opcode == CEE_BR || opcode == CEE_BR_S))
2978+
if ((jmpDist == 0) && (opcode == CEE_BR || opcode == CEE_BR_S) && opts.IsInstrumentedOrOptimized())
29782979
{
29792980
continue; /* NOP */
29802981
}

src/coreclr/jit/fgprofile.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ void BlockCountInstrumentor::RelocateProbes()
436436
{
437437
// We only see such blocks when optimizing. They are flagged by the importer.
438438
//
439-
if (!m_comp->opts.IsInstrumentedOptimized() || ((m_comp->optMethodFlags & OMF_HAS_TAILCALL_SUCCESSOR) == 0))
439+
if (!m_comp->opts.IsInstrumentedAndOptimized() || ((m_comp->optMethodFlags & OMF_HAS_TAILCALL_SUCCESSOR) == 0))
440440
{
441441
// No problematic blocks to worry about.
442442
//
@@ -1616,7 +1616,7 @@ void EfficientEdgeCountInstrumentor::RelocateProbes()
16161616
{
16171617
// We only see such blocks when optimizing. They are flagged by the importer.
16181618
//
1619-
if (!m_comp->opts.IsInstrumentedOptimized() || ((m_comp->optMethodFlags & OMF_HAS_TAILCALL_SUCCESSOR) == 0))
1619+
if (!m_comp->opts.IsInstrumentedAndOptimized() || ((m_comp->optMethodFlags & OMF_HAS_TAILCALL_SUCCESSOR) == 0))
16201620
{
16211621
// No problematic blocks to worry about.
16221622
//

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 (compIsForInlining() && jmpDist == 0)
7479+
if ((jmpDist == 0) && opts.IsInstrumentedOrOptimized())
74807480
{
74817481
break; /* NOP */
74827482
}

src/coreclr/jit/importercalls.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,7 +1282,7 @@ var_types Compiler::impImportCall(OPCODE opcode,
12821282
// have to check for anything that might introduce a recursive tail call.
12831283
// * We only instrument root method blocks in OSR methods,
12841284
//
1285-
if ((opts.IsInstrumentedOptimized() || opts.IsOSR()) && !compIsForInlining())
1285+
if ((opts.IsInstrumentedAndOptimized() || opts.IsOSR()) && !compIsForInlining())
12861286
{
12871287
// If a root method tail call candidate block is not a BBJ_RETURN, it should have a unique
12881288
// BBJ_RETURN successor. Mark that successor so we can handle it specially during profile
@@ -7201,7 +7201,7 @@ bool Compiler::impConsiderCallProbe(GenTreeCall* call, IL_OFFSET ilOffset)
72017201
return false;
72027202
}
72037203

7204-
assert(opts.OptimizationDisabled() || opts.IsInstrumentedOptimized());
7204+
assert(opts.OptimizationDisabled() || opts.IsInstrumentedAndOptimized());
72057205
assert(!compIsForInlining());
72067206

72077207
// During importation, optionally flag this block as one that

0 commit comments

Comments
 (0)