Skip to content

Commit 2c6c003

Browse files
authored
Unmark loop align regardless if we found block to align or not (#86198)
* unmark loop align regardless if we found block to align or not * remove redundant if check
1 parent 8a2aec1 commit 2c6c003

File tree

1 file changed

+51
-51
lines changed

1 file changed

+51
-51
lines changed

src/coreclr/jit/compiler.cpp

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -5297,66 +5297,66 @@ PhaseStatus Compiler::placeLoopAlignInstructions()
52975297
{
52985298
// Loop alignment is disabled for cold blocks
52995299
assert((block->bbFlags & BBF_COLD) == 0);
5300-
BasicBlock* const loopTop = block->bbNext;
5301-
5302-
// If jmp was not found, then block before the loop start is where align instruction will be added.
5303-
// There are two special cases:
5304-
// 1. If the block before the loop start is a retless BBJ_CALLFINALLY with
5305-
// FEATURE_EH_CALLFINALLY_THUNKS, we can't add alignment because it will affect reported EH
5306-
// region range.
5307-
// 2. If the previous block is the BBJ_ALWAYS of a BBJ_CALLFINALLY/BBJ_ALWAYS pair, then we
5308-
// can't add alignment because we can't add instructions in that block. In the
5309-
// FEATURE_EH_CALLFINALLY_THUNKS case, it would affect the reported EH, as above.
5310-
//
5311-
// Currently, we don't align loops for these cases.
5312-
//
5313-
if (bbHavingAlign == nullptr)
5314-
{
5315-
bool isSpecialCallFinally = block->isBBCallAlwaysPairTail();
5300+
BasicBlock* const loopTop = block->bbNext;
5301+
bool isSpecialCallFinally = block->isBBCallAlwaysPairTail();
5302+
bool unmarkedLoopAlign = false;
5303+
53165304
#if FEATURE_EH_CALLFINALLY_THUNKS
5317-
if (block->bbJumpKind == BBJ_CALLFINALLY)
5318-
{
5319-
// It must be a retless BBJ_CALLFINALLY if we get here.
5320-
assert(!block->isBBCallAlwaysPair());
5321-
5322-
// In the case of FEATURE_EH_CALLFINALLY_THUNKS, we can't put the align instruction in a retless
5323-
// BBJ_CALLFINALLY either, because it alters the "cloned finally" region reported to the VM.
5324-
// In the x86 case (the only !FEATURE_EH_CALLFINALLY_THUNKS that supports retless
5325-
// BBJ_CALLFINALLY), we allow it.
5326-
isSpecialCallFinally = true;
5327-
}
5305+
if (block->bbJumpKind == BBJ_CALLFINALLY)
5306+
{
5307+
// It must be a retless BBJ_CALLFINALLY if we get here.
5308+
assert(!block->isBBCallAlwaysPair());
5309+
5310+
// In the case of FEATURE_EH_CALLFINALLY_THUNKS, we can't put the align instruction in a retless
5311+
// BBJ_CALLFINALLY either, because it alters the "cloned finally" region reported to the VM.
5312+
// In the x86 case (the only !FEATURE_EH_CALLFINALLY_THUNKS that supports retless
5313+
// BBJ_CALLFINALLY), we allow it.
5314+
isSpecialCallFinally = true;
5315+
}
53285316
#endif // FEATURE_EH_CALLFINALLY_THUNKS
53295317

5330-
if (isSpecialCallFinally)
5331-
{
5332-
loopTop->unmarkLoopAlign(this DEBUG_ARG("block before loop is special callfinally/always block"));
5333-
madeChanges = true;
5334-
}
5335-
else if ((block->bbNatLoopNum != BasicBlock::NOT_IN_LOOP) &&
5336-
(block->bbNatLoopNum == loopTop->bbNatLoopNum))
5337-
{
5338-
// In some odd cases we may see blocks within the loop before we see the
5339-
// top block of the loop. Just bail on aligning such loops.
5340-
//
5341-
loopTop->unmarkLoopAlign(this DEBUG_ARG("loop block appears before top of loop"));
5342-
madeChanges = true;
5343-
}
5344-
else
5318+
if (isSpecialCallFinally)
5319+
{
5320+
// There are two special cases:
5321+
// 1. If the block before the loop start is a retless BBJ_CALLFINALLY with
5322+
// FEATURE_EH_CALLFINALLY_THUNKS, we can't add alignment because it will affect reported EH
5323+
// region range.
5324+
// 2. If the previous block is the BBJ_ALWAYS of a BBJ_CALLFINALLY/BBJ_ALWAYS pair, then we
5325+
// can't add alignment because we can't add instructions in that block. In the
5326+
// FEATURE_EH_CALLFINALLY_THUNKS case, it would affect the reported EH, as above.
5327+
// Currently, we don't align loops for these cases.
5328+
5329+
loopTop->unmarkLoopAlign(this DEBUG_ARG("block before loop is special callfinally/always block"));
5330+
madeChanges = true;
5331+
unmarkedLoopAlign = true;
5332+
}
5333+
else if ((block->bbNatLoopNum != BasicBlock::NOT_IN_LOOP) && (block->bbNatLoopNum == loopTop->bbNatLoopNum))
5334+
{
5335+
// In some odd cases we may see blocks within the loop before we see the
5336+
// top block of the loop. Just bail on aligning such loops.
5337+
//
5338+
loopTop->unmarkLoopAlign(this DEBUG_ARG("loop block appears before top of loop"));
5339+
madeChanges = true;
5340+
unmarkedLoopAlign = true;
5341+
}
5342+
5343+
if (!unmarkedLoopAlign)
5344+
{
5345+
if (bbHavingAlign == nullptr)
53455346
{
5347+
// If jmp was not found, then block before the loop start is where align instruction will be added.
5348+
53465349
bbHavingAlign = block;
53475350
JITDUMP("Marking " FMT_BB " before the loop with BBF_HAS_ALIGN for loop at " FMT_BB "\n",
53485351
block->bbNum, loopTop->bbNum);
53495352
}
5350-
}
5351-
else
5352-
{
5353-
JITDUMP("Marking " FMT_BB " that ends with unconditional jump with BBF_HAS_ALIGN for loop at " FMT_BB
5354-
"\n",
5355-
bbHavingAlign->bbNum, loopTop->bbNum);
5356-
}
5353+
else
5354+
{
5355+
JITDUMP("Marking " FMT_BB
5356+
" that ends with unconditional jump with BBF_HAS_ALIGN for loop at " FMT_BB "\n",
5357+
bbHavingAlign->bbNum, loopTop->bbNum);
5358+
}
53575359

5358-
if (bbHavingAlign != nullptr)
5359-
{
53605360
madeChanges = true;
53615361
bbHavingAlign->bbFlags |= BBF_HAS_ALIGN;
53625362
}

0 commit comments

Comments
 (0)