Skip to content

Unused struct fields sometimes improve the codegen #79928

@am11

Description

@am11

Given:

public struct T
{
    private double x;
    private byte y; // unused
    private int z; // unused

    public static double M(double v)
    {
        T t = new T { x = v };
        return t.x;
    }
}

codegen of M looks like:

T:M(double):double:
       ret  

after removing unused fields (y and z), it turns into:

T:M(double):double:
       push     rax
       movsd    qword ptr [rsp], xmm0
       add      rsp, 8
       ret

IOW, it needs at least one unused field (i.e. size of struct > 8) for this optimization to kick in.

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