Skip to content

Invalid hoisting of indirections proven to be loop invariant #54118

@jakobbotsch

Description

@jakobbotsch
// Generated by Fuzzlyn v1.2 on 2021-06-13 00:28:44
// Seed: 3271777432388482561
// Reduced from 81.8 KiB to 0.3 KiB in 00:01:03
// Debug: Outputs 1
// Release: Outputs 0
public class Program
{
    public static void Main()
    {
        uint[] vr1 = new uint[] { 0 };
        for (int vr2 = 0; vr2 < 2; vr2++)
        {
            vr1[0] = 1;
            var vr3 = vr1[0];
            System.Console.WriteLine(vr3);
        }
    }
}

We hoist vr1[0] out of the loop because it's constant. Seems to be a variant of #13328 which was fixed for static fields in dotnet/coreclr#26952.

Another variant:

// Generated by Fuzzlyn v1.2 on 2021-06-13 01:10:47
// Seed: 15404436673887137956
// Reduced from 66.4 KiB to 0.3 KiB in 00:00:53
// Debug: Outputs 1
// Release: Outputs 0
public class Program
{
    static uint[] s_16 = new uint[]{0};
    public static void Main()
    {
        ref uint vr0 = ref s_16[0];
        for (int vr1 = 0; vr1 < 2; vr1++)
        {
            vr0 = 1;
            vr0 = vr0;
        }

        System.Console.WriteLine(s_16[0]);
    }
}

cc @dotnet/jit-contrib

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions