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

Support loop cloning of class member arrays #77071

Open
BruceForstall opened this issue Oct 15, 2022 · 2 comments
Open

Support loop cloning of class member arrays #77071

BruceForstall opened this issue Oct 15, 2022 · 2 comments
Assignees
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Milestone

Comments

@BruceForstall
Copy link
Member

BruceForstall commented Oct 15, 2022

Currently, if the array being iterated is a class member (and not a function local), we can't analyze the access (e.g., can't determine if the array object is loop-invariant).

e.g.,

public class Program
{
    int[] array = new int[1000003];

    public int Sum()
    {
        int sum = 0;
        for (int i = 0; i < array.Length; i++)
            sum += array[i];
        return sum;
    }
}

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

@BruceForstall BruceForstall added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Oct 15, 2022
@BruceForstall BruceForstall added this to the 8.0.0 milestone Oct 15, 2022
@ghost
Copy link

ghost commented Oct 15, 2022

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

Issue Details

Currently, if the array being iterated is a class member (and not a function local), we can't analyze the access (e.g., can't determine if the array object is loop-invariant).

e.g.,

public class Program
{
    int[] array = new int[1000003];

    public int Sum()
    {
        int sum = 0;
        for (int i = 0; i < array.Length; i++)
            sum += array[i];
        return sum;
    }
}
Author: BruceForstall
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: 8.0.0

@ChrML
Copy link

ChrML commented Apr 16, 2024

Just a question out of curiousity: I guess you can't guarantee that someone else doesn't change the array reference while looping.

What would be the criterias for assuming that the code up to the element-access is "short" enough / that it's safe to fetch the instance once, check and then access it without bound-checks?

@JulieLeeMSFT JulieLeeMSFT added the Priority:2 Work that is important, but not critical for the release label May 7, 2024
@JulieLeeMSFT JulieLeeMSFT removed the Priority:2 Work that is important, but not critical for the release label Jun 13, 2024
@JulieLeeMSFT JulieLeeMSFT modified the milestones: 9.0.0, 10.0.0 Jul 25, 2024
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

No branches or pull requests

3 participants