Skip to content

[x86-64 BMI1] Missed blsi emit when & x can be unnecessarily factored out of (x & -x) #131587

@Validark

Description

@Validark

This code: (Zig Godbolt) (LLVM Godbolt)

export fn z(b: bool, x: u64) u64 {
    const y = x & -%x; // blsi
    return if (b) y else x;
}

Gives:

        mov     rcx, rsi
        neg     rcx
        test    edi, edi
        mov     rax, -1
        cmovne  rax, rcx
        and     rax, rsi

It should be:

        blsi    rax, rsi
        test    edi, edi
        cmove   rax, rsi

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions