Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Experiment] Inline "is on heap?" checks for checked write barriers #111561

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

EgorBo
Copy link
Member

@EgorBo EgorBo commented Jan 18, 2025

Let's see if it works out

void Test(ref object dst, object src) => dst = src;

Current codegen:

; Method Benchmark:Test(byref,System.Object):this (FullOpts)
G_M9668_IG01:
            stp     fp, lr, [sp, #-0x10]!
            mov     fp, sp
G_M9668_IG02:
            mov     x14, x1
            mov     x15, x2
            bl      CORINFO_HELP_CHECKED_ASSIGN_REF
G_M9668_IG03:
            ldp     fp, lr, [sp], #0x10
            ret     lr
; Total bytes of code: 28

New codegen:

; Method Benchmark:Test(byref,System.Object):this (FullOpts)
G_M9668_IG01:
            stp     fp, lr, [sp, #-0x10]!
            mov     fp, sp
G_M9668_IG02:
            movz    x14, #0x5788
            movk    x14, #0xD979 LSL #16
            movk    x14, #0x7FFA LSL #32
            ldp     x15, x14, [x14]
            cmp     x1, x15
            ccmp    x1, x14, z, ge
            blt     G_M9668_IG05
G_M9668_IG03:
            str     x2, [x1]
G_M9668_IG04:
            ldp     fp, lr, [sp], #0x10
            ret     lr
G_M9668_IG05:
            mov     x14, x1
            mov     x15, x2
            bl      CORINFO_HELP_ASSIGN_REF
            b       G_M9668_IG04
; Total bytes of code: 64

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jan 18, 2025
Copy link
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

@EgorBo

This comment was marked as outdated.

@EgorBo

This comment was marked as outdated.

@EgorBo

This comment was marked as resolved.

@EgorBo
Copy link
Member Author

EgorBo commented Jan 18, 2025

@EgorBot -arm -profiler

using System.Runtime.CompilerServices;
using BenchmarkDotNet.Attributes;

public class Benchmark
{
    [Benchmark]
    public void ReturnBufferWB() => _ = Test1(default, null);

    [Benchmark]
    public void ReturnBufferWB_batch() => _ = Test2(default);

    [Benchmark]
    public void CheckedWB()
    {
        object o = null;
        Test3(ref o, null);
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    static MyStruct Test1(MyStruct ms, object o)
    {
        ms.Fld2 = o;
        return ms;
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    static MyLargeStruct Test2(MyLargeStruct ms) => ms;

    [MethodImpl(MethodImplOptions.NoInlining)]
    static void Test3(ref object dst, object src) => dst = src;
}

public struct MyStruct
{
    public object Fld1;
    public object Fld2;
    public object Fld3;
}
public struct MyLargeStruct
{
    public object Fld1;
    public object Fld2;
    public object Fld3;
    public object Fld4;
    public object Fld5;
    public object Fld6;
    public object Fld7;
    public object Fld8;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant