Skip to content

PGO: Static profile affects loop alignment where it's not supposed to do #71649

Description

@EgorBo

Extracted from dotnet/performance:

    private static uint[] input_uint = Enumerable.Range(0, 1000).Select(i => (uint)i).ToArray();

    [MethodImpl(MethodImplOptions.NoInlining)]
    public int TrailingZeroCount_uint()
    {
        int sum = 0;
        uint[] input = input_uint;
        for (int i = 0; i < input.Length; i++)
            sum += BitOperations.TrailingZeroCount(input[i]);
        return sum;
    }

Codegen diff: https://www.diffchecker.com/dIVV1Iwy
Left: ReadyToRun=1, Right: ReadyToRun=0

My theory that when we collect the profile for TrailingZeroCount we don't have BMI on that machine so it messes weights up which then inmported into this loop and mark it as non-profitable to align.

mibc dump:

"Method": "[S.P.CoreLib]System.Numerics.BitOperations.TrailingZeroCount(uint32)",
"InstrumentationData": [
  {
    "ILOffset": 0,
    "InstrumentationKind": "NumRuns",
    "Other": 7
  },
  {
    "ILOffset": 7,
    "InstrumentationKind": "EdgeIntCount",
    "Other": 0,
    "Data": 162837
  },
  {
    "ILOffset": 20,
    "InstrumentationKind": "EdgeIntCount",
    "Other": 0,
    "Data": 0
  },
  {
    "ILOffset": 30,
    "InstrumentationKind": "EdgeIntCount",
    "Other": 0,
    "Data": 0
  },
  {
    "ILOffset": 37,
    "InstrumentationKind": "EdgeIntCount",
    "Other": 0,
    "Data": 0
  }
]

Hm.. however, looks like MIBC is correct for BitOperations.TrailingZeroCount, "ILOffset": 7 stands for

call         unsigned int32 System.Runtime.Intrinsics.X86.Bmi1::TrailingZeroCount(unsigned int32)

Metadata

Metadata

Assignees

Labels

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

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions