Skip to content

Commit

Permalink
fix for dotnet#61899
Browse files Browse the repository at this point in the history
  • Loading branch information
kunalspathak committed Dec 1, 2021
1 parent cc2cb04 commit 1fc26a5
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions src/coreclr/jit/emit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5175,6 +5175,20 @@ void emitter::emitSetLoopBackEdge(BasicBlock* loopTopBlock)

emitLastLoopStart = currLoopStart;
emitLastLoopEnd = currLoopEnd;

for (insGroup* igInLoop = dstIG; igInLoop != nullptr; igInLoop = igInLoop->igNext)
{
// Presence of an IG that ends with an align instruction is misleading to the loop size calculation of
// current loop, because the padding amount is not known when loop size is calculated.
if (igInLoop->endsWithAlignInstr())
{
alignCurrentLoop = false;
JITDUMP("** Skip alignment for current loop IG%02u ~ IG%02u because it has IG%02u that contains an align instruction for a different loop.\n",
currLoopStart, currLoopEnd, igInLoop->igNum);

break;
}
}
}
else if (currLoopStart == emitLastLoopStart)
{
Expand All @@ -5194,18 +5208,27 @@ void emitter::emitSetLoopBackEdge(BasicBlock* loopTopBlock)
// if current loop completely encloses last loop,
// then current loop should not be aligned.
alignCurrentLoop = false;
JITDUMP("** Skip alignment for current loop IG%02u ~ IG%02u because it encloses an aligned loop "
"IG%02u ~ IG%02u.\n",
currLoopStart, currLoopEnd, emitLastLoopStart, emitLastLoopEnd);
}
else if ((emitLastLoopStart < currLoopStart) && (currLoopEnd < emitLastLoopEnd))
{
// if last loop completely encloses current loop,
// then last loop should not be aligned.
alignLastLoop = false;
JITDUMP("** Skip alignment for aligned loop IG%02u ~ IG%02u because it encloses the current loop "
"IG%02u ~ IG%02u.\n",
emitLastLoopStart, emitLastLoopEnd, currLoopStart, currLoopEnd);
}
else
{
// The loops intersect and should not align either of the loops
alignLastLoop = false;
alignCurrentLoop = false;
JITDUMP("** Skip alignment for aligned loop IG%02u ~ IG%02u that intersects with the current loop "
"IG%02u ~ IG%02u.\n",
emitLastLoopStart, emitLastLoopEnd, currLoopStart, currLoopEnd);
}

if (!alignLastLoop || !alignCurrentLoop)
Expand All @@ -5225,11 +5248,7 @@ void emitter::emitSetLoopBackEdge(BasicBlock* loopTopBlock)

// This IG should no longer contain alignment instruction
alignInstr->removeAlignFlags();

markedCurrLoop = true;
JITDUMP("** Skip alignment for current loop IG%02u ~ IG%02u because it encloses an aligned loop "
"IG%02u ~ IG%02u.\n",
currLoopStart, currLoopEnd, emitLastLoopStart, emitLastLoopEnd);
}

// Find the IG that has 'align' instruction to align the last loop
Expand All @@ -5241,11 +5260,7 @@ void emitter::emitSetLoopBackEdge(BasicBlock* loopTopBlock)

// This IG should no longer contain alignment instruction
alignInstr->removeAlignFlags();

markedLastLoop = true;
JITDUMP("** Skip alignment for aligned loop IG%02u ~ IG%02u because it encloses the current loop "
"IG%02u ~ IG%02u.\n",
emitLastLoopStart, emitLastLoopEnd, currLoopStart, currLoopEnd);
}

if (markedLastLoop && markedCurrLoop)
Expand Down

0 comments on commit 1fc26a5

Please sign in to comment.