Open BruceForstall opened 3 years ago
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
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.
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:
Related: https://github.com/dotnet/runtime/pull/47901
category:cq theme:loop-opt skill-level:expert cost:medium impact:medium