https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88841
Bug ID: 88841 Summary: Missed optimization transforming cascading ||s into a bit select Product: gcc Version: 9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: other Assignee: unassigned at gcc dot gnu.org Reporter: matt at godbolt dot org Target Milestone: --- It seems around GCC 7 an optimization was added turning multiple comparisons of a small range into a bit-select. This optimization seems to be sensitive to the ordering of the comparisons, which seems like a missed opportunity. On x86_64 GCCs 7 and above (tested with trunk 9.0 too) with -O2 : ---snip bool isspc_1(char c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t'; } bool isspc_2(char c) { return c == ' ' || c == '\r' || c == '\n' || c == '\t'; } --- end snip (see https://godbolt.org/z/ovB_Oz ) ...the isspc_2 is optimized using the bit selection optimization, but the isspc_1 is not. The only difference is the order of the comparisons. It's not clear to me which is actually faster, but my instinct is the results of these two functions should be the same code.