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

Consider hoisting of class init checks for loop cloning and inversion #49102

Open
BruceForstall opened this issue Mar 4, 2021 · 2 comments
Open
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 Mar 4, 2021

Cloning to allow for a loop with a class init check, and one where the class init check is removed, could be profitable.

AndyAyersMS writes:

I wonder if we should consider using this check as a gating condition for loop cloning... Also may factor into the do-while transformation heuristics, these try to account for the potential "savings" from hoisting the class init call check out of the loop.

So for some subset of loops we would produce a loop that knows classes are inited and does no checks, and another that will conditionally check within the loop body as above.

Related: #47901

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

@BruceForstall BruceForstall added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Mar 4, 2021
@BruceForstall BruceForstall added this to the 6.0.0 milestone Mar 4, 2021
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Mar 4, 2021
@EgorBo
Copy link
Member

EgorBo commented Mar 4, 2021

What is going to happen for, let's say:

class MyStaticCctor
{
    public static readonly int s_Field = 0;

    static MyStaticCctor()
    {
        s_Field = 42;
    }
}

class Tests
{
    void TestMethod(int[] array)
    {
        for (int i = 0; i < 1000; i++)
            array[i] = MyStaticCctor.s_Field;
    }
}

Here we already are going to clone the loop for Length>=1000 check. Will it look like this then?:

if (array.Length>=1000 && MyStaticCctor.IsInited)
    fast-loop
else
    slow-loop

@BruceForstall
Copy link
Member Author

Yeah, that's the idea, where slow-loop is required to have an in-loop init check, and fast-loop can remove it. It wouldn't be valuable if the init check can already be hoisted.

@JulieLeeMSFT JulieLeeMSFT removed the untriaged New issue has not been triaged by the area owner label Mar 8, 2021
@BruceForstall BruceForstall modified the milestones: 6.0.0, 7.0.0 Jul 6, 2021
@BruceForstall BruceForstall modified the milestones: 7.0.0, 8.0.0 May 26, 2022
@BruceForstall BruceForstall modified the milestones: 8.0.0, 9.0.0 Jul 7, 2023
@JulieLeeMSFT JulieLeeMSFT moved this to Optimizations in .NET Core CodeGen Jun 5, 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
Status: Optimizations
Development

No branches or pull requests

3 participants