Skip to content

JIT: IV widening does not kick in for a simple loop with array and string indexing #102068

Closed
@jakobbotsch

Description

Example from @richlander:

public static void Foo()
{
    string puzzle = "003020600900305001001806400008102900700000008006708200002609500800203009005010300";
    int[] board = new int[81];

    for (int i = 0; i < puzzle.Length; i++)
    {
        board[i] = puzzle[i] - '0';
    }
}

Loop codegen:

       xor      ecx, ecx
       align    [0 bytes for IG03]
						;; size=22 bbWeight=1 PerfScore 1.75
G_M24659_IG03:  ;; offset=0x001A
       mov      edx, ecx
       mov      r8, 0x160D4E52C30      ; '003020600900305001001806400008102900700000008006708200002609500'
       movzx    r8, word  ptr [r8+2*rdx+0x0C]
       add      r8d, -48
       mov      dword ptr [rax+4*rdx+0x10], r8d
       inc      ecx
       cmp      ecx, 81
       jl       SHORT G_M24659_IG03
						;; size=34 bbWeight=3.96 PerfScore 20.79

Expected:

       xor      ecx, ecx
       align    [0 bytes for IG03]
						;; size=22 bbWeight=1 PerfScore 1.75
G_M24659_IG03:  ;; offset=0x001A
       mov      r8, 0x160D4E52C30      ; '003020600900305001001806400008102900700000008006708200002609500'
       movzx    r8, word  ptr [r8+2*rcx+0x0C]
       add      r8d, -48
       mov      dword ptr [rax+4*rcx+0x10], r8d
       inc      ecx
       cmp      ecx, 81
       jl       SHORT G_M24659_IG03
						;; size=34 bbWeight=3.96 PerfScore 20.79

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

Relationships

None yet

Development

No branches or pull requests

Issue actions