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

[x86] Opportunity to use shorter encoding for comparisons against powers of two #122383

Open
Kmeakin opened this issue Jan 9, 2025 · 1 comment

Comments

@Kmeakin
Copy link
Contributor

Kmeakin commented Jan 9, 2025

https://godbolt.org/z/hhbsf8she

For the expression (x >> amt) != 0, for values of amt between 8 and 31, LLVM emits a cmp against an immediate instead of a shift right and comparison. The compare against immediate instruction takes 7 bytes to encode; the shift right instruction takes 4 bytes

src:
        cmp    rdi,0x7fffffff ; 48 81 ff ff ff ff 7f
        setae   al            ; 0f 97 c0
        ret                   ; c3

tgt:
        shr     rdi, 0x1f  ; 48 c1 ef 1f
        setne   al         ; 0f 95 c0
        ret                ; c3
@llvmbot
Copy link
Member

llvmbot commented Jan 9, 2025

@llvm/issue-subscribers-backend-x86

Author: Karl Meakin (Kmeakin)

https://godbolt.org/z/hhbsf8she

For the expression (x >> amt) != 0, for values of amt between 8 and 31, LLVM emits a cmp against an immediate instead of a shift right and comparison. The compare against immediate instruction takes 7 bytes to encode; the shift right instruction takes 4 bytes

src:
        cmp    rdi,0x7fffffff ; 48 81 ff ff ff ff 7f
        setae   al            ; 0f 97 c0
        ret                   ; c3

tgt:
        shr     rdi, 0x1f  ; 48 c1 ef 1f
        setne   al         ; 0f 95 c0
        ret                ; c3

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

2 participants