From 7752e480217f176623bea0c1b70e65b1d733efde Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Thu, 18 Jan 2024 14:22:39 +0100 Subject: [PATCH 1/2] JIT: Compact newly recognized loops --- src/coreclr/jit/optimizer.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/coreclr/jit/optimizer.cpp b/src/coreclr/jit/optimizer.cpp index a0f40efa975251..85a4ebb401db47 100644 --- a/src/coreclr/jit/optimizer.cpp +++ b/src/coreclr/jit/optimizer.cpp @@ -4466,11 +4466,6 @@ bool Compiler::optCompactLoops() bool changed = false; for (FlowGraphNaturalLoop* loop : m_loops->InReversePostOrder()) { - if (!loop->GetHeader()->HasFlag(BBF_OLD_LOOP_HEADER_QUIRK)) - { - continue; - } - changed |= optCompactLoop(loop); } From c78459f8dd2322f1a75e055dcbd44b3a7004aa2a Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Thu, 18 Jan 2024 17:32:48 +0100 Subject: [PATCH 2/2] Skip singular CALLFINALLYRET outside loop if the CALLFINALLYRET is in the loop --- src/coreclr/jit/optimizer.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/coreclr/jit/optimizer.cpp b/src/coreclr/jit/optimizer.cpp index 85a4ebb401db47..f28691e666bb38 100644 --- a/src/coreclr/jit/optimizer.cpp +++ b/src/coreclr/jit/optimizer.cpp @@ -4499,6 +4499,16 @@ bool Compiler::optCompactLoop(FlowGraphNaturalLoop* loop) continue; } + // If this is a CALLFINALLYRET that is not in the loop, but the + // CALLFINALLY was, then we have to leave it in place. For compaction + // purposes this doesn't really make any difference, since no codegen + // is associated with the CALLFINALLYRET anyway. + if (cur->isBBCallFinallyPairTail()) + { + cur = cur->Next(); + continue; + } + BasicBlock* lastNonLoopBlock = cur; while (true) {