Skip to content

Commit

Permalink
Updated requested method aligment for xarch
Browse files Browse the repository at this point in the history
Align Tier1, small and IBC hot methods to 16 byte boundaries for x64 and x86.
Consensus from various folks I polled was that this isn't as helpful for arm
architectures, so for now this is xarch only.

This ensures that instruction prefetch pulls in as much code as possible.

It should also improve performance stability in some benchmarks, as well as
opening the door for possible loop-top aligment padding.

Resolves #16873.
  • Loading branch information
AndyAyersMS committed Dec 7, 2018
1 parent 6e9c14e commit 18b2123
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions src/jit/emit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4461,33 +4461,31 @@ unsigned emitter::emitEndCodeGen(Compiler* comp,

CorJitAllocMemFlag allocMemFlag = CORJIT_ALLOCMEM_DEFAULT_CODE_ALIGN;

#ifdef _TARGET_X86_
//
#ifdef _TARGET_XARCH_

// These are the heuristics we use to decide whether or not to force the
// code to be 16-byte aligned.
//
// 1. For ngen code with IBC data, use 16-byte alignment if the method
// has been called more than BB_VERY_HOT_WEIGHT times.
// 2. For JITed code and ngen code without IBC data, use 16-byte alignment
// when the code is 16 bytes or smaller. We align small getters/setters
// because of they are penalized heavily on certain hardware when not 16-byte
// aligned (VSWhidbey #373938). To minimize size impact of this optimization,
// we do not align large methods because of the penalty is amortized for them.
// 1. Methods jitted at Tier1.
// 2. Methods with small hot code size.
// 3. IBC profiled methods which are frequently called.
//
if (emitComp->fgHaveProfileData())
if (emitComp->opts.jitFlags->IsSet(JitFlags::JIT_FLAG_TIER1))
{
if (emitComp->fgCalledCount > (BB_VERY_HOT_WEIGHT * emitComp->fgProfileRunsCount()))
{
allocMemFlag = CORJIT_ALLOCMEM_FLG_16BYTE_ALIGN;
}
allocMemFlag = CORJIT_ALLOCMEM_FLG_16BYTE_ALIGN;
}
else
else if (emitTotalHotCodeSize <= 16)
{
allocMemFlag = CORJIT_ALLOCMEM_FLG_16BYTE_ALIGN;
}
else if (emitComp->fgHaveProfileData())
{
if (emitTotalHotCodeSize <= 16)
if (emitComp->fgCalledCount > (BB_VERY_HOT_WEIGHT * emitComp->fgProfileRunsCount()))
{
allocMemFlag = CORJIT_ALLOCMEM_FLG_16BYTE_ALIGN;
}
}

#endif

#ifdef _TARGET_ARM64_
Expand Down

0 comments on commit 18b2123

Please sign in to comment.