// Remove the call
fgRemoveStmt(block, last);
- // Set the loop edge.
+ // Set the loop edge. Ensure we have a scratch block and then target the
+ // next block. Loop detection needs to see a pred out of the loop, so
+ // mark the scratch block BBF_DONT_REMOVE to prevent empty block removal
+ // on it.
+ fgEnsureFirstBBisScratch();
+ fgFirstBB->bbFlags |= BBF_DONT_REMOVE;
block->bbJumpKind = BBJ_ALWAYS;
- block->bbJumpDest = fgFirstBBisScratch() ? fgFirstBB->bbNext : fgFirstBB;
+ block->bbJumpDest = fgFirstBB->bbNext;
fgAddRefPred(block->bbJumpDest, block);
block->bbFlags &= ~BBF_HAS_JMP;
}