https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105670
Bug ID: 105670 Summary: [x86] suboptimal code for branch over two bools Product: gcc Version: 12.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: fent at in dot tum.de Target Milestone: --- void test(bool a, bool b, int* t) { if (a & b) *t = 42; } With -O1, -O2, -O3, and -Os this produces: test(bool, bool, int*): test dil, dil je .L1 test sil, sil je .L1 mov DWORD PTR [rdx], 42 .L1: ret The following would be 5B shorter and also faster, since it minimizes branch misses: test(bool, bool, int*): test sil, dil je .L1 mov DWORD PTR [rdx], 42 .L1: ret Note that this is (somewhat) ABI dependent, but works on x86-64 System V, since: > bit 0 contains the truth value and bits 1 to 7 shall be zero