Skip to content

[missed-opt] [isel] Unnecessary shift count masking in 128-bit arithmetic #171920

@purplesyringa

Description

@purplesyringa

Godbolt

__uint128_t shift(unsigned long x, unsigned long n) {
    return (__uint128_t)x << (n & 63);
}
; x86-64
shift(unsigned long, unsigned long):
        mov     rcx, rsi
        mov     rax, rdi
        shl     rax, cl
        shr     rdi
        and     cl, 63 ; unnecessary
        not     cl
        shr     rdi, cl
        mov     rdx, rdi
        ret
; aarch64
shift(unsigned long, unsigned long):
        and     x8, x1, #0x3f ; unnecessary
        lsr     x9, x0, #1
        lsl     x0, x0, x1
        eor     x8, x8, #0x3f
        lsr     x1, x9, x8
        ret

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions