Skip to content

manual popcnt has unnecessary cmove since clang 16.0.0 #62450

Closed
@y21

Description

@y21

Code:

int popcnt(int x) {
    int cnt = 0;
    while (x) {
        cnt++;
        x &= x - 1;
    }
    return cnt;
}

On x86-64 clang 16.0.0 as well as trunk (17.0.0 d7fa921) with -O -march=haswell compiles to:

popcnt:                                 # @popcnt
        popcnt  eax, edi
        cmove   eax, edi
        ret

(Note the unnecessary cmove)

On clang 15.0.0 with the same options:

popcnt:                                 # @popcnt
        popcnt  eax, edi
        ret

Reproducer

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions