Skip to content

Commit 0b28e59

Browse files
authored
Never set fgPgoSingleEdge for cctors or large single-edge blocks (#117420)
1 parent cd726e7 commit 0b28e59

File tree

5 files changed

+27
-24
lines changed

5 files changed

+27
-24
lines changed

src/coreclr/jit/compiler.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2550,8 +2550,9 @@ void Compiler::compInitOptions(JitFlags* jitFlags)
25502550
opts.genFPorder = true;
25512551
opts.genFPopt = true;
25522552

2553-
opts.instrCount = 0;
2554-
opts.lvRefCount = 0;
2553+
opts.instrCount = 0;
2554+
opts.callInstrCount = 0;
2555+
opts.lvRefCount = 0;
25552556

25562557
#ifdef PROFILING_SUPPORTED
25572558
opts.compJitELTHookEnabled = false;

src/coreclr/jit/compiler.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9913,8 +9913,9 @@ class Compiler
99139913
compSupportsISA = isas;
99149914
}
99159915

9916-
unsigned compFlags; // method attributes
9917-
unsigned instrCount = 0;
9916+
unsigned compFlags; // method attributes
9917+
unsigned instrCount = 0; // number of IL opcodes
9918+
unsigned callInstrCount = 0; // number of IL opcodes (calls only).
99189919
unsigned lvRefCount;
99199920

99209921
codeOptimize compCodeOpt; // what type of code optimizations

src/coreclr/jit/fgbasic.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3170,6 +3170,7 @@ void Compiler::fgMakeBasicBlocks(const BYTE* codeAddr, IL_OFFSET codeSize, Fixed
31703170
case CEE_CALLVIRT:
31713171
case CEE_CALLI:
31723172
{
3173+
opts.callInstrCount++;
31733174
if (compIsForInlining() || // Ignore tail call in the inlinee. Period.
31743175
(!tailCall && !compTailCallStress()) // A new BB with BBJ_RETURN would have been created
31753176

@@ -3288,6 +3289,7 @@ void Compiler::fgMakeBasicBlocks(const BYTE* codeAddr, IL_OFFSET codeSize, Fixed
32883289

32893290
// These ctrl-flow opcodes don't need any special handling
32903291
case CEE_NEWOBJ: // CTRL_CALL
3292+
opts.callInstrCount++;
32913293
break;
32923294

32933295
// what's left are forgotten instructions

src/coreclr/jit/fgprofilesynthesis.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,14 +249,23 @@ void ProfileSynthesis::Run(ProfileSynthesisOption option)
249249
m_comp->fgPgoSynthesized = true;
250250
m_comp->fgPgoConsistent = !m_approximate;
251251

252-
// A simple check whether the current method has more than one edge.
253-
m_comp->fgPgoSingleEdge = true;
254-
for (BasicBlock* const block : m_comp->Blocks())
252+
// If a method has just one edge, we simulate having PGO data for it since we typically
253+
// don't instrument such methods. To avoid giving excessive inlining boost to large and/or
254+
// infrequently executed methods, we apply the following heuristics to exclude:
255+
//
256+
const bool preferSize = m_comp->opts.jitFlags->IsSet(JitFlags::JIT_FLAG_SIZE_OPT);
257+
const bool isCctor = (m_comp->info.compFlags & FLG_CCTOR) == FLG_CCTOR;
258+
m_comp->fgPgoSingleEdge = !isCctor && !preferSize && (m_comp->opts.callInstrCount < 10);
259+
260+
if (m_comp->fgPgoSingleEdge)
255261
{
256-
if (block->NumSucc() > 1)
262+
for (BasicBlock* const block : m_comp->Blocks())
257263
{
258-
m_comp->fgPgoSingleEdge = false;
259-
break;
264+
if (block->NumSucc() > 1)
265+
{
266+
m_comp->fgPgoSingleEdge = false;
267+
break;
268+
}
260269
}
261270
}
262271

src/coreclr/jit/jit.h

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -738,16 +738,9 @@ inline size_t unsigned_abs(int64_t x)
738738
#define FEATURE_TAILCALL_OPT_SHARED_RETURN 0
739739
#endif // !FEATURE_TAILCALL_OPT
740740

741-
#define CLFLG_CODESIZE 0x00001
742-
#define CLFLG_CODESPEED 0x00002
743-
#define CLFLG_CSE 0x00004
744-
#define CLFLG_REGVAR 0x00008
745-
#define CLFLG_RNGCHKOPT 0x00010
746-
#define CLFLG_DEADSTORE 0x00020
747-
#define CLFLG_CODEMOTION 0x00040
748-
#define CLFLG_QMARK 0x00080
749-
#define CLFLG_TREETRANS 0x00100
750-
#define CLFLG_INLINING 0x00200
741+
#define CLFLG_REGVAR 0x00008
742+
#define CLFLG_TREETRANS 0x00100
743+
#define CLFLG_INLINING 0x00200
751744

752745
#if FEATURE_STRUCTPROMOTE
753746
#define CLFLG_STRUCTPROMOTE 0x00400
@@ -761,10 +754,7 @@ inline size_t unsigned_abs(int64_t x)
761754
#define FEATURE_LOOP_ALIGN 0
762755
#endif
763756

764-
#define CLFLG_MAXOPT \
765-
(CLFLG_CSE | CLFLG_REGVAR | CLFLG_RNGCHKOPT | CLFLG_DEADSTORE | CLFLG_CODEMOTION | CLFLG_QMARK | CLFLG_TREETRANS | \
766-
CLFLG_INLINING | CLFLG_STRUCTPROMOTE)
767-
757+
#define CLFLG_MAXOPT (CLFLG_REGVAR | CLFLG_TREETRANS | CLFLG_INLINING | CLFLG_STRUCTPROMOTE)
768758
#define CLFLG_MINOPT (CLFLG_TREETRANS)
769759

770760
/*****************************************************************************/

0 commit comments

Comments
 (0)