You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When writing generic types, using a pattern as seen in Vector<T> (if (typeof(T) == typeof(int)) ... if (typeof(T) == typeof(float)) ...) once this construct grows to 9 blocks JIT will end up not correctly eliding some casts:
See sharplab
Removing any two blocks from As2<T> will improve code gen significantly (matching a non-generic version & the other version)
splitting up the function will also resolve the issue.
@AndyAyersMS This is a bit of common pattern that I've noticed while using Sharplab, primarily because it comes up when doing this. I've always assumed it was some bug "in the toolchain".
The inliner has a budget that it uses to prevent runaway inlining, and it is tripping (prematurely) in this case, as (generally speaking) AggressiveInlining methods should be exempt from budgeting.
Activity
AndyAyersMS commentedon Jun 18, 2020
The sharplab link is showing codegen for . Net Framework x86 jit. For core this sharplab is more relevant.
Either way we're tail calling into
C.As2instead of inlining it, which seems odd. I'll dig in and see what's up.SingleAccretion commentedon Jun 18, 2020
@AndyAyersMS This is a bit of common pattern that I've noticed while using Sharplab, primarily because it comes up when doing this. I've always assumed it was some bug "in the toolchain".
AndyAyersMS commentedon Jun 18, 2020
The inliner has a budget that it uses to prevent runaway inlining, and it is tripping (prematurely) in this case, as (generally speaking)
AggressiveInliningmethods should be exempt from budgeting.That explains why the behavior changes as more checks are added -- at some point the extra IL pushes
As2over budget.Let me look into fixing this.
JIT: allow some aggressive inlines to go over budget
JIT: allow some aggressive inlines to go over budget (#38163)