Skip to content

JIT: Value-numbering is over-conservative for image_rel32 statics #6552

@JosephTremoulet

Description

@JosephTremoulet

When fgMorphField processes a static field for which eeGetRelocTypeHint returns IMAGE_REL_BASED_REL32, it creates an GT_IND over an IntCon rather than a GT_CLSVAR. Value numbering has processing to disambiguate static fields represented as ClsVars, but not the others, despite the others being annotated with the symbolic field information.

Here's some code that shows the issue; there are logs of redundant m_arr accesses that don't get CSE'd because of this. Note that they get CSE'd with crossgen, where eeGetRelocTypeHint doesn't return IMAGE_REL_BASED_REL32, just not with CoreRun.

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);
    }
}

dotnet/coreclr#6889 is already in flight to address this, just filing this issue for tracking and to be able to reference it for further issues optimizing the same code.

category:cq
theme:value-numbering
skill-level:expert
cost:small

Metadata

Metadata

Assignees

No one assigned

    Labels

    JitUntriagedCLR JIT issues needing additional triagearea-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIenhancementProduct code improvement that does NOT require public API changes/additionsoptimizationtenet-performancePerformance related issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions