public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "lh_mouse at 126 dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/105495] New: `__atomic_compare_exchange` prevents tail-call optimization Date: Thu, 05 May 2022 14:00:07 +0000 [thread overview] Message-ID: <bug-105495-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105495 Bug ID: 105495 Summary: `__atomic_compare_exchange` prevents tail-call optimization Product: gcc Version: 11.3.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: lh_mouse at 126 dot com Target Milestone: --- Godbolt: https://gcc.godbolt.org/z/7ob6zc17P Offending testcase: ```c typedef struct { int b; } cond; int __MCF_batch_release_common(cond* p, int c); int _MCF_cond_signal_some(cond* p, int x) { cond c = {x}, n = {2}; __atomic_compare_exchange(p, &c, &n, 1, 0, 0); return __MCF_batch_release_common(p, x); } ``` GCC output: ```asm _MCF_cond_signal_some: sub rsp, 24 mov edx, 2 mov eax, esi mov DWORD PTR [rsp+12], esi lock cmpxchg DWORD PTR [rdi], edx je .L2 mov DWORD PTR [rsp+12], eax <------- note this extra store, which clang doesn't generate .L2: call __MCF_batch_release_common add rsp, 24 ret ``` Clang output: ```asm _MCF_cond_signal_some: # @_MCF_cond_signal_some mov ecx, 2 mov eax, esi lock cmpxchg dword ptr [rdi], ecx jmp __MCF_batch_release_common # TAILCALL ``` 1. If `cond` was defined as a scalar type such as `long`, there is no such issue. 2. `__atomic_exchange` doesn't suffer from this issue.
next reply other threads:[~2022-05-05 14:00 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-05-05 14:00 lh_mouse at 126 dot com [this message] 2022-05-05 14:10 ` [Bug c/105495] " lh_mouse at 126 dot com 2022-05-05 14:17 ` rguenth at gcc dot gnu.org 2022-05-05 14:30 ` lh_mouse at 126 dot com 2022-05-05 14:33 ` jakub at gcc dot gnu.org 2022-05-05 15:28 ` [Bug middle-end/105495] " pinskia at gcc dot gnu.org 2022-05-06 7:40 ` lh_mouse at 126 dot com 2022-10-31 7:55 ` [Bug tree-optimization/105495] " pinskia at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-105495-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).