https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85516
Bug ID: 85516 Summary: [missed-optimization] gcc does not convert multiple compares against constants to a shift+bitmask test Product: gcc Version: 8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: a...@cloudius-systems.com Target Milestone: --- Consider === example starts === enum class E { a, b, c, d, e, f, g, h, i, j }; bool check_mask(E v) { return v == E::b || v == E::e || v == E::f || v == E::j; } === example ends === This can be compiled to just three instructions (x86): mov $0x232, %eax bt %edi, %eax setc %al but instead gcc compiles it to: cmpl $1, %edi sete %al cmpl $4, %edi sete %dl orb %dl, %al jne .L1 subl $5, %edi andl $-5, %edi sete %al .L1: which is three times as large and contains a possibly unpredictable branch. More bits in the mask will presumably generate larger code.