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

[Aarch64] lsr v, v, #56+ldr d0, [x9, x8, lsl #3] optimized to lsr v, v, #53+and v, v, #0x7f8+ldr d0, [x9, x8] #107526

Closed
Validark opened this issue Sep 6, 2024 · 3 comments

Comments

@Validark
Copy link

Validark commented Sep 6, 2024

Godbolt link

export fn foo(bitstring: u64, dest: [*]u8, src: [*][8]u8) void {
    dest[0..8].* = src[bitstring >> 56];
}

Compiled for the Apple M3:

foo:
        lsr     x8, x0, #53
        and     x8, x8, #0x7f8
        ldr     x8, [x2, x8]
        str     x8, [x1]
        ret

I think it should be:

foo:
        lsr     x8, x0, #56
        ldr     x8, [x2, x8, lsl #3]
        str     x8, [x1]
        ret
@Validark Validark changed the title lsr v, v, #56+ldr d0, [x9, x8, lsl #3] optimized to lsr v, v, #53+and v, v, #0x7f8+ldr d0, [x9, x8] [Aarch64] lsr v, v, #56+ldr d0, [x9, x8, lsl #3] optimized to lsr v, v, #53+and v, v, #0x7f8+ldr d0, [x9, x8] Sep 6, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Sep 6, 2024

@llvm/issue-subscribers-backend-aarch64

Author: Niles Salter (Validark)

[Godbolt link](https://zig.godbolt.org/z/sbefWdEcf)
export fn foo(bitstring: u64, dest: [*]u8, src: [*][8]u8) void {
    dest[0..8].* = src[bitstring >> 56];
}

Compiled for the Apple M3:

foo:
        lsr     x8, x0, #<!-- -->53
        and     x8, x8, #<!-- -->0x7f8
        ldr     x8, [x2, x8]
        str     x8, [x1]
        ret

I think it should be:

foo:
        lsr     x8, x0, #<!-- -->56
        ldr     x8, [x2, x8, lsl #<!-- -->3]
        str     x8, [x1]
        ret

@davemgreen
Copy link
Collaborator

I believe this might have been fixed by #89531.
https://godbolt.org/z/sxT1dsxed

@Validark
Copy link
Author

Validark commented Sep 6, 2024

Looks like it was! Job well done!

@Validark Validark closed this as completed Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants