Skip to content

Commit

Permalink
JIT: Enable CSE for CLS/STR const handles (#70580)
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorBo committed Jun 13, 2022
1 parent e4aba62 commit 76d3224
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
5 changes: 5 additions & 0 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4401,6 +4401,11 @@ unsigned Compiler::gtSetEvalOrder(GenTree* tree)
{
costSz = 10;
costEx = 2;
if (con->IsIconHandle())
{
// A sort of a hint for CSE to try harder for class handles
costEx += 1;
}
}
#endif // TARGET_AMD64
else
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 @@ -354,9 +354,9 @@ CONFIG_INTEGER(JitDisableSimdVN, W("JitDisableSimdVN"), 0) // Default 0, ValueNu
//
CONFIG_INTEGER(JitConstCSE, W("JitConstCSE"), 0)

#define CONST_CSE_ENABLE_ARM64 0
#define CONST_CSE_ENABLE_ARM 0
#define CONST_CSE_DISABLE_ALL 1
#define CONST_CSE_ENABLE_ARM64_NO_SHARING 2
#define CONST_CSE_ENABLE_ARM_NO_SHARING 2
#define CONST_CSE_ENABLE_ALL 3
#define CONST_CSE_ENABLE_ALL_NO_SHARING 4

Expand Down
14 changes: 8 additions & 6 deletions src/coreclr/jit/optcse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,13 +385,13 @@ unsigned Compiler::optValnumCSE_Index(GenTree* tree, Statement* stmt)
bool isSharedConst = false;
int configValue = JitConfig.JitConstCSE();

#if defined(TARGET_ARM64)
// ARM64 - allow to combine with nearby offsets, when config is not 2 or 4
if ((configValue != CONST_CSE_ENABLE_ARM64_NO_SHARING) && (configValue != CONST_CSE_ENABLE_ALL_NO_SHARING))
#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_ARM64
#endif // TARGET_ARMARCH

// All Platforms - also allow to combine with nearby offsets, when config is 3
if (configValue == CONST_CSE_ENABLE_ALL)
Expand Down Expand Up @@ -785,10 +785,12 @@ bool Compiler::optValnumCSE_Locate()
}

// Don't allow CSE of constants if it is disabled
//
if (tree->IsIntegralConst())
{
if (!enableConstCSE)
if (!enableConstCSE &&
// Unconditionally allow these constant handles to be CSE'd
!tree->IsIconHandle(GTF_ICON_STATIC_HDL) && !tree->IsIconHandle(GTF_ICON_CLASS_HDL) &&
!tree->IsIconHandle(GTF_ICON_STR_HDL))
{
continue;
}
Expand Down

0 comments on commit 76d3224

Please sign in to comment.