From bedc113779e4fa7fbf4df9061f015295f1330e23 Mon Sep 17 00:00:00 2001 From: Andy Ayers Date: Fri, 29 May 2026 16:50:38 -0700 Subject: [PATCH] JIT: remove dead BBJ_RETURN-in-loop assertion in loop cloner MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit optIsLoopClonable contained a DEBUG-only walk that asserted no block in the loop was BBJ_RETURN, plus a stale function comment claiming that fgReturnCount would be bumped on success. There is no code anywhere in loopcloning.cpp that adjusts fgReturnCount (verified by grep), and the assertion is redundant: natural loops in RyuJIT can never contain a BBJ_RETURN block, because FlowGraphNaturalLoop discovery uses only regular CFG back-edges and BBJ_RETURN has no successor that can flow back to a loop header. Verified empirically across 23,712 natural loops from the benchmarks.run_pgo.windows SPMI collection (Tier1 + Tier1-OSR + FullOpts + Tier0-FullOpts, clonable + unclonable) — zero loops contained any BBJ_RETURN block. Drop both the assertion and the stale comment. No behavior change. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/coreclr/jit/loopcloning.cpp | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/coreclr/jit/loopcloning.cpp b/src/coreclr/jit/loopcloning.cpp index afa15fceb6dba4..1b66645ad0d7be 100644 --- a/src/coreclr/jit/loopcloning.cpp +++ b/src/coreclr/jit/loopcloning.cpp @@ -1906,10 +1906,6 @@ void Compiler::optPerformStaticOptimizations(FlowGraphNaturalLoop* loop, // Returns true if the loop can be cloned. If it returns false, // it prints a message to the JIT dump describing why the loop can't be cloned. // -// Notes: if `true` is returned, then `fgReturnCount` is increased by the number of -// return blocks in the loop that will be cloned. (REVIEW: this 'predicate' function -// doesn't seem like the right place to do this change.) -// bool Compiler::optIsLoopClonable(FlowGraphNaturalLoop* loop, LoopCloneContext* context) { if (loop->GetHeader()->isRunRarely()) @@ -1945,20 +1941,6 @@ bool Compiler::optIsLoopClonable(FlowGraphNaturalLoop* loop, LoopCloneContext* c return false; } -#ifdef DEBUG - // Today we will never see any BBJ_RETURN blocks because we cannot - // duplicate loops with EH in them. When we have no try-regions that start - // in the loop it is not possible for BBJ_RETURN blocks to be part of the - // loop; a BBJ_RETURN block can only be part of the loop if its exceptional - // flow can reach the header, but that would require the handler to also be - // part of the loop, which guarantees that the loop contains two distinct - // EH regions. - loop->VisitLoopBlocks([](BasicBlock* block) { - assert(!block->KindIs(BBJ_RETURN)); - return BasicBlockVisit::Continue; - }); -#endif - // Is the entry block a handler or filter start? If so, then if we cloned, we could create a jump // into the middle of a handler (to go to the cloned copy.) Reject. // TODO: This seems like it can be deleted. If the header is the beginning