Skip to content

JIT: Unnecessary bounds checks for MD array accesses #103321

@jakobbotsch

Description

@jakobbotsch

For code like:

void Foo(int[,] foo)
{
    for (int i = foo.GetLowerBound(0); i < foo.GetUpperBound(0); i++)
    {
        int count = i * 100;

        for (int j = foo.GetLowerBound(1); j < foo.GetUpperBound(1); j++)
        {
            foo[i, j] = count++;
        }
    }
}

we generate unnecessary bounds checks on the accesses within the loop. This pattern is also what Roslyn produces for foreach over MD arrays, so we should be able to optimize it better.

Reported by @richlander

category:cq
theme:md-arrays
skill-level:expert
cost:large

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions