https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92237
Bug ID: 92237 Summary: [x86] Missed optimisation opportunity with bit tests Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: andrew.cooper3 at citrix dot com Target Milestone: --- See https://godbolt.org/z/mP-8Y7 An expression such as: bool foo(uint64_t val) { return (val & 0x120) == 0x20; } gets assembled to: <foo>: 0: 81 e7 20 01 00 00 and $0x120,%edi 6: 48 83 ff 20 cmp $0x20,%rdi a: 0f 94 c0 sete %al d: c3 retq Some part of optimisation has noticed that, due to the 32bit constant, the AND can be performed on %edi, but hasn't spotted that the same is true for the following CMP. In this example, the CMP could use %edi as well, and save emitting the REX prefix into the instruction stream.