Skip to content

JIT: Fold constant access to RVA #64613

Description

@EgorBo

Fold constant accesses to RVA data (from #64612). Example:

static ReadOnlySpan<byte> data => new byte[] { 1, 2, 3, 4, 5 };

byte Test() => data[3];

Current codegen:

; Method Prog:Test():ubyte:this
       48B8A32BAD36FD010000 mov      rax, 0x1FD36AD2BA3
       0FB600               movzx    rax, byte  ptr [rax]
       C3                   ret      
; Total bytes of code: 14

Expected codegen:

; Method Prog:Test():ubyte:this
       B804000000           mov      eax, 4
       C3                   ret      
; Total bytes of code: 6

NOTES:

  • JIT is already able to do it for string literals e.g. "hello"[2] (see fgMorphArrayIndex)
  • C# should soon get a support for ROS<any primitive> = RVA, not just byte/bool as it is currently
  • We probably can't do it for RVAs in C++/CLI/CX which are mutable (check for mixed-mode)
  • This task most likely needs a new JIT-EE API or maybe the existing getArrayInitializationData is enough

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIhelp wanted[up-for-grabs] Good issue for external contributorstenet-performancePerformance related issue

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions