Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ARM64 Redundant load/stores for methods that operates/returns structs #35071

@kunalspathak

Description

@kunalspathak

Part of library code SqlDouble where we are generating code that does redundant stores and loads of x0, x1, x2 and x3 and can be removed for arm64. I tried trimming the repro, but it was not getting the generated code that it would do for the actual scenario. So here is the repro code:

public struct MyType
{
    private double m_value;
    private bool IsNull;

    public MyType(double _value)
    {
        m_value = _value;
        IsNull = false;
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    public static SqlBoolean Check(MyType data1, MyType data2)
    {
        return data1 <= data2;
    }

    public static SqlBoolean operator <=(MyType x, MyType y)
    {
        return (x.IsNull || y.IsNull) ? SqlBoolean.Null : new SqlBoolean(x.m_value <= y.m_value);
    }

    public static SqlBoolean operator >=(MyType x, MyType y)
    {
        return (x.IsNull || y.IsNull) ? SqlBoolean.Null : new SqlBoolean(x.m_value >= y.m_value);
    }
}

public struct SqlBoolean
{
    private bool value;
    public SqlBoolean(bool _value)
    {
        value = _value;
    }
    public static SqlBoolean Null = new SqlBoolean();
}

MyType.Check(new MyType(1.1), new MyType(1.5));

On ARM64, it generates:

G_M35994_IG01:
        A9BD7BFD          stp     fp, lr, [sp,#-48]!
        910003FD          mov     fp, sp
        F90013A0          str     x0, [fp,#32]
        F90017A1          str     x1, [fp,#40]
        F9000BA2          str     x2, [fp,#16]
        F9000FA3          str     x3, [fp,#24]
                                                ;; bbWeight=1    PerfScore 5.50
G_M35994_IG02:
        F94013A0          ldr     x0, [fp,#32]
        F94017A1          ldr     x1, [fp,#40]
        F9400BA2          ldr     x2, [fp,#16]
        F9400FA3          ldr     x3, [fp,#24]
        97FFFFB0          bl      projs.MyType:op_LessThanOrEqual(projs.MyType,projs.MyType):projs.SqlBoolean
                                                ;; bbWeight=1    PerfScore 9.00
G_M35994_IG03:
        A8C37BFD          ldp     fp, lr, [sp],#48
        D65F03C0          ret     lr

category:cq
theme:optimization
skill-level:intermediate
cost:medium

Metadata

Metadata

Assignees

Labels

arch-arm64area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions