Skip to content

JIT: Methods with switches aren't inlineable #55336

Closed

Description

@EgorBo

Example:

public int Test1(char format) =>
    format switch
    {
        'A' => 1,
        'B' => 2,
        'C' => 3,
        'D' => 4,
        _ => 0,
    };

public int Test2() => Test1('B');

Codegen for Test2:

       mov      edx, 66
       jmp      ConsoleApp26.Program:Test1(ushort):int:this
; Total bytes of code: 10

Currently it's failed to inline into Test2:

INLINER: during 'fgInline' result 'failed this callee' reason 'has switch'

I guess it's tricky for the importer, but at least we could import it as a single JTRUE block when we pass a constant at the callsite (and that arg feeds that switch).

/cc @AndyAyersMS

Activity

  1. added
    tenet-performance
    on Jul 8, 2021
  2. ghost added
    area-CodeGen-coreclr
    on Jul 8, 2021
  3. ghost added
    untriaged
    on Jul 8, 2021
  4. added this to the 7.0.0 milestone on Jul 8, 2021
  5. self-assigned this
    on Jul 8, 2021
  6. removed
    untriaged
    on Jul 8, 2021
  7. MichalPetryka commented on Jul 8, 2021

    @MichalPetryka
    Contributor

    This is also a case for a switch on a sizeof(T) in a generic method with an unmanaged constraint, those switches should be completely ignored by the inliner as the JIT always knows which path will be taken.

  8. AndyAyersMS commented on Jul 9, 2021

    @AndyAyersMS
    Member

    See #10634 and #10658 (comment) -- latter has a prototype of the changes needed to enable inlining of switches.

    There is a cache of switch info kept in the jit (m_switchDescMap) that might need updating/invalidating too, I haven't looked.

  9. ghost added
    in-pr
    on Jul 11, 2021
  10. modified the milestones: 7.0.0, 6.0.0 on Jul 12, 2021
  11. ghost removed
    in-pr
    on Jul 14, 2021
  12. ghost locked as resolved and limited conversation to collaborators on Aug 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrtenet-performance

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions