diff --git a/src/coreclr/jit/optimizer.cpp b/src/coreclr/jit/optimizer.cpp index a0f40efa97525..f28691e666bb3 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); } @@ -4504,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) {