Skip to content

Commit

Permalink
JIT: Handle BBJ_CALLFINALLYRET block kind when checking for loop exit (
Browse files Browse the repository at this point in the history
  • Loading branch information
amanasifkhalid authored Dec 19, 2023
1 parent bd26d7e commit c282395
Showing 1 changed file with 36 additions and 18 deletions.
54 changes: 36 additions & 18 deletions src/coreclr/jit/optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2342,16 +2342,13 @@ class LoopSearch
//
void CheckForExit(BasicBlock* block)
{
BasicBlock* exitPoint;
assert(!block->HasTarget() || block->HasInitializedTarget());

switch (block->GetKind())
{
case BBJ_COND:
case BBJ_CALLFINALLY:
case BBJ_ALWAYS:
case BBJ_EHCATCHRET:
assert(block->HasInitializedTarget());
exitPoint = block->KindIs(BBJ_COND) ? block->GetTrueTarget() : block->GetTarget();
{
BasicBlock* exitPoint = block->GetTarget();

if (!loopBlocks.IsMember(exitPoint->bbNum))
{
Expand All @@ -2362,19 +2359,47 @@ class LoopSearch
// On non-funclet platforms (x86), the catch exit is a BBJ_ALWAYS, but we don't want that to
// be considered a loop exit block, as catch handlers don't have predecessor lists and don't
// show up as might be expected in the dominator tree.
if (block->KindIs(BBJ_ALWAYS))
if (!BasicBlock::sameHndRegion(block, exitPoint))
{
if (!BasicBlock::sameHndRegion(block, exitPoint))
{
break;
}
break;
}
#endif // !defined(FEATURE_EH_FUNCLETS)

lastExit = block;
exitCount++;
}
break;
}
case BBJ_COND:
if (!loopBlocks.IsMember(block->GetTrueTarget()->bbNum))
{
lastExit = block;
exitCount++;
}

if (!loopBlocks.IsMember(block->GetFalseTarget()->bbNum))
{
lastExit = block;
exitCount++;
}
break;
case BBJ_CALLFINALLY:
// Check fallthrough successor
if (!loopBlocks.IsMember(block->Next()->bbNum))
{
lastExit = block;
exitCount++;
}

FALLTHROUGH;
case BBJ_CALLFINALLYRET:
case BBJ_EHCATCHRET:
if (!loopBlocks.IsMember(block->GetTarget()->bbNum))
{
lastExit = block;
exitCount++;
}
break;

case BBJ_EHFINALLYRET:
case BBJ_EHFAULTRET:
Expand Down Expand Up @@ -2405,13 +2430,6 @@ class LoopSearch
noway_assert(!"Unexpected bbKind");
break;
}

if (block->bbFallsThrough() && !loopBlocks.IsMember(block->Next()->bbNum))
{
// Found a fall-through exit.
lastExit = block;
exitCount++;
}
}
};
} // end (anonymous) namespace
Expand Down

0 comments on commit c282395

Please sign in to comment.