Skip to content

Commit b549229

Browse files
Enable constant CSE for ARM (#100054)
Also, extract out the code that determines if constant CSE or shared constant CSE are enabled, and rewrite it to be easier to understand.
1 parent 51782dc commit b549229

File tree

3 files changed

+66
-50
lines changed

3 files changed

+66
-50
lines changed

src/coreclr/jit/compiler.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7083,6 +7083,9 @@ class Compiler
70837083
return (enckey & ~TARGET_SIGN_BIT) << CSE_CONST_SHARED_LOW_BITS;
70847084
}
70857085

7086+
static bool optSharedConstantCSEEnabled();
7087+
static bool optConstantCSEEnabled();
7088+
70867089
/**************************************************************************
70877090
* Value Number based CSEs
70887091
*************************************************************************/

src/coreclr/jit/jitconfigvalues.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,9 +379,9 @@ CONFIG_INTEGER(JitDisableSimdVN, W("JitDisableSimdVN"), 0) // Default 0, ValueNu
379379
// If 3, disable both SIMD and HW Intrinsic nodes
380380
#endif // FEATURE_SIMD
381381

382-
// Default 0, enable the CSE of Constants, including nearby offsets. (only for ARM64)
382+
// Default 0, enable the CSE of Constants, including nearby offsets. (only for ARM/ARM64)
383383
// If 1, disable all the CSE of Constants
384-
// If 2, enable the CSE of Constants but don't combine with nearby offsets. (only for ARM64)
384+
// If 2, enable the CSE of Constants but don't combine with nearby offsets. (only for ARM/ARM64)
385385
// If 3, enable the CSE of Constants including nearby offsets. (all platforms)
386386
// If 4, enable the CSE of Constants but don't combine with nearby offsets. (all platforms)
387387
//

src/coreclr/jit/optcse.cpp

Lines changed: 61 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -499,26 +499,11 @@ unsigned optCSEKeyToHashIndex(size_t key, size_t optCSEhashSize)
499499
//
500500
unsigned Compiler::optValnumCSE_Index(GenTree* tree, Statement* stmt)
501501
{
502-
size_t key;
503-
unsigned hval;
504-
CSEdsc* hashDsc;
505-
bool enableSharedConstCSE = false;
506-
bool isSharedConst = false;
507-
int configValue = JitConfig.JitConstCSE();
508-
509-
#if defined(TARGET_ARMARCH)
510-
// ARMARCH - allow to combine with nearby offsets, when config is not 2 or 4
511-
if ((configValue != CONST_CSE_ENABLE_ARM_NO_SHARING) && (configValue != CONST_CSE_ENABLE_ALL_NO_SHARING))
512-
{
513-
enableSharedConstCSE = true;
514-
}
515-
#endif // TARGET_ARMARCH
516-
517-
// All Platforms - also allow to combine with nearby offsets, when config is 3
518-
if (configValue == CONST_CSE_ENABLE_ALL)
519-
{
520-
enableSharedConstCSE = true;
521-
}
502+
size_t key;
503+
unsigned hval;
504+
CSEdsc* hashDsc;
505+
const bool enableSharedConstCSE = optSharedConstantCSEEnabled();
506+
bool isSharedConst = false;
522507

523508
// We use the liberal Value numbers when building the set of CSE
524509
ValueNum vnLib = tree->GetVN(VNK_Liberal);
@@ -1759,34 +1744,12 @@ void Compiler::optValnumCSE_Availability()
17591744
//
17601745
CSE_HeuristicCommon::CSE_HeuristicCommon(Compiler* pCompiler) : m_pCompiler(pCompiler)
17611746
{
1762-
m_addCSEcount = 0; /* Count of the number of LclVars for CSEs that we added */
1763-
sortTab = nullptr;
1764-
sortSiz = 0;
1765-
madeChanges = false;
1766-
codeOptKind = m_pCompiler->compCodeOpt();
1767-
1768-
enableConstCSE = true;
1769-
1770-
int configValue = JitConfig.JitConstCSE();
1771-
1772-
// all platforms - disable CSE of constant values when config is 1
1773-
if (configValue == CONST_CSE_DISABLE_ALL)
1774-
{
1775-
enableConstCSE = false;
1776-
}
1777-
1778-
#if !defined(TARGET_ARM64)
1779-
// non-ARM64 platforms - disable by default
1780-
//
1781-
enableConstCSE = false;
1782-
1783-
// Check for the two enable cases for all platforms
1784-
//
1785-
if ((configValue == CONST_CSE_ENABLE_ALL) || (configValue == CONST_CSE_ENABLE_ALL_NO_SHARING))
1786-
{
1787-
enableConstCSE = true;
1788-
}
1789-
#endif
1747+
m_addCSEcount = 0; /* Count of the number of LclVars for CSEs that we added */
1748+
sortTab = nullptr;
1749+
sortSiz = 0;
1750+
madeChanges = false;
1751+
codeOptKind = m_pCompiler->compCodeOpt();
1752+
enableConstCSE = Compiler::optConstantCSEEnabled();
17901753

17911754
#ifdef DEBUG
17921755
// Track the order of CSEs done (candidate number)
@@ -5460,6 +5423,56 @@ void Compiler::optCleanupCSEs()
54605423
}
54615424
}
54625425

5426+
//---------------------------------------------------------------------------
5427+
// optSharedConstantCSEEnabled: Returns `true` if shared constant CSE is enabled.
5428+
//
5429+
// Notes: see `optConstantCSEEnabled` for detecting if general constant CSE is enabled.
5430+
//
5431+
// static
5432+
bool Compiler::optSharedConstantCSEEnabled()
5433+
{
5434+
bool enableSharedConstCSE = false;
5435+
int configValue = JitConfig.JitConstCSE();
5436+
5437+
if (configValue == CONST_CSE_ENABLE_ALL)
5438+
{
5439+
enableSharedConstCSE = true;
5440+
}
5441+
#if defined(TARGET_ARMARCH)
5442+
else if (configValue == CONST_CSE_ENABLE_ARM)
5443+
{
5444+
enableSharedConstCSE = true;
5445+
}
5446+
#endif // TARGET_ARMARCH
5447+
5448+
return enableSharedConstCSE;
5449+
}
5450+
5451+
//---------------------------------------------------------------------------
5452+
// optConstantCSEEnabled: Returns `true` if constant CSE is enabled.
5453+
//
5454+
// Notes: see `optSharedConstantCSEEnabled` for detecting if shared constant CSE is enabled.
5455+
//
5456+
// static
5457+
bool Compiler::optConstantCSEEnabled()
5458+
{
5459+
bool enableConstCSE = false;
5460+
int configValue = JitConfig.JitConstCSE();
5461+
5462+
if ((configValue == CONST_CSE_ENABLE_ALL) || (configValue == CONST_CSE_ENABLE_ALL_NO_SHARING))
5463+
{
5464+
enableConstCSE = true;
5465+
}
5466+
#if defined(TARGET_ARMARCH)
5467+
else if ((configValue == CONST_CSE_ENABLE_ARM) || (configValue == CONST_CSE_ENABLE_ARM_NO_SHARING))
5468+
{
5469+
enableConstCSE = true;
5470+
}
5471+
#endif
5472+
5473+
return enableConstCSE;
5474+
}
5475+
54635476
#ifdef DEBUG
54645477

54655478
/*****************************************************************************

0 commit comments

Comments
 (0)