https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105276
Bug ID: 105276 Summary: [12 Regression] executed once loop not optimized anymore Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: denis.campredon at gmail dot com Target Milestone: --- bool foo(unsigned i) { bool result = true; while (i) { i = i % 3; i = i - (i==2 ? 2 : i ? 1 : 0); result = !result; } return result; } -------------- compiled with g++ 11.2 and -O2 it produces: ----------------- foo(unsigned int): test edi, edi sete al ret ---------------- With current trunk and -02 lots of instructions are generated, the loop is still present, about 30 instructions are produced. Also, when compiled with -Os trunk produces loopless assembly: ------------------ foo(unsigned int): mov dl, 1 test edi, edi je .L1 xor edx, edx .L1: mov eax, edx ret ------------------- Whereas using -Os and g++ 11.2 it uses one less register: ------------------ foo(unsigned int): mov al, 1 test edi, edi je .L4 xor eax, eax .L4: ret