Skip to content

JIT: Loop hoisting is overly-conservative with helper calls #6553

@JosephTremoulet

Description

@JosephTremoulet

Loop hoisting has code to avoid illegally re-ordering side-effects, which includes a check for calls that is overly-general. The check looks at the GTF_CALL flag, which (A) will be set for the entire expression containing a call as a sub-expression (which is unnecessary because this code is walking the whole tree), and (B) doesn't distinguish non-side-effecting helper calls, like we do in value-numbering and in the code just above that identifies hoistable calls. This blocks hoisting of the m_arr accesses (because of the GetStaticBase helper call that precedes them) in the following code, even with a fix for #6552 in place:

using System;
using System.Diagnostics;

class ArrayPerf
{

    private static int[] m_arr;
    private const int MAX_ARRAY_SIZE = 4096;

    private static readonly int DIM_1 = MAX_ARRAY_SIZE;

    static void Main(string[] args)
    {
        long iterations = Int64.Parse(args[0]);

        int value;
        m_arr = new int[DIM_1];

        for (int i = 0; i < DIM_1; i++)
            m_arr[i] = i;

        for (int j = 0; j < DIM_1; j++)
            value = m_arr[j];

        //var sw = Stopwatch.StartNew();

        for (long i = 0; i < iterations; i++)
        {
            for (int j = 0; j < DIM_1; j++)
            {
                value = m_arr[j];
                value = m_arr[j];
                value = m_arr[j];
                value = m_arr[j];
                value = m_arr[j];
                value = m_arr[j];
                value = m_arr[j];
                value = m_arr[j];
                value = m_arr[j];
                value = m_arr[j];
            }
        }

        //sw.Stop();
        //Console.WriteLine(sw.ElapsedMilliseconds);
    }
}

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