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] Suboptimal expansion of __builtin_bswap16 #77222

Open
Kmeakin opened this issue Jan 7, 2024 · 5 comments
Open

[AArch64] Suboptimal expansion of __builtin_bswap16 #77222

Kmeakin opened this issue Jan 7, 2024 · 5 comments

Comments

@Kmeakin
Copy link
Contributor

Kmeakin commented Jan 7, 2024

https://godbolt.org/z/jcxb4n97o

uint16_t rev16(uint16_t x) { return __builtin_bswap16(x); }

expands to

rev16:
        rev     w8, w0
        lsr     w0, w8, #16
        ret

instead of

rev16:
        rev16   w0, w0
        ret

__builtin_bswap32 and __builtin_bswap64 don't have the same issue

@llvmbot
Copy link
Member

llvmbot commented Jan 7, 2024

@llvm/issue-subscribers-backend-aarch64

Author: Karl Meakin (Kmeakin)

https://godbolt.org/z/jcxb4n97o
uint16_t rev16(uint16_t x) { return __builtin_bswap16(x); }

expands to

rev16:
        rev     w8, w0
        lsr     w0, w8, #<!-- -->16
        ret

instead of

rev16:
        rev16   w0, w0
        ret

__builtin_bswap32 and __builtin_bswap64 don't have the same issue

@anematode
Copy link
Contributor

Latest clang seems to emit rev16 here. Maybe fixed by #80036 ?

@Kmeakin
Copy link
Contributor Author

Kmeakin commented Feb 29, 2024

Latest clang seems to emit rev16 here. Maybe fixed by #80036 ?

It is still suboptimal on Compiler Explorer

@landfillbaby
Copy link

landfillbaby commented Jun 24, 2024

this also applies to the __revsh and __rev16 ACLE intrinsics! they should generate the instruction they represent!

adprasad-nvidia added a commit to adprasad-nvidia/llvm-project that referenced this issue Sep 3, 2024
@adprasad-nvidia
Copy link
Contributor

I've been working on a patch for this at #105375 .

adprasad-nvidia added a commit to adprasad-nvidia/llvm-project that referenced this issue Sep 5, 2024
adprasad-nvidia added a commit to adprasad-nvidia/llvm-project that referenced this issue Sep 6, 2024
adprasad-nvidia added a commit to adprasad-nvidia/llvm-project that referenced this issue 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

5 participants