Skip to content

Loops aren't cloned for Spans #82946

@EgorBo

Description

@EgorBo
void Test(Span<byte> source)
{
    for (int i = 0; i < 100; i++)
        source[i] = 0;
}

Codegen:

; Method Progr:Test(System.Span`1[ubyte]):this
G_M11420_IG01:              
       4883EC28             sub      rsp, 40
G_M11420_IG02:              
       33C0                 xor      eax, eax
                            align    [0 bytes for IG03]
G_M11420_IG03:              
       3B4208               cmp      eax, dword ptr [rdx+08H]
       7317                 jae      SHORT G_M11420_IG05
       488B0A               mov      rcx, bword ptr [rdx]
       448BC0               mov      r8d, eax
       42C6040100           mov      byte  ptr [rcx+r8], 0
       FFC0                 inc      eax
       83F864               cmp      eax, 100
       7CE9                 jl       SHORT G_M11420_IG03
G_M11420_IG04:              
       4883C428             add      rsp, 40
       C3                   ret      
G_M11420_IG05:              
       E829C64C5F           call     CORINFO_HELP_RNGCHKFAIL
       CC                   int3     
; Total bytes of code: 40
*************** Starting PHASE Clone loops

*************** In optCloneLoops()
Considering loop L00 to clone for optimizations.
Not checking loop L00 -- no array bounds or type tests in this method
------------------------------------------------------------

  No clonable loops

*************** Finishing PHASE Clone loops

Here it is expected to have two loops and one of them without bound checks.

cc @BruceForstall @dotnet/jit-contrib

category:cq
theme:loop-opt
skill-level:expert
cost:medium
impact:large

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIin-prThere is an active PR which will close this issue when it is merged

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions