Skip to content

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

Description

@BruceForstall

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

Activity

  1. added
    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
    on Mar 4, 2021
  2. added this to the 6.0.0 milestone on Mar 4, 2021
  3. ghost added
    untriagedNew issue has not been triaged by the area owner
    on Mar 4, 2021
  4. EgorBo commented on Mar 4, 2021

    @EgorBo
    Member

    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
    
  5. BruceForstall commented on Mar 4, 2021

    @BruceForstall
    ContributorAuthor

    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.

  6. removed
    untriagedNew issue has not been triaged by the area owner
    on Mar 8, 2021
  7. modified the milestones: 6.0.0, 7.0.0 on Jul 6, 2021
  8. modified the milestones: 7.0.0, 8.0.0 on May 26, 2022
  9. modified the milestones: 8.0.0, 9.0.0 on Jul 7, 2023
  10. moved this to Optimizations in .NET Core CodeGenon Jun 5, 2024
  11. modified the milestones: 9.0.0, 10.0.0 on Jul 25, 2024
  12. modified the milestones: 10.0.0, Future on Apr 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions