Skip to content

Unnecessary stack spilling for struct instant property access #57055

Description

@hez2010

Description

Repro:

int Test()
{
    var a = new A().X;
    return 1 + a;
}

struct A
{
    public int X { get; }
}

Codegen:

push rax
xor eax, eax
mov [rsp], rax
lea rax, [rsp]
xor edx, edx
mov [rax], edx
mov eax, [rax]
inc eax
add rsp, 8
ret

But if I change the code to:

int Test()
{
    var a = new A();
    return 1 + a.X;
}

struct A
{
    public int X { get; }
}

The codegen will become:

mov eax, 1
ret

I think JIT should recognize patterns like: initobj - call - stloc - ldloc

Also applies to method calls.

Configuration

.NET 6 Preivew 6

Activity

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 SuperPMIhelp wanted[up-for-grabs] Good issue for external contributorstenet-performancePerformance related issue

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions