Skip to content

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

Open
@Kmeakin

Description

@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

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions