-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Optimize comparison of unknown type with a typeof #31686
Closed
Closed
Commits on Feb 6, 2020
-
Optimize comparison of unknown type with a typeof
The JIT currently optimizes `System.Type` comparisons that involve either `typeof` on both sides of the comparison, or `typeof` on one side and `object.GetType` on the other. This adds handling for "anything" on one side and a `typeof` on the other side. The optimization removes the materialization of the `System.Type` instance from the `typeof`. This is done by calling a new helper that can compare a raw type handle with a `System.Type` instance. Obligatory before/after: ```csharp class Program { static Type s_Object = typeof(object); static int Main() { if (typeof(object) != s_Object) return 1; return 100; } } ``` Before: ```asm 56 push rsi 4883EC20 sub rsp, 32 488B0D00000000 mov rcx, qword ptr [(reloc)] FF1500000000 call [CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE] 488BF0 mov rsi, rax FF1500000000 call [CORINFO_HELP_READYTORUN_STATIC_BASE] 483B30 cmp rsi, gword ptr [rax] 740B je SHORT G_M24376_IG05 B801000000 mov eax, 1 4883C420 add rsp, 32 5E pop rsi C3 ret B864000000 mov eax, 100 4883C420 add rsp, 32 5E pop rsi C3 ret ``` After: ```asm 4883EC28 sub rsp, 40 FF1500000000 call [CORINFO_HELP_READYTORUN_STATIC_BASE] 488B10 mov rdx, gword ptr [rax] 488B0D00000000 mov rcx, qword ptr [(reloc)] FF1500000000 call [CORINFO_HELP_ARE_TYPEHANDLE_AND_TYPE_EQUIVALENT] 85C0 test eax, eax 750A jne SHORT G_M24376_IG05 B801000000 mov eax, 1 4883C428 add rsp, 40 C3 ret B864000000 mov eax, 100 4883C428 add rsp, 40 C3 ret ```
Configuration menu - View commit details
-
Copy full SHA for 11f47d1 - Browse repository at this point
Copy the full SHA 11f47d1View commit details -
Configuration menu - View commit details
-
Copy full SHA for 00b8a22 - Browse repository at this point
Copy the full SHA 00b8a22View commit details -
Configuration menu - View commit details
-
Copy full SHA for 1615ea5 - Browse repository at this point
Copy the full SHA 1615ea5View commit details -
Configuration menu - View commit details
-
Copy full SHA for 6996492 - Browse repository at this point
Copy the full SHA 6996492View commit details
Commits on Feb 17, 2020
-
Configuration menu - View commit details
-
Copy full SHA for 671fdf0 - Browse repository at this point
Copy the full SHA 671fdf0View commit details -
Configuration menu - View commit details
-
Copy full SHA for f82a5fc - Browse repository at this point
Copy the full SHA f82a5fcView commit details -
Configuration menu - View commit details
-
Copy full SHA for 665385a - Browse repository at this point
Copy the full SHA 665385aView commit details
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.