From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 155653858418; Thu, 14 Apr 2022 13:47:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 155653858418 From: "denis.campredon at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/105276] New: [12 Regression] executed once loop not optimized anymore Date: Thu, 14 Apr 2022 13:47:31 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: denis.campredon at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Apr 2022 13:47:32 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105276 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 =3D true; while (i) { i =3D i % 3; i =3D i - (i=3D=3D2 ? 2 : i ? 1 : 0); result =3D !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=