Skip to content

LoopCloneContext::EvaluateConditions need to evaluate for const init, limit condition.  #10314

@ArtBlnd

Description

@ArtBlnd

current EvaluateConditions should evaluate const-init, const-limit for not cloning very natural loops
this is actually statically known as true. (always taken)

this makes loop to clone(evaluate as not statically known as true or false), which causes not to unroll general natural loops (flagged as LPFLG_DONT_UNROLL)

int[] arr = { 1, 2, 3, 4 };
int total = 0;

for(int i = 0; i < 4; ++i)
{
    total += arr[i];
}

actually, this loop dosn't really needs to be cloned. (or maybe needs implements for evaluate loop taken count?)
reason why evaluate conditions needs to evaluate const-init, const-limit because if this code unrolled, the for expressions is be always taken. so its statically taken.

here is example

int[] arr = { 1, 2, 3, 4 };
int total = 0;

do {
    total += arr[0];
    total += arr[1];
    total += arr[2];
    total += arr[3];
} while(false);

but after loop-cloning will not to perform unroll-loop.
this is like ironic, like a deadlock.

Perform optUnrollLoops after optCloneLoops
https://github.com/dotnet/coreclr/blob/e5299e87b6eda43acb12a3cb341b71e8a3121960/src/jit/compiler.cpp#L4802-L4812

I think transforming for or foreach expressions into do~while need to be separated method from optCloneLoops , which that doesn't really need to be cloned.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions