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

Expand String.EndsWith/MemoryExtensions.EndsWith in JIT #98593

Merged
merged 6 commits into from
Feb 20, 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
16 changes: 11 additions & 5 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -4418,17 +4418,23 @@ class Compiler
Ordinal = 4,
OrdinalIgnoreCase = 5
};
enum StringComparisonJoint
enum class StringComparisonJoint
{
Eq, // (d1 == cns1) && (s2 == cns2)
Xor, // (d1 ^ cns1) | (s2 ^ cns2)
};
GenTree* impStringEqualsOrStartsWith(bool startsWith, CORINFO_SIG_INFO* sig, unsigned methodFlags);
GenTree* impSpanEqualsOrStartsWith(bool startsWith, CORINFO_SIG_INFO* sig, unsigned methodFlags);
enum class StringComparisonKind
{
Equals,
StartsWith,
EndsWith
};
GenTree* impUtf16StringComparison(StringComparisonKind kind, CORINFO_SIG_INFO* sig, unsigned methodFlags);
GenTree* impUtf16SpanComparison(StringComparisonKind kind, CORINFO_SIG_INFO* sig, unsigned methodFlags);
GenTree* impExpandHalfConstEquals(GenTreeLclVarCommon* data,
GenTree* lengthFld,
bool checkForNull,
bool startsWith,
StringComparisonKind kind,
WCHAR* cnsData,
int len,
int dataOffset,
Expand All @@ -4438,7 +4444,7 @@ class Compiler
ssize_t offset,
ssize_t value,
StringComparison ignoreCase,
StringComparisonJoint joint = Eq);
StringComparisonJoint joint = StringComparisonJoint::Eq);
GenTree* impExpandHalfConstEqualsSWAR(
GenTreeLclVarCommon* data, WCHAR* cns, int len, int dataOffset, StringComparison cmpMode);
GenTree* impExpandHalfConstEqualsSIMD(
Expand Down
28 changes: 24 additions & 4 deletions src/coreclr/jit/importercalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2827,26 +2827,38 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis,

case NI_System_String_Equals:
{
retNode = impStringEqualsOrStartsWith(/*startsWith:*/ false, sig, methodFlags);
retNode = impUtf16StringComparison(StringComparisonKind::Equals, sig, methodFlags);
break;
}

case NI_System_MemoryExtensions_Equals:
case NI_System_MemoryExtensions_SequenceEqual:
{
retNode = impSpanEqualsOrStartsWith(/*startsWith:*/ false, sig, methodFlags);
retNode = impUtf16SpanComparison(StringComparisonKind::Equals, sig, methodFlags);
break;
}

case NI_System_String_StartsWith:
{
retNode = impStringEqualsOrStartsWith(/*startsWith:*/ true, sig, methodFlags);
retNode = impUtf16StringComparison(StringComparisonKind::StartsWith, sig, methodFlags);
break;
}

case NI_System_String_EndsWith:
{
retNode = impUtf16StringComparison(StringComparisonKind::EndsWith, sig, methodFlags);
break;
}

case NI_System_MemoryExtensions_StartsWith:
{
retNode = impSpanEqualsOrStartsWith(/*startsWith:*/ true, sig, methodFlags);
retNode = impUtf16SpanComparison(StringComparisonKind::StartsWith, sig, methodFlags);
break;
}

case NI_System_MemoryExtensions_EndsWith:
{
retNode = impUtf16SpanComparison(StringComparisonKind::EndsWith, sig, methodFlags);
break;
}

Expand Down Expand Up @@ -8932,6 +8944,10 @@ NamedIntrinsic Compiler::lookupNamedIntrinsic(CORINFO_METHOD_HANDLE method)
{
result = NI_System_MemoryExtensions_StartsWith;
}
else if (strcmp(methodName, "EndsWith") == 0)
{
result = NI_System_MemoryExtensions_EndsWith;
}
}
break;
}
Expand Down Expand Up @@ -9032,6 +9048,10 @@ NamedIntrinsic Compiler::lookupNamedIntrinsic(CORINFO_METHOD_HANDLE method)
{
result = NI_System_String_StartsWith;
}
else if (strcmp(methodName, "EndsWith") == 0)
{
result = NI_System_String_EndsWith;
}
}
break;
}
Expand Down
Loading
Loading