From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 807333858D39; Wed, 31 Aug 2022 11:16:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 807333858D39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661944609; bh=wGG1SkPFkI1RoHyG1YB0ukjjAdtfzoRp7T+2gXys5eU=; h=From:To:Subject:Date:From; b=Y0/SpmYrR7YUXsf33TEz/3eJGJoUcKF7WsS5JeUIpq6iBQdtmp2ZV37O21hJmaTYS aA1Uc8oC6fpmwTrNkGdkZ9EEvk/WcfwPDhmGgsQFC3lLWZiyb0ng7ogtb4FShpbO70 nHoOtMHJu02Zp8A0aH6zHtqOXgJ3kWhtTkZdGrgI= From: "chfast at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/106786] New: Regression in cmp+sbb Date: Wed, 31 Aug 2022 11:16:48 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 12.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: chfast 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106786 Bug ID: 106786 Summary: Regression in cmp+sbb Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: chfast at gmail dot com Target Milestone: --- I noticed a regression when using the builtin for sbb instruction (__builtin_ia32_sbb_u64). typedef unsigned long long u64; struct R { u64 value; bool carry; }; inline R subc(u64 x, u64 y, bool carry) noexcept { u64 d; const u64 carryout =3D __builtin_ia32_sbb_u64(carry, x, y, &d); return {d, carryout !=3D 0}; } bool bad(u64 x, u64 y) { const R z =3D subc(x, y, false); R a =3D subc(x, y, z.carry); return a.carry; } https://godbolt.org/z/f41KKe19q The expected assembly is cmp rdi, rsi sbb rdi, rsi But GCC 12.2.0 and trunk produces cmp rdi, rsi setb al movzx eax, al add al, -1 sbb rdi, rsi The regression is in 12.2.0, the 11.3.0 optimizes properly. There are simple changes which will bring back the expected optimization: - change `const R z` to `R z`, - change `bool carry` to `u64 carry`. This may be related to calling convention / ABI because I noticed in one of= the tree optimization outputs for 12.2.0 that the `bool carry` is forced to be = in memory: `MEM [(struct R *)&z + 8B]`. https://godbolt.org/z/7zh7GxraK=