Skip to content

Commit 296780d

Browse files
JIT: Don't transform infinite loops in fgOptimizeBranchToEmptyUnconditional (#116822)
Fixes #116701.
1 parent 8dbc826 commit 296780d

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/coreclr/jit/fgopt.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1298,6 +1298,17 @@ bool Compiler::fgOptimizeBranchToEmptyUnconditional(BasicBlock* block, BasicBloc
12981298
assert(bDest->isEmpty());
12991299
assert(bDest->KindIs(BBJ_ALWAYS));
13001300

1301+
BasicBlock* const bDestTarget = bDest->GetTarget();
1302+
1303+
// Don't redirect 'block' to 'bDestTarget' if the latter jumps to 'bDest'.
1304+
// This will lead the JIT to consider optimizing 'block' -> 'bDestTarget' -> 'bDest',
1305+
// entering an infinite loop.
1306+
//
1307+
if (bDestTarget->GetUniqueSucc() == bDest)
1308+
{
1309+
optimizeJump = false;
1310+
}
1311+
13011312
// We do not optimize jumps between two different try regions.
13021313
// However jumping to a block that is not in any try region is OK
13031314
//
@@ -1307,7 +1318,7 @@ bool Compiler::fgOptimizeBranchToEmptyUnconditional(BasicBlock* block, BasicBloc
13071318
}
13081319

13091320
// Don't optimize a jump to a removed block
1310-
if (bDest->GetTarget()->HasFlag(BBF_REMOVED))
1321+
if (bDestTarget->HasFlag(BBF_REMOVED))
13111322
{
13121323
optimizeJump = false;
13131324
}

0 commit comments

Comments
 (0)