KEMBAR78
JIT: Slow spills to stack in a loop on Linux vs Windows · Issue #58522 · dotnet/runtime · GitHub
Skip to content

JIT: Slow spills to stack in a loop on Linux vs Windows #58522

@EgorBo

Description

@EgorBo

The following program (reported by @WhiteBlackGoose):

public class Program
{
    struct RangeEnumerator
    {
        private readonly int to;
        private readonly int step;
        private int curr;

        public bool MoveNext()
        {
            curr += step;
            return curr != to;
        }

        public int Current => curr;
    }

    static int EnumerateItAll(RangeEnumerator enumerator)
    {
        var a = 0;
        while (enumerator.MoveNext())
            a += enumerator.Current;
        return a;
    }
}

here is the assembly diff for EnumerateItAll method between Win-x64 and Linux-x64: https://www.diffchecker.com/NorefcMS
Windows one looks much better and there are no spills in the Loop body leading to much better performance.
I've not investigated this one yet - from my understanding RangeEnumerator is passed by stack on win-x64 ABI and via registers on lin-x64. Is there anything we can do here for Linux or it's a dup for some "first class structs promotion" issue? cc @dotnet/jit-contrib @kunalspathak

category:cq
theme:stack-allocation

Metadata

Metadata

Assignees

Labels

Priority:2Work that is important, but not critical for the releasearea-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMItenet-performancePerformance related issue

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions