-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Add IsKnownConstant jit helper and optimize 'str == ""' with str.StartsWith('c') #63734
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
Changes from 11 commits
9f55fa6
7d3ef94
0a717aa
407a953
9d45461
2f8a034
4883a46
aa88cf9
64843f0
2ebdae9
e264d27
f08a182
8e5fd0d
e2ebf30
895abc4
45bfe7c
80f9ddd
eebd8d1
e0e3e51
5b2fbfe
30e1855
3cb8402
7c7c264
a9b85fc
a3e5f3c
4947947
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3879,19 +3879,25 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis, | |
| return new (this, GT_LABEL) GenTree(GT_LABEL, TYP_I_IMPL); | ||
| } | ||
|
|
||
| if (((ni == NI_System_Runtime_CompilerServices_RuntimeHelpers_CreateSpan) || | ||
| (ni == NI_System_Runtime_CompilerServices_RuntimeHelpers_InitializeArray)) && | ||
| IsTargetAbi(CORINFO_CORERT_ABI)) | ||
| switch (ni) | ||
| { | ||
| // CreateSpan must be expanded for NativeAOT | ||
| mustExpand = true; | ||
| } | ||
| case NI_System_Runtime_CompilerServices_RuntimeHelpers_CreateSpan: | ||
| case NI_System_Runtime_CompilerServices_RuntimeHelpers_InitializeArray: | ||
| mustExpand = IsTargetAbi(CORINFO_CORERT_ABI); | ||
| break; | ||
|
|
||
| if ((ni == NI_System_ByReference_ctor) || (ni == NI_System_ByReference_get_Value) || | ||
| (ni == NI_System_Activator_AllocatorOf) || (ni == NI_System_Activator_DefaultConstructorOf) || | ||
| (ni == NI_System_Object_MethodTableOf) || (ni == NI_System_EETypePtr_EETypePtrOf)) | ||
| { | ||
| mustExpand = true; | ||
| case NI_System_ByReference_ctor: | ||
| case NI_System_ByReference_get_Value: | ||
| case NI_System_Activator_AllocatorOf: | ||
| case NI_System_Activator_DefaultConstructorOf: | ||
| case NI_System_Object_MethodTableOf: | ||
| case NI_System_EETypePtr_EETypePtrOf: | ||
| mustExpand = true; | ||
| break; | ||
|
|
||
| default: | ||
| break; | ||
| } | ||
|
|
||
| GenTree* retNode = nullptr; | ||
|
|
@@ -4007,6 +4013,30 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis, | |
| break; | ||
| } | ||
|
|
||
| case NI_System_Runtime_CompilerServices_RuntimeHelpers_IsKnownConstant: | ||
| { | ||
| if (opts.OptimizationEnabled()) | ||
|
||
| { | ||
| GenTree* op1 = impPopStack().val; | ||
| if (op1->OperIsConst()) | ||
|
||
| { | ||
| // op1 is a known constant, replace with 'true'. | ||
| impPopStack(); | ||
EgorBo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| retNode = gtNewIconNode(1); | ||
| JITDUMP("\nExpanding RuntimeHelpers.IsKnownConstant to true early\n"); | ||
| // We can also consider FTN_ADDR and typeof(T) here | ||
| } | ||
| else | ||
| { | ||
| // op1 is not a known constant, we'll do the expansion in morph | ||
| retNode = new (this, GT_INTRINSIC) GenTreeIntrinsic(TYP_INT, op1, ni, method); | ||
| JITDUMP("\nConverting RuntimeHelpers.IsKnownConstant to:\n"); | ||
| DISPTREE(retNode); | ||
| } | ||
| } | ||
| break; | ||
| } | ||
|
|
||
| case NI_System_Activator_AllocatorOf: | ||
| case NI_System_Activator_DefaultConstructorOf: | ||
| case NI_System_Object_MethodTableOf: | ||
|
|
@@ -5352,6 +5382,10 @@ NamedIntrinsic Compiler::lookupNamedIntrinsic(CORINFO_METHOD_HANDLE method) | |
| { | ||
| result = NI_System_Runtime_CompilerServices_RuntimeHelpers_InitializeArray; | ||
| } | ||
| else if (strcmp(methodName, "IsKnownConstant") == 0) | ||
| { | ||
| result = NI_System_Runtime_CompilerServices_RuntimeHelpers_IsKnownConstant; | ||
| } | ||
| } | ||
| else if (strncmp(namespaceName, "System.Runtime.Intrinsics", 25) == 0) | ||
| { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.