public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug target/103066] __sync_val_compare_and_swap/__sync_bool_compare_and_swap aren't optimized Date: Fri, 05 Nov 2021 12:55:10 +0000 [thread overview] Message-ID: <bug-103066-4-IIlNGvhvrq@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-103066-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103066 --- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> --- E.g. the builtin is often used in a loop where the user does his own atomic load first and decides what to do based on that. Say for float f; void foo () { #pragma omp atomic f += 3.0f; } with -O2 -fopenmp we emit: D.2113 = &f; D.2115 = __atomic_load_4 (D.2113, 0); D.2114 = D.2115; <bb 3> : D.2112 = VIEW_CONVERT_EXPR<float>(D.2114); _1 = D.2112 + 3.0e+0; D.2116 = VIEW_CONVERT_EXPR<unsigned int>(_1); D.2117 = .ATOMIC_COMPARE_EXCHANGE (D.2113, D.2114, D.2116, 4, 0, 0); D.2118 = REALPART_EXPR <D.2117>; D.2119 = D.2114; D.2114 = D.2118; if (D.2118 != D.2119) goto <bb 3>; [0.00%] else goto <bb 4>; [100.00%] <bb 4> : return; which is essentially void foo () { int x = __atomic_load_4 ((int *) &f, __ATOMIC_RELAXED), y; float g; do { __builtin_memcpy (&g, &x, 4); g += 3.0f; __builtin_memcpy (&y, &g, 4); } while (!__atomic_compare_exchange_n ((int *) &f, &x, y, false, __ATOMIC_RELAXED, __ATOMIC_RELAXED)); } Can you explain how your proposed change would improve this? It would just slow it down and make it larger.
next prev parent reply other threads:[~2021-11-05 12:55 UTC|newest] Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-11-03 17:35 [Bug target/103066] New: " hjl.tools at gmail dot com 2021-11-05 5:57 ` [Bug target/103066] " wwwhhhyyy333 at gmail dot com 2021-11-05 11:57 ` hjl.tools at gmail dot com 2021-11-05 12:17 ` jakub at gcc dot gnu.org 2021-11-05 12:33 ` hjl.tools at gmail dot com 2021-11-05 12:44 ` jakub at gcc dot gnu.org 2021-11-05 12:55 ` jakub at gcc dot gnu.org [this message] 2021-11-05 13:07 ` hjl.tools at gmail dot com 2021-11-05 13:25 ` jakub at gcc dot gnu.org 2021-11-05 17:40 ` redi at gcc dot gnu.org 2021-11-06 16:31 ` thiago at kde dot 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-103066-4-IIlNGvhvrq@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).