https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95861
Bug ID: 95861 Summary: popcnt --- unnecessary leading xor instruction Product: gcc Version: 9.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: zero at smallinteger dot com Target Milestone: --- Created attachment 48778 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48778&action=edit sample code Consider the attached code, compiled with -O3 -mpopcnt. The assembly produced in gcc 9.3 is below (the same code is generated by gcc 10.x at godbolt). foo(unsigned long long): xor eax, eax popcnt rax, rdi ret The popcnt instruction will overwrite rax. Whether eax is cleared with xor has no effect. No xor instruction should be emitted in this case. For reference, trunk clang emits this code instead: foo(unsigned long long): # @foo(unsigned long long) popcnt rax, rdi ret This second code sample is as expected.