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

JIT: Cloned loop not fully strength reduced on arm64 #109412

Closed
jakobbotsch opened this issue Oct 31, 2024 · 2 comments · Fixed by #106637
Closed

JIT: Cloned loop not fully strength reduced on arm64 #109412

jakobbotsch opened this issue Oct 31, 2024 · 2 comments · Fixed by #106637
Assignees
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI in-pr There is an active PR which will close this issue when it is merged
Milestone

Comments

@jakobbotsch
Copy link
Member

With the example taken from #109379:

AggregateDelegate(Enumerable.Range(0, 100_000).ToArray(), (acc, v) => acc + v, 0);

[MethodImpl(MethodImplOptions.NoInlining)]
public static T AggregateDelegate<T>(T[] ar, Func<T, T, T> func, T seed)
{
    for (int i = 0; i < ar.Length; i++)
    {
        seed = func(seed, ar[i]);
    }
    return seed;
}

Once the fix in #109407 is applied, we end up with the following x64 codegen for the inner loop in the good case:

G_M53109_IG04:  ;; offset=0x002A
       mov      eax, dword ptr [rcx]
       add      r8d, eax
       add      rcx, 4
       dec      edx
       jne      SHORT G_M53109_IG04

which looks great. However, for arm64, we end up with the following codegen:

G_M53109_IG03:  ;; offset=0x0024
            cbz     x19, G_M53109_IG07
            ldr     x3, [x19, #0x18]
            movz    x20, #0x828      // code for C+<>c:<Main>b__0_0(int,int):int:this
            movk    x20, #540 LSL #16
            movk    x20, #0x7FFA LSL #32
            cmp     x3, x20
            bne     G_M53109_IG07
            add     x21, x0, #16
            mov     x0, xzr
            align   [0 bytes for IG04]
                                                ;; size=36 bbWeight=0.99 PerfScore 7.95
G_M53109_IG04:  ;; offset=0x0048
            ldr     w3, [x21, x0]
            add     x0, x0, #4
            add     w2, w2, w3
            sub     w1, w1, #1
            cbnz    w1, G_M53109_IG04

where we were unable to fully strength reduce. The problem is a multi-def CSE that was not put in SSA, which makes IV opts unable to reason about it.

@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 Oct 31, 2024
@jakobbotsch jakobbotsch self-assigned this Oct 31, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Oct 31, 2024
@jakobbotsch jakobbotsch added this to the 10.0.0 milestone Oct 31, 2024
@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label Oct 31, 2024
Copy link
Contributor

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

@jakobbotsch
Copy link
Member Author

jakobbotsch commented Oct 31, 2024

With #106637 the codegen becomes

G_M53109_IG03:  ;; offset=0x0020
            cbz     x19, G_M53109_IG07
            ldr     x3, [x19, #0x18]
            movz    x20, #0x828      // code for C+<>c:<Main>b__0_0(int,int):int:this
            movk    x20, #542 LSL #16
            movk    x20, #0x7FFA LSL #32
            cmp     x3, x20
            bne     G_M53109_IG07
            add     x3, x0, #16
            align   [0 bytes for IG04]
                                                ;; size=32 bbWeight=0.99 PerfScore 7.46
G_M53109_IG04:  ;; offset=0x0040
            ldr     w4, [x3], #0x04
            add     w2, w2, w4
            sub     w1, w1, #1
            cbnz    w1, G_M53109_IG04

@dotnet-policy-service dotnet-policy-service bot added the in-pr There is an active PR which will close this issue when it is merged label Oct 31, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Dec 8, 2024
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 in-pr There is an active PR which will close this issue when it is merged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant