Skip to content

JIT known generic casts not elided #38106

Closed

Description

@HurricanKai

Description

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.

Activity

  1. added
    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
    untriagedNew issue has not been triaged by the area owner
    on Jun 18, 2020
  2. AndyAyersMS commented on Jun 18, 2020

    @AndyAyersMS
    Member

    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.As2 instead of inlining it, which seems odd. I'll dig in and see what's up.

    C.AsByte2(Single)
        L0000: vzeroupper
        L0003: mov rax, C.As2[[System.Byte, System.Private.CoreLib]](Single)
        L000d: jmp rax
  3. SingleAccretion commented on Jun 18, 2020

    @SingleAccretion
    Contributor

    @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".

  4. removed
    untriagedNew issue has not been triaged by the area owner
    on Jun 18, 2020
  5. added this to the 5.0.0 milestone on Jun 18, 2020
  6. AndyAyersMS commented on Jun 18, 2020

    @AndyAyersMS
    Member

    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.

    Inlines into 06000003 C:AsByte2(float):ubyte
      [0 IL=0001 TR=000001 06000006] [FAILED: inline exceeds budget] C:As2(float):ubyte
    

    That explains why the behavior changes as more checks are added -- at some point the extra IL pushes As2 over budget.

    Let me look into fixing this.

  7. added a commit that references this issue on Jun 19, 2020
    8a89a0d
  8. self-assigned this
    on Jun 23, 2020
  9. added a commit that references this issue on Jun 23, 2020
    0256379
  10. ghost locked as resolved and limited conversation to collaborators on Dec 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions