public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "josephcsible at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/105875] New: Toggling an atomic_bool is inefficient Date: Tue, 07 Jun 2022 15:10:30 +0000 [thread overview] Message-ID: <bug-105875-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105875 Bug ID: 105875 Summary: Toggling an atomic_bool is inefficient Product: gcc Version: 12.1.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: josephcsible at gmail dot com Target Milestone: --- Target: x86_64-pc-linux-gnu Consider this C code: #include <stdatomic.h> atomic_bool b; atomic_char c; _Bool b2; void f1(void) { b ^= 1; } void f2(void) { c ^= 1; } void f3(void) { b2 ^= 1; } At -O3, those functions compile into this: f1: movzbl b(%rip), %eax .L5: movb %al, -1(%rsp) xorl $1, %eax movl %eax, %edx movzbl -1(%rsp), %eax lock cmpxchgb %dl, b(%rip) jne .L5 ret f2: lock xorb $1, c(%rip) ret f3: xorb $1, b2(%rip) ret The code generated for f1 is inefficient. It should have just done a "lock xorb $1, b(%rip)".
next reply other threads:[~2022-06-07 15:10 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-06-07 15:10 josephcsible at gmail dot com [this message] 2022-06-21 6:35 ` [Bug tree-optimization/105875] " pinskia at gcc dot gnu.org 2023-05-17 23:32 ` [Bug c/105875] " 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-105875-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).