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

Arm64: Better addressing mode for array access whose elements are accessed byref #67981

Closed
kunalspathak opened this issue Apr 13, 2022 · 6 comments
Assignees
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Milestone

Comments

@kunalspathak
Copy link
Member

kunalspathak commented Apr 13, 2022

Continuing on #64819, we should also improve the array accesses if the element is accessed using ref.

private int[] _srcData = new int[20];

public int[] Test(int m, int n, byte v)
{
    for (int i = 0; i < n; i++) {
        Consume(ref _srcData[i]);
    }
    return _srcData;
}
G_M11249_IG03:
            mov     x0, x19
            ldr     x0, [x0,#8]
            ldr     w1, [x0,#8]
            cmp     w21, w1
            bhs     G_M11249_IG06
            add     x0, x0, #16
            ubfiz   x1, x21, #2, #32   
            add     x1, x0, x1           ; <-- can compact with previous instruction?
            mov     x0, x19
            movz    x2, #0xd1ffab1e
            movk    x2, #0xd1ffab1e LSL #16
            movk    x2, #0xd1ffab1e LSL #32
            ldr     x2, [x2]
            blr     x2
            add     w21, w21, #1
            cmp     w21, w20
            blt     G_M11249_IG03

Without ref:

private int[] _srcData = new int[20];

public int[] Test(int m, int n, byte v)
{
    for (int i = 0; i < n; i++) {
        Consume(_srcData[i]);
    }
    return _srcData;
}
G_M11249_IG03:
            mov     x0, x19
            ldr     x0, [x0,#8]
            ldr     w1, [x0,#8]
            cmp     w21, w1
            bhs     G_M11249_IG06
            add     x0, x0, #16
            ldr     w1, [x0, w21, UXTW #2] ; <-- compacted
            mov     x0, x19
            movz    x2, #0xd1ffab1e
            movk    x2, #0xd1ffab1e LSL #16
            movk    x2, #0xd1ffab1e LSL #32
            ldr     x2, [x2]
            blr     x2
            add     w21, w21, #1
            cmp     w21, w20
            blt     G_M11249_IG03
@dotnet-issue-labeler dotnet-issue-labeler bot added area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI untriaged New issue has not been triaged by the area owner labels Apr 13, 2022
@ghost
Copy link

ghost commented Apr 13, 2022

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

Issue Details

Continuing on #64819, we should also improve the array accesses if the element is accessed using ref.

private int[] _srcData = new int[20];

public int[] Test(int m, int n, byte v)
{
    for (int i = 0; i < n; i++) {
        Consume(ref _srcData[i]);
    }
    return _srcData;
}
G_M11249_IG03:
            mov     x0, x19
            ldr     x0, [x0,#8]
            ldr     w1, [x0,#8]
            cmp     w21, w1
            bhs     G_M11249_IG06
            add     x0, x0, #16
            ubfiz   x1, x21, #2, #32
            add     x1, x0, x1
            mov     x0, x19
            movz    x2, #0xd1ffab1e
            movk    x2, #0xd1ffab1e LSL #16
            movk    x2, #0xd1ffab1e LSL #32
            ldr     x2, [x2]
            blr     x2
            add     w21, w21, #1
            cmp     w21, w20
            blt     G_M11249_IG03

Without ref:

private int[] _srcData = new int[20];

public int[] Test(int m, int n, byte v)
{
    for (int i = 0; i < n; i++) {
        Consume(ref _srcData[i]);
    }
    return _srcData;
}
G_M11249_IG03:
            mov     x0, x19
            ldr     x0, [x0,#8]
            ldr     w1, [x0,#8]
            cmp     w21, w1
            bhs     G_M11249_IG06
            add     x0, x0, #16
            ldr     w1, [x0, w21, UXTW #2] ; <-- compact
            mov     x0, x19
            movz    x2, #0xd1ffab1e
            movk    x2, #0xd1ffab1e LSL #16
            movk    x2, #0xd1ffab1e LSL #32
            ldr     x2, [x2]
            blr     x2
            add     w21, w21, #1
            cmp     w21, w20
            blt     G_M11249_IG03
Author: kunalspathak
Assignees: -
Labels:

area-CodeGen-coreclr, untriaged

Milestone: -

@kunalspathak
Copy link
Member Author

@dotnet/jit-contrib

@EgorBo
Copy link
Member

EgorBo commented Jun 15, 2022

I don't understand the expected codegen - the first codegen doesn't contain any memory loads (because we don't dereference _srcData)

@kunalspathak
Copy link
Member Author

I don't understand the expected codegen - the first codegen doesn't contain any memory loads (because we don't dereference _srcData)

Ah, I think the 2nd version had to be Consume(_srcData[i]);. In the first codegen, I was referring to the following (if that's what you are asking):

            ubfiz   x1, x21, #2, #32
            add     x1, x0, x1

@EgorBo
Copy link
Member

EgorBo commented Jul 19, 2022

@kunalspathak so can you tell what's the expected codegen here? I don't see loads and I don't see how we can combine these ubfix and add

@EgorBo EgorBo modified the milestones: 7.0.0, 8.0.0 Jul 31, 2022
@kunalspathak
Copy link
Member Author

I was misreading that the ref example has memory load in ldr x2, [x1], but it doesn't need it.

@ghost ghost locked as resolved and limited conversation to collaborators Nov 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

No branches or pull requests

3 participants