Uh oh!
There was an error while loading. Please reload this page.
Optimize GetType with known type - #87579
Conversation
ghost
commented
Jun 14, 2023
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch Issue DetailsShould help with the codegen in this simple method with ; Assembly listing for method Program:A(C):System.Type; Emitting BLENDED_CODE for X64 CPU with AVX - Windows; optimized code; rsp based frame; partially interruptible; No PGO data; 0 inlinees with PGO data; 1 single block inlinees; 0 inlinees without PGO dataG_M000_IG01: ;; offset=0000Hsubrsp,40G_M000_IG02: ;; offset=0004Hcall System.Object:GetType():System.Type:thisnopG_M000_IG03: ;; offset=000AHaddrsp,40ret; Total bytes of code 15
|
Uh oh!
There was an error while loading. Please reload this page.
EgorBo
commented
Jun 16, 2023
How is this different from #87101 except doing the work earlier? |
MichalPetryka
commented
Jun 16, 2023
I missed that change when I originally opened this PR (I only checked if the latest preview did this optimization and it didn't) and when @SingleAccretion told me about it, I've decided to let the jobs run to see if SPMI shows any meaningful diffs cause of running earlier which allows folding of stuff like IsKnownConstant and since this also handles |
EgorBo
commented
Jun 16, 2023
That can be handled in VN in my change by adding a nullref exceptionset I guess, I just didn't bother because the diffs were not too promising |
@MichalPetryka my guess is that the NativeAOT failures are because this brings into existence types that shouldn't exist. We have an optimization that optimizes MethodTables for things that shouldn't exist into a smaller data structure. Is it possible that for this code: Console.WriteLine(Holder.TheX.GetType());sealedclassX{}sealedclassHolder{publicstaticXTheX=null;}Codegen will replace this with this? Console.WriteLine(typeof(X));The problem is that when we're doing optimized code generation, we need to compute the full set of types that had a MethodTable in the whole program. For the above program, we would not include MT for X because it was not needed. The failure you're hitting looks like a situation where we didn't expect the MT to be needed so we generated a gimped "MT" that doesn't actually have much in it (and we can't construct a System.Type for it, among other things). This should also be asserting the compiler. Related: dotnet/runtimelab#1128 |
It'd actually be like this: Nullcheck(Holder.TheX);Console.WriteLine(typeof(X));Which would prevent the code from getting to the typeof (and if possible I'd assume the compiler would fold the nullcheck to always true since it knows it can remove the metadata). newMyType().GetType().ToString();Could the unused new removal cause NAOT to omit metadata after the transformation? |
MichalStrehovsky
commented
Jun 23, 2023
Got a local repro. The codegen for: publicstringGenericFooFunc3<M>(){returnthis.GetType()+"::GenericFooFunc3 called on "+typeof(T)+"::"+typeof(M);}Is: Notice we're grabbing the |
MichalPetryka
commented
Jun 23, 2023
I've accidentally removed the shared generic check, readded it now, the issue is that we're getting invalid handled even with that. |
MichalStrehovsky
commented
Jun 23, 2023
I'm still seeing the same bad codegen with your latest commit. |
MichalPetryka
commented
Jun 23, 2023
Yeah that's the issue here, |
Unifies (Equality)Comparer.Default logic so that it matches between CoreCLR, NativeAOT, Mono in runtime and intrinsic implementations. Fixes devirt behaviour around Nullable types. Also enables devirt for non final types in CoreCLR and NativeAOT. Required for #87579. Fixes#87391. Co-authored-by: Jan Kotas <jkotas@microsoft.com>
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
MichalPetryka
commented
Jul 18, 2023
@MihuBot -dependsOn 88163 |
MichalPetryka
commented
Jul 19, 2023
Diffs seem to mostly be regressions, closing this then. |
Should help with the codegen in this simple method with
Cbeing a sealed type: