@@ -5175,6 +5175,20 @@ void emitter::emitSetLoopBackEdge(BasicBlock* loopTopBlock)
51755175
51765176 emitLastLoopStart = currLoopStart;
51775177 emitLastLoopEnd = currLoopEnd;
5178+
5179+ for (insGroup* igInLoop = dstIG; igInLoop != nullptr ; igInLoop = igInLoop->igNext )
5180+ {
5181+ // Presence of an IG that ends with an align instruction is misleading to the loop size calculation of
5182+ // current loop, because the padding amount is not known when loop size is calculated.
5183+ if (igInLoop->endsWithAlignInstr ())
5184+ {
5185+ alignCurrentLoop = false ;
5186+ 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 " ,
5187+ currLoopStart, currLoopEnd, igInLoop->igNum );
5188+
5189+ break ;
5190+ }
5191+ }
51785192 }
51795193 else if (currLoopStart == emitLastLoopStart)
51805194 {
@@ -5194,18 +5208,27 @@ void emitter::emitSetLoopBackEdge(BasicBlock* loopTopBlock)
51945208 // if current loop completely encloses last loop,
51955209 // then current loop should not be aligned.
51965210 alignCurrentLoop = false ;
5211+ JITDUMP (" ** Skip alignment for current loop IG%02u ~ IG%02u because it encloses an aligned loop "
5212+ " IG%02u ~ IG%02u.\n " ,
5213+ currLoopStart, currLoopEnd, emitLastLoopStart, emitLastLoopEnd);
51975214 }
51985215 else if ((emitLastLoopStart < currLoopStart) && (currLoopEnd < emitLastLoopEnd))
51995216 {
52005217 // if last loop completely encloses current loop,
52015218 // then last loop should not be aligned.
52025219 alignLastLoop = false ;
5220+ JITDUMP (" ** Skip alignment for aligned loop IG%02u ~ IG%02u because it encloses the current loop "
5221+ " IG%02u ~ IG%02u.\n " ,
5222+ emitLastLoopStart, emitLastLoopEnd, currLoopStart, currLoopEnd);
52035223 }
52045224 else
52055225 {
52065226 // The loops intersect and should not align either of the loops
52075227 alignLastLoop = false ;
52085228 alignCurrentLoop = false ;
5229+ JITDUMP (" ** Skip alignment for aligned loop IG%02u ~ IG%02u that intersects with the current loop "
5230+ " IG%02u ~ IG%02u.\n " ,
5231+ emitLastLoopStart, emitLastLoopEnd, currLoopStart, currLoopEnd);
52095232 }
52105233
52115234 if (!alignLastLoop || !alignCurrentLoop)
@@ -5225,11 +5248,7 @@ void emitter::emitSetLoopBackEdge(BasicBlock* loopTopBlock)
52255248
52265249 // This IG should no longer contain alignment instruction
52275250 alignInstr->removeAlignFlags ();
5228-
52295251 markedCurrLoop = true ;
5230- JITDUMP (" ** Skip alignment for current loop IG%02u ~ IG%02u because it encloses an aligned loop "
5231- " IG%02u ~ IG%02u.\n " ,
5232- currLoopStart, currLoopEnd, emitLastLoopStart, emitLastLoopEnd);
52335252 }
52345253
52355254 // Find the IG that has 'align' instruction to align the last loop
@@ -5241,11 +5260,7 @@ void emitter::emitSetLoopBackEdge(BasicBlock* loopTopBlock)
52415260
52425261 // This IG should no longer contain alignment instruction
52435262 alignInstr->removeAlignFlags ();
5244-
52455263 markedLastLoop = true ;
5246- JITDUMP (" ** Skip alignment for aligned loop IG%02u ~ IG%02u because it encloses the current loop "
5247- " IG%02u ~ IG%02u.\n " ,
5248- emitLastLoopStart, emitLastLoopEnd, currLoopStart, currLoopEnd);
52495264 }
52505265
52515266 if (markedLastLoop && markedCurrLoop)
0 commit comments