Skip to content

Commit c8cb0f8

Browse files
JIT: Don't clone or unroll cold loops (#115744)
Companion to #115734.
1 parent b683862 commit c8cb0f8

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/coreclr/jit/loopcloning.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,6 +1885,12 @@ bool Compiler::optShouldCloneLoop(FlowGraphNaturalLoop* loop, LoopCloneContext*
18851885
//
18861886
bool Compiler::optIsLoopClonable(FlowGraphNaturalLoop* loop, LoopCloneContext* context)
18871887
{
1888+
if (loop->GetHeader()->isRunRarely())
1889+
{
1890+
JITDUMP("Loop cloning: rejecting loop " FMT_LP ". Loop is cold.\n", loop->GetIndex());
1891+
return false;
1892+
}
1893+
18881894
const bool requireIterable = !doesMethodHaveGuardedDevirtualization();
18891895
NaturalLoopIterInfo* iterInfo = context->GetLoopIterInfo(loop->GetIndex());
18901896

src/coreclr/jit/optimizer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,6 +1390,12 @@ bool Compiler::optTryUnrollLoop(FlowGraphNaturalLoop* loop, bool* changedIR)
13901390
assert(UNROLL_LIMIT_SZ[SMALL_CODE] == 0);
13911391
assert(UNROLL_LIMIT_SZ[COUNT_OPT_CODE] == 0);
13921392

1393+
if (loop->GetHeader()->isRunRarely())
1394+
{
1395+
JITDUMP("Failed to unroll loop " FMT_LP ": Loop is cold.\n", loop->GetIndex());
1396+
return false;
1397+
}
1398+
13931399
NaturalLoopIterInfo iterInfo;
13941400
if (!loop->AnalyzeIteration(&iterInfo))
13951401
{

0 commit comments

Comments
 (0)