public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/105875] New: Toggling an atomic_bool is inefficient
@ 2022-06-07 15:10 josephcsible at gmail dot com
  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
  0 siblings, 2 replies; 3+ messages in thread
From: josephcsible at gmail dot com @ 2022-06-07 15:10 UTC (permalink / raw)
  To: gcc-bugs

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)".

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-05-17 23:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-07 15:10 [Bug c/105875] New: Toggling an atomic_bool is inefficient josephcsible at gmail dot com
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

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).