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

JIT: unroll more memset patterns #110893

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

EgorBo
Copy link
Member

@EgorBo EgorBo commented Dec 22, 2024

Currently, JIT always gives up on unrolling Memset(Fill) for anything other than byte or zero. This PR enables it for all non-zero primitives.

void Test(Span<char> span) => span.Slice(0, 10).Fill('x');

Current codegen:

; Method Program:Test(System.Span`1[ushort]):this (FullOpts)
G_M11560_IG01:
       sub      rsp, 40
G_M11560_IG02:
       cmp      dword ptr [rdx+0x08], 10
       jl       SHORT G_M11560_IG04
       mov      rcx, bword ptr [rdx]
       mov      edx, 10
       mov      r8d, 120
       call     [System.SpanHelpers:Fill[ushort](byref,ulong,ushort)]
       nop      
G_M11560_IG03:
       add      rsp, 40
       ret      
G_M11560_IG04:
       call     [System.ThrowHelper:ThrowArgumentOutOfRangeException()]
       int3     
; Total bytes of code: 43

New codegen:

; Method Program:Test(System.Span`1[ushort]):this (FullOpts)
G_M11560_IG01:
       sub      rsp, 40
G_M11560_IG02:
       cmp      dword ptr [rdx+0x08], 10
       jl       SHORT G_M11560_IG04
       mov      rax, bword ptr [rdx]
       vmovups  xmm0, xmmword ptr [reloc @RWD00]
       vmovups  xmmword ptr [rax], xmm0
       mov      dword ptr [rax+0x10], 0x780078
G_M11560_IG03:
       add      rsp, 40
       ret      
G_M11560_IG04:
       call     [System.ThrowHelper:ThrowArgumentOutOfRangeException()]
       int3     
RWD00  	dq	0078007800780078h, 0078007800780078h
; Total bytes of code: 44

@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 Dec 22, 2024
Copy link
Contributor

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

@EgorBo EgorBo marked this pull request as ready for review December 23, 2024 02:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant