diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index 70384056e0709a..18e538e3010d04 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -4399,6 +4399,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 diff --git a/src/coreclr/jit/jitconfigvalues.h b/src/coreclr/jit/jitconfigvalues.h index 0d701bb958ce30..33cf1d74f206eb 100644 --- a/src/coreclr/jit/jitconfigvalues.h +++ b/src/coreclr/jit/jitconfigvalues.h @@ -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 diff --git a/src/coreclr/jit/optcse.cpp b/src/coreclr/jit/optcse.cpp index af04a6b11fcc3d..6898c5ae62a44d 100644 --- a/src/coreclr/jit/optcse.cpp +++ b/src/coreclr/jit/optcse.cpp @@ -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) @@ -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; }