Skip to content

Commit

Permalink
Merge pull request #7400 from a7ehuo/system-arraycopy-perf-add-option…
Browse files Browse the repository at this point in the history
…-threshold

Add options to select the threshold for using rep movs in arraycopy
  • Loading branch information
0xdaryl committed Jul 9, 2024
2 parents d58019e + bcf5c45 commit 330a128
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
5 changes: 5 additions & 0 deletions compiler/control/OMROptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ TR::OptionTable OMR::Options::_jitOptions[] = {
SET_OPTION_BIT(TR_AOTCompileOnlyFromBootstrap), "F", NOT_IN_SUBSET },
{"aotrtDebugLevel=", "R<nnn>\tprint aotrt debug output according to level", TR::Options::set32BitNumeric, offsetof(OMR::Options,_newAotrtDebugLevel), 0, "F%d"},
{"aotSecondRunDetection", "M\tperform second run detection for AOT", RESET_OPTION_BIT(TR_NoAotSecondRunDetection), "F", NOT_IN_SUBSET},
{"arraycopyRepMovsByteArrayThreshold=", "C<nnn>\tByte array copy threshold for using REP MOVS instructions. Only supports 32 or 64 bytes", TR::Options::set32BitNumeric, offsetof(OMR::Options,_arraycopyRepMovsByteArrayThreshold), 0, "F%d"},
{"arraycopyRepMovsCharArrayThreshold=", "C<nnn>\tChar array copy threshold for using REP MOVS instructions. Only supports 32 or 64 bytes", TR::Options::set32BitNumeric, offsetof(OMR::Options,_arraycopyRepMovsCharArrayThreshold), 0, "F%d"},
{"arraycopyRepMovsIntArrayThreshold=", "C<nnn>\tInt array copy threshold for using REP MOVS instructions. Only supports 32, 64, or 128 bytes", TR::Options::set32BitNumeric, offsetof(OMR::Options,_arraycopyRepMovsIntArrayThreshold), 0, "F%d"},
{"arraycopyRepMovsLongArrayThreshold=", "C<nnn>\tLong Array copy threshold for using REP MOVS instructions. Only supports 32, 64, or 128 bytes", TR::Options::set32BitNumeric, offsetof(OMR::Options,_arraycopyRepMovsLongArrayThreshold), 0, "F%d"},
{"arraycopyRepMovsReferenceArrayThreshold=", "C<nnn>\tReference array copy threshold for using REP MOVS instructions. Only supports 32, 64, or 128 bytes", TR::Options::set32BitNumeric, offsetof(OMR::Options,_arraycopyRepMovsReferenceArrayThreshold), 0, "F%d"},
{"assignEveryGlobalRegister", "I\tnever refuse to assign any possible register for GRA in spite of the resulting potential spills", SET_OPTION_BIT(TR_AssignEveryGlobalRegister), "F"},
{"assumeStartupPhaseUntilToldNotTo", "M\tUse compiler.Command(""endOfStartup"") to exit startup phase",
SET_OPTION_BIT(TR_AssumeStartupPhaseUntilToldNotTo), "F" },
Expand Down
18 changes: 18 additions & 0 deletions compiler/control/OMROptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1493,6 +1493,11 @@ class OMR_EXTENSIBLE Options
_edoRecompSizeThreshold = 0;
_edoRecompSizeThresholdInStartupMode = 0;
_catchBlockCounterThreshold = 0;
_arraycopyRepMovsByteArrayThreshold = 32;
_arraycopyRepMovsCharArrayThreshold = 32;
_arraycopyRepMovsIntArrayThreshold = 32;
_arraycopyRepMovsLongArrayThreshold = 32;
_arraycopyRepMovsReferenceArrayThreshold = 32;

memset(_options, 0, sizeof(_options));
memset(_disabledOptimizations, false, sizeof(_disabledOptimizations));
Expand Down Expand Up @@ -1837,6 +1842,12 @@ class OMR_EXTENSIBLE Options
int32_t getEdoRecompSizeThresholdInStartupMode() { return _edoRecompSizeThresholdInStartupMode; }
int32_t getCatchBlockCounterThreshold() { return _catchBlockCounterThreshold; }

int32_t getArraycopyRepMovsByteArrayThreshold() { return _arraycopyRepMovsByteArrayThreshold; }
int32_t getArraycopyRepMovsCharArrayThreshold() { return _arraycopyRepMovsCharArrayThreshold; }
int32_t getArraycopyRepMovsIntArrayThreshold() { return _arraycopyRepMovsIntArrayThreshold; }
int32_t getArraycopyRepMovsLongArrayThreshold() { return _arraycopyRepMovsLongArrayThreshold; }
int32_t getArraycopyRepMovsReferenceArrayThreshold() { return _arraycopyRepMovsReferenceArrayThreshold; }


public:

Expand Down Expand Up @@ -2517,6 +2528,13 @@ class OMR_EXTENSIBLE Options
int32_t _edoRecompSizeThreshold; // Size threshold (in nodes) for candidates to recompilation through EDO
int32_t _edoRecompSizeThresholdInStartupMode; // Size threshold (in nodes) for candidates to recompilation through EDO during startup
int32_t _catchBlockCounterThreshold; // Counter threshold for catch blocks to trigger more aggresive inlining on the throw path

int32_t _arraycopyRepMovsByteArrayThreshold; // Byte array copy threshold for using REP MOVS instructions. Only supports 32 or 64 bytes
int32_t _arraycopyRepMovsCharArrayThreshold; // Char array copy threshold for using REP MOVS instructions. Only supports 32 or 64 bytes
int32_t _arraycopyRepMovsIntArrayThreshold; // Int array copy threshold for using REP MOVS instructions. Only supports 32, 64, or 128 bytes
int32_t _arraycopyRepMovsLongArrayThreshold; // Long array copy threshold for using REP MOVS instructions. Only supports 32, 64, or 128 bytes
int32_t _arraycopyRepMovsReferenceArrayThreshold; // Reference array copy threshold for using REP MOVS instructions. Only supports 32, 64, or 128 bytes

}; // TR::Options

}
Expand Down
34 changes: 33 additions & 1 deletion compiler/x/codegen/OMRTreeEvaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2602,7 +2602,7 @@ static void arrayCopyPrimitiveInlineSmallSizeWithoutREPMOVS(TR::Node* node,
cg->stopUsingRegister(tmpXmmYmmReg2);
}

static bool enablePrimitiveArrayCopyInlineSmallSizeWithoutREPMOVS(uint8_t elementSize, TR::CodeGenerator* cg, int& threshold)
static bool enablePrimitiveArrayCopyInlineSmallSizeWithoutREPMOVS(uint8_t elementSize, TR::CodeGenerator* cg, int32_t& threshold)
{
static bool disable8BitPrimitiveArrayCopyInlineSmallSizeWithoutREPMOVS = feGetEnv("TR_Disable8BitPrimitiveArrayCopyInlineSmallSizeWithoutREPMOVS") != NULL;
static bool disable16BitPrimitiveArrayCopyInlineSmallSizeWithoutREPMOVS = feGetEnv("TR_Disable16BitPrimitiveArrayCopyInlineSmallSizeWithoutREPMOVS") != NULL;
Expand All @@ -2617,20 +2617,52 @@ static bool enablePrimitiveArrayCopyInlineSmallSizeWithoutREPMOVS(uint8_t elemen
switch (elementSize)
{
case 8:
{
disableEnhancement = disable64BitPrimitiveArrayCopyInlineSmallSizeWithoutREPMOVS
|| cg->comp()->getOption(TR_Disable64BitPrimitiveArrayCopyInlineSmallSizeWithoutREPMOVS);

int32_t newThreshold = cg->comp()->getOptions()->getArraycopyRepMovsLongArrayThreshold();
if ((threshold < newThreshold) && ((newThreshold == 64) || (newThreshold == 128)))
{
// If the CPU doesn't support AVX512, reduce the threshold to 64 bytes
threshold = ((newThreshold == 128) && !cg->comp()->target().cpu.supportsFeature(OMR_FEATURE_X86_AVX512F)) ? 64 : newThreshold;
}
}
break;
case 4:
{
disableEnhancement = disable32BitPrimitiveArrayCopyInlineSmallSizeWithoutREPMOVS
|| cg->comp()->getOption(TR_Disable32BitPrimitiveArrayCopyInlineSmallSizeWithoutREPMOVS);

int32_t newThreshold = cg->comp()->getOptions()->getArraycopyRepMovsIntArrayThreshold();
if ((threshold < newThreshold) && ((newThreshold == 64) || (newThreshold == 128)))
{
// If the CPU doesn't support AVX512, reduce the threshold to 64 bytes
threshold = ((newThreshold == 128) && !cg->comp()->target().cpu.supportsFeature(OMR_FEATURE_X86_AVX512F)) ? 64 : newThreshold;
}
}
break;
case 2:
{
disableEnhancement = disable16BitPrimitiveArrayCopyInlineSmallSizeWithoutREPMOVS
|| cg->comp()->getOption(TR_Disable16BitPrimitiveArrayCopyInlineSmallSizeWithoutREPMOVS);

int32_t newThreshold = cg->comp()->getOptions()->getArraycopyRepMovsCharArrayThreshold();

// Char array enhancement supports only 32 or 64 bytes
threshold = (newThreshold == 64) ? 64 : threshold;
}
break;
default: // 1 byte
{
disableEnhancement = disable8BitPrimitiveArrayCopyInlineSmallSizeWithoutREPMOVS
|| cg->comp()->getOption(TR_Disable8BitPrimitiveArrayCopyInlineSmallSizeWithoutREPMOVS);

int32_t newThreshold = cg->comp()->getOptions()->getArraycopyRepMovsByteArrayThreshold();

// Byte array enhancement supports only 32 or 64 bytes
threshold = (newThreshold == 64) ? 64 : threshold;
}
break;
}

Expand Down

0 comments on commit 330a128

Please sign in to comment.