Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suboptimal struct zeroing in case of gc pointers #83297

Closed
EgorBo opened this issue Mar 11, 2023 · 4 comments · Fixed by #102132
Closed

Suboptimal struct zeroing in case of gc pointers #83297

EgorBo opened this issue Mar 11, 2023 · 4 comments · Fixed by #102132
Assignees
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI in-pr There is an active PR which will close this issue when it is merged
Milestone

Comments

@EgorBo
Copy link
Member

EgorBo commented Mar 11, 2023

public struct MyStruct
{
    public long a;
    public long b;
    public long c;
    public long d;
    public long e;
    public long f;
    public long g;
    public long h;
    public long i;
    public long j;
    public long k;
    public long l;
    public long m;
    public long n;
    public long o;
    public string s;
}

public MyStruct Foo()
{
    MyStruct s = default;
    return s;
}
; Method Program:Foo():Program+MyStruct:this
       33C0                 xor      eax, eax
       488902               mov      qword ptr [rdx], rax
       48894208             mov      qword ptr [rdx+08H], rax
       48894210             mov      qword ptr [rdx+10H], rax
       48894218             mov      qword ptr [rdx+18H], rax
       48894220             mov      qword ptr [rdx+20H], rax
       48894228             mov      qword ptr [rdx+28H], rax
       48894230             mov      qword ptr [rdx+30H], rax
       48894238             mov      qword ptr [rdx+38H], rax
       48894240             mov      qword ptr [rdx+40H], rax
       48894248             mov      qword ptr [rdx+48H], rax
       48894250             mov      qword ptr [rdx+50H], rax
       48894258             mov      qword ptr [rdx+58H], rax
       48894260             mov      qword ptr [rdx+60H], rax
       48894268             mov      qword ptr [rdx+68H], rax
       48894270             mov      qword ptr [rdx+70H], rax
       48894278             mov      qword ptr [rdx+78H], rax
       488BC2               mov      rax, rdx
       C3                   ret      
; Total bytes of code: 69

JIT gives up on SIMDs because of gc pointers in a struct while it could use SIMD only for unmanaged part

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Mar 11, 2023
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Mar 11, 2023
@ghost
Copy link

ghost commented Mar 11, 2023

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch, @kunalspathak
See info in area-owners.md if you want to be subscribed.

Issue Details
public struct MyStruct
{
    public long a;
    public long b;
    public long c;
    public long d;
    public long e;
    public long f;
    public long g;
    public long h;
    public long i;
    public long j;
    public long k;
    public long l;
    public long m;
    public long n;
    public long o;
    public string s;
}

public MyStruct Foo()
{
    MyStruct s = default;
    return s;
}
; Method Program:Foo():Program+MyStruct:this
       33C0                 xor      eax, eax
       488902               mov      qword ptr [rdx], rax
       48894208             mov      qword ptr [rdx+08H], rax
       48894210             mov      qword ptr [rdx+10H], rax
       48894218             mov      qword ptr [rdx+18H], rax
       48894220             mov      qword ptr [rdx+20H], rax
       48894228             mov      qword ptr [rdx+28H], rax
       48894230             mov      qword ptr [rdx+30H], rax
       48894238             mov      qword ptr [rdx+38H], rax
       48894240             mov      qword ptr [rdx+40H], rax
       48894248             mov      qword ptr [rdx+48H], rax
       48894250             mov      qword ptr [rdx+50H], rax
       48894258             mov      qword ptr [rdx+58H], rax
       48894260             mov      qword ptr [rdx+60H], rax
       48894268             mov      qword ptr [rdx+68H], rax
       48894270             mov      qword ptr [rdx+70H], rax
       48894278             mov      qword ptr [rdx+78H], rax
       488BC2               mov      rax, rdx
       C3                   ret      
; Total bytes of code: 69

JIT gives up on SIMDs because of gc pointers in a struct while it could use SIMD only for unmanaged part

Author: EgorBo
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

@EgorBo EgorBo added this to the Future milestone Mar 11, 2023
@EgorBo EgorBo removed the untriaged New issue has not been triaged by the area owner label Mar 11, 2023
@EgorBo EgorBo self-assigned this Mar 11, 2023
@EgorBo
Copy link
Member Author

EgorBo commented Mar 11, 2023

Arm64 does use SIMD in this case

; Method MyBenchmarks:Foo():MyBenchmarks+MyStruct:this
G_M35785_IG01:              ;; offset=0000H
        A9BF7BFD          stp     fp, lr, [sp, #-0x10]!
        910003FD          mov     fp, sp
        4F00E410          movi    v16.16b, #0
        AD004110          stp     q16, q16, [x8]
        AD014110          stp     q16, q16, [x8, #0x20]
        AD024110          stp     q16, q16, [x8, #0x40]
        AD034110          stp     q16, q16, [x8, #0x60]
        F900411F          str     xzr, [x8, #0x80]
        A8C17BFD          ldp     fp, lr, [sp], #0x10
        D65F03C0          ret     lr

Presumably because stp is atomic

@jakobbotsch
Copy link
Member

Is this one fixed @EgorBo?

@EgorBo
Copy link
Member Author

EgorBo commented Nov 30, 2023

Is this one fixed @EgorBo?

Nope, the codegen is the same

@EgorBo EgorBo modified the milestones: Future, 9.0.0 May 12, 2024
@dotnet-policy-service dotnet-policy-service bot added the in-pr There is an active PR which will close this issue when it is merged label May 12, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jun 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI in-pr There is an active PR which will close this issue when it is merged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants