Skip to content

Constant expression evaluation for offset calculations #9791

@MichalStrehovsky

Description

@MichalStrehovsky
.assembly extern System.Runtime { }

.assembly byrefmath { }

.class private sequential ansi sealed beforefieldinit Foo
    extends [System.Runtime]System.ValueType
{
    .field public int32 X
    .field public int32 Y
}

.method public hidebysig static int32 Main() cil managed
{
  .locals init (valuetype Foo)
  .entrypoint
  ldloca 0
  ldflda int32 Foo::Y
  ldloca 0
  sub
  ret
}

This should be possible to evaluate to a constant because the result is known at compile time. RyuJIT currently generates:

G_M30739_IG01:
       50                   push     rax
       33C0                 xor      rax, rax
       48890424             mov      qword ptr [rsp], rax

G_M30739_IG02:
       488D442404           lea      rax, bword ptr [rsp+04H]
       488D1424             lea      rdx, bword ptr [rsp]
       482BC2               sub      rax, rdx

G_M30739_IG03:
       4883C408             add      rsp, 8
       C3                   ret

category:cq
theme:basic-cq
skill-level:intermediate
cost:small

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions