Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable constant CSE for ARM #100054

Merged
merged 1 commit into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -7061,6 +7061,9 @@ class Compiler
return (enckey & ~TARGET_SIGN_BIT) << CSE_CONST_SHARED_LOW_BITS;
}

static bool optSharedConstantCSEEnabled();
static bool optConstantCSEEnabled();

/**************************************************************************
* Value Number based CSEs
*************************************************************************/
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/jitconfigvalues.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,9 @@ CONFIG_INTEGER(JitDisableSimdVN, W("JitDisableSimdVN"), 0) // Default 0, ValueNu
// If 3, disable both SIMD and HW Intrinsic nodes
#endif // FEATURE_SIMD

// Default 0, enable the CSE of Constants, including nearby offsets. (only for ARM64)
// Default 0, enable the CSE of Constants, including nearby offsets. (only for ARM/ARM64)
// If 1, disable all the CSE of Constants
// If 2, enable the CSE of Constants but don't combine with nearby offsets. (only for ARM64)
// If 2, enable the CSE of Constants but don't combine with nearby offsets. (only for ARM/ARM64)
// If 3, enable the CSE of Constants including nearby offsets. (all platforms)
// If 4, enable the CSE of Constants but don't combine with nearby offsets. (all platforms)
//
Expand Down
109 changes: 61 additions & 48 deletions src/coreclr/jit/optcse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,26 +499,11 @@ unsigned optCSEKeyToHashIndex(size_t key, size_t optCSEhashSize)
//
unsigned Compiler::optValnumCSE_Index(GenTree* tree, Statement* stmt)
{
size_t key;
unsigned hval;
CSEdsc* hashDsc;
bool enableSharedConstCSE = false;
bool isSharedConst = false;
int configValue = JitConfig.JitConstCSE();

#if defined(TARGET_ARMARCH)
// ARMARCH - allow to combine with nearby offsets, when config is not 2 or 4
if ((configValue != CONST_CSE_ENABLE_ARM_NO_SHARING) && (configValue != CONST_CSE_ENABLE_ALL_NO_SHARING))
{
enableSharedConstCSE = true;
}
#endif // TARGET_ARMARCH

// All Platforms - also allow to combine with nearby offsets, when config is 3
if (configValue == CONST_CSE_ENABLE_ALL)
{
enableSharedConstCSE = true;
}
size_t key;
unsigned hval;
CSEdsc* hashDsc;
const bool enableSharedConstCSE = optSharedConstantCSEEnabled();
bool isSharedConst = false;

// We use the liberal Value numbers when building the set of CSE
ValueNum vnLib = tree->GetVN(VNK_Liberal);
Expand Down Expand Up @@ -1759,34 +1744,12 @@ void Compiler::optValnumCSE_Availability()
//
CSE_HeuristicCommon::CSE_HeuristicCommon(Compiler* pCompiler) : m_pCompiler(pCompiler)
{
m_addCSEcount = 0; /* Count of the number of LclVars for CSEs that we added */
sortTab = nullptr;
sortSiz = 0;
madeChanges = false;
codeOptKind = m_pCompiler->compCodeOpt();

enableConstCSE = true;

int configValue = JitConfig.JitConstCSE();

// all platforms - disable CSE of constant values when config is 1
if (configValue == CONST_CSE_DISABLE_ALL)
{
enableConstCSE = false;
}

#if !defined(TARGET_ARM64)
// non-ARM64 platforms - disable by default
//
enableConstCSE = false;

// Check for the two enable cases for all platforms
//
if ((configValue == CONST_CSE_ENABLE_ALL) || (configValue == CONST_CSE_ENABLE_ALL_NO_SHARING))
{
enableConstCSE = true;
}
#endif
m_addCSEcount = 0; /* Count of the number of LclVars for CSEs that we added */
sortTab = nullptr;
sortSiz = 0;
madeChanges = false;
codeOptKind = m_pCompiler->compCodeOpt();
enableConstCSE = Compiler::optConstantCSEEnabled();

#ifdef DEBUG
// Track the order of CSEs done (candidate number)
Expand Down Expand Up @@ -5453,6 +5416,56 @@ void Compiler::optCleanupCSEs()
}
}

//---------------------------------------------------------------------------
// optSharedConstantCSEEnabled: Returns `true` if shared constant CSE is enabled.
//
// Notes: see `optConstantCSEEnabled` for detecting if general constant CSE is enabled.
//
// static
bool Compiler::optSharedConstantCSEEnabled()
{
bool enableSharedConstCSE = false;
int configValue = JitConfig.JitConstCSE();

if (configValue == CONST_CSE_ENABLE_ALL)
{
enableSharedConstCSE = true;
}
#if defined(TARGET_ARMARCH)
else if (configValue == CONST_CSE_ENABLE_ARM)
{
enableSharedConstCSE = true;
}
#endif // TARGET_ARMARCH

return enableSharedConstCSE;
}

//---------------------------------------------------------------------------
// optConstantCSEEnabled: Returns `true` if constant CSE is enabled.
//
// Notes: see `optSharedConstantCSEEnabled` for detecting if shared constant CSE is enabled.
//
// static
bool Compiler::optConstantCSEEnabled()
{
bool enableConstCSE = false;
int configValue = JitConfig.JitConstCSE();

if ((configValue == CONST_CSE_ENABLE_ALL) || (configValue == CONST_CSE_ENABLE_ALL_NO_SHARING))
{
enableConstCSE = true;
}
#if defined(TARGET_ARMARCH)
else if ((configValue == CONST_CSE_ENABLE_ARM) || (configValue == CONST_CSE_ENABLE_ARM_NO_SHARING))
{
enableConstCSE = true;
}
#endif

return enableConstCSE;
}

#ifdef DEBUG

/*****************************************************************************
Expand Down
Loading