From aa660d505260642ed04fec8a0224236cb038b69e Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Wed, 10 Feb 2021 23:43:32 -0800 Subject: [PATCH] Do not align cloned loops (#48090) * Do not align cloned loops --- src/coreclr/jit/emitxarch.cpp | 6 ++++++ src/coreclr/jit/optimizer.cpp | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/coreclr/jit/emitxarch.cpp b/src/coreclr/jit/emitxarch.cpp index d09ed44..6353d06 100644 --- a/src/coreclr/jit/emitxarch.cpp +++ b/src/coreclr/jit/emitxarch.cpp @@ -9223,6 +9223,12 @@ void emitter::emitDispIns( break; case IF_NONE: +#if FEATURE_LOOP_ALIGN + if (ins == INS_align) + { + printf("[%d bytes]", id->idCodeSize()); + } +#endif break; default: diff --git a/src/coreclr/jit/optimizer.cpp b/src/coreclr/jit/optimizer.cpp index 5655b60..0cf14f0 100644 --- a/src/coreclr/jit/optimizer.cpp +++ b/src/coreclr/jit/optimizer.cpp @@ -5319,6 +5319,18 @@ void Compiler::optCloneLoop(unsigned loopInd, LoopCloneContext* context) // checked them to guarantee they are clonable. bool cloneOk = BasicBlock::CloneBlockState(this, newBlk, blk); noway_assert(cloneOk); + +#if FEATURE_LOOP_ALIGN + // If the original loop is aligned, do not align the cloned loop because cloned loop will be executed in + // rare scenario. Additionally, having to align cloned loop will force us to disable some VEX prefix encoding + // and adding compensation for over-estimated instructions. + if (blk->isLoopAlign()) + { + newBlk->bbFlags &= ~BBF_LOOP_ALIGN; + JITDUMP("Removing LOOP_ALIGN flag from cloned loop in " FMT_BB "\n", newBlk->bbNum); + } +#endif + // TODO-Cleanup: The above clones the bbNatLoopNum, which is incorrect. Eventually, we should probably insert // the cloned loop in the loop table. For now, however, we'll just make these blocks be part of the surrounding // loop, if one exists -- the parent of the loop we're cloning. -- 2.7.4