From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B06233858D3C; Thu, 5 May 2022 14:10:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B06233858D3C From: "lh_mouse at 126 dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/105495] `__atomic_compare_exchange` prevents tail-call optimization Date: Thu, 05 May 2022 14:10:46 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 11.3.1 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: lh_mouse at 126 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: Message-ID: In-Reply-To: References: 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, 05 May 2022 14:10:46 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105495 --- Comment #1 from LIU Hao --- A possible workaround is to use a scalar type to provide storage for local variables, and cast them as needed: Godbolt: https://gcc.godbolt.org/z/n7zq7Pn4G ```c typedef struct { int b; } cond; int __MCF_batch_release_common(cond* p, int c); int _MCF_cond_signal_some(cond* p, int x) { int c =3D {x}, n =3D {2}; __atomic_compare_exchange((cond*)p, (cond*)&c, (cond*)&n, 1, 0, 0); return __MCF_batch_release_common(p, x); } ``` This makes GCC output the same assembly as Clang.=