From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 1FCCE3858D37; Thu, 21 Apr 2022 17:47:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1FCCE3858D37 From: "denis.campredon at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/105338] New: Regression: jump or cmove generated for pattern (x ? CST : 0) Date: Thu, 21 Apr 2022 17:47:22 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: rtl-optimization 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, 21 Apr 2022 17:47:23 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105338 Bug ID: 105338 Summary: Regression: jump or cmove generated for pattern (x ? CST : 0) Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: denis.campredon at gmail dot com Target Milestone: --- int f(int i) { return i ? 5 : 0; } int g(int i) { return i ? -2 : 0; } int h(int b) { return !!b * -2; } int i(int b) { return !!b * 5; } int j(int b) { if (!b) return 0; return -2; } ------------- With -02 gcc 11.2 the five functions above output branchless code like: f(int): neg edi sbb eax, eax and eax, 5 ret g(int): neg edi sbb eax, eax and eax, -2 ret ... -------------- Whereas -02 gcc 12 now outputs a cmov or jump depending of sign of the constant: f(int): mov eax, edi test edi, edi mov edx, 5 cmovne eax, edx ret g(int): mov eax, edi test edi, edi jne .L11 ret .L11: mov eax, -2 ret h(int): mov eax, edi test edi, edi jne .L17 ret .L17: mov eax, -2 ret i(int): mov eax, edi test edi, edi mov edx, 5 cmovne eax, edx ret j(int): mov eax, edi test edi, edi mov edx, -2 cmovne eax, edx ret --------------------------- Alternatively, with the following code int k(int b) { bool b2 =3D b; return b2 * 5; } ---------------- Both gcc 12 and 11.2 are outputing k(int): xor eax, eax test edi, edi setne al lea eax, [rax+rax*4] ret=