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: inefficient multidimensional array access vis Jit32 (and in general) #8569

Closed
AndyAyersMS opened this issue Jul 17, 2017 · 3 comments
Closed
Assignees
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI enhancement Product code improvement that does NOT require public API changes/additions JitUntriaged CLR JIT issues needing additional triage optimization tenet-performance Performance related issue
Milestone

Comments

@AndyAyersMS
Copy link
Member

RyuJit fails to optimize multidimensional array indices and misses some cases that Jit32 is able to optimize. In the following code example,

class M
{
    public static int Example(int[,] a, int b)
    {
        int r = 0;
        for (int i = 0; i < a.GetLength(1); i++)
        {
            r += a[b, i] + a[b, i];
        }
        return r;
    }

    public static int Main()
    {
        int[,] a = new int[10,10];
        a[3,3] = 3;
        a[3,7] = 7;
        int r = Example(a, 3);
        return r == 20 ? 100 : 0;
    }
}

Jit32 is able to CSE the addressing done in the a[b,i] references in Example (though it does not CSE the array fetch itself). RyuJit does not CSE anything in the loop.

Neither jit recognizes a.GetLength as being a loop invariant, or that the initial bounds check r[b, ] is likewise a loop invariant, or inline and decompose GetLength despite inlining the very similar bounds check and element addressing logic. Neither jit is able to optimize away the bounds checks in Main where the array size and indices are known.

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

@AndyAyersMS
Copy link
Member Author

See also the codegen in Bytemark/BenchNumericSortRectangular's NumSift.

@msftgits msftgits transferred this issue from dotnet/coreclr Jan 31, 2020
@msftgits msftgits added this to the Future milestone Jan 31, 2020
@BruceForstall BruceForstall added the JitUntriaged CLR JIT issues needing additional triage label Oct 28, 2020
@BruceForstall BruceForstall self-assigned this Oct 9, 2021
@BruceForstall
Copy link
Member

Related: #5481

@BruceForstall
Copy link
Member

This is addressed in #70271. There are follow-up items there to continue to improve MD array performance.

@ghost ghost locked as resolved and limited conversation to collaborators Aug 5, 2022
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 enhancement Product code improvement that does NOT require public API changes/additions JitUntriaged CLR JIT issues needing additional triage optimization tenet-performance Performance related issue
Projects
None yet
Development

No branches or pull requests

3 participants