Skip to content

Commit

Permalink
JIT: Unroll more Equals/StartsWith/EndsWith on arm64 (dotnet#109036)
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorBo authored Nov 20, 2024
1 parent 2eb6a2a commit db6cef1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
9 changes: 9 additions & 0 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -9573,6 +9573,7 @@ class Compiler
Memset,
Memcpy,
Memmove,
MemcmpU16,
ProfiledMemmove,
ProfiledMemcmp
};
Expand Down Expand Up @@ -9649,6 +9650,14 @@ class Compiler
threshold = maxRegSize * 4;
}

if (type == UnrollKind::MemcmpU16)
{
threshold = maxRegSize * 2;
#ifdef TARGET_ARM64
threshold = maxRegSize * 6;
#endif
}

// For profiled memcmp/memmove we don't want to unroll too much as it's just a guess,
// and it works better for small sizes.
if ((type == UnrollKind::ProfiledMemcmp) || (type == UnrollKind::ProfiledMemmove))
Expand Down
10 changes: 4 additions & 6 deletions src/coreclr/jit/importervectorization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#pragma hdrstop
#endif

// For now the max possible size is Vector512<ushort>.Count * 2
#define MaxPossibleUnrollSize 64
// Overestimated threshold to avoid memory allocations,
#define MaxPossibleUnrollSize 128

//------------------------------------------------------------------------
// importer_vectorization.cpp
Expand Down Expand Up @@ -484,9 +484,8 @@ GenTree* Compiler::impUtf16StringComparison(StringComparisonKind kind, CORINFO_S
// We were unable to get the literal (e.g. dynamic context)
return nullptr;
}
if (cnsLength > (int)genTypeSize(roundDownMaxType(MaxPossibleUnrollSize * 2)))
if (cnsLength > ((int)getUnrollThreshold(MemcmpU16) / 2))
{
// Not more than two loads (of max width)
JITDUMP("UTF16 data is too long to unroll - bail out.\n");
return nullptr;
}
Expand Down Expand Up @@ -642,9 +641,8 @@ GenTree* Compiler::impUtf16SpanComparison(StringComparisonKind kind, CORINFO_SIG
// We were unable to get the literal (e.g. dynamic context)
return nullptr;
}
if (cnsLength > (int)genTypeSize(roundDownMaxType(MaxPossibleUnrollSize * 2)))
if (cnsLength > ((int)getUnrollThreshold(MemcmpU16) / 2))
{
// Not more than two loads (of max width)
JITDUMP("UTF16 data is too long to unroll - bail out.\n");
return nullptr;
}
Expand Down

0 comments on commit db6cef1

Please sign in to comment.