public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/66867] New: Suboptimal code generation for C11 atomic_compare_exchange_strong_explicit()
@ 2015-07-14 11:17 sebastian.huber@embedded-brains.de
  2015-07-17 20:43 ` [Bug target/66867] " sebastian.huber@embedded-brains.de
  2015-09-21  7:17 ` [Bug target/66867] Suboptimal code generation for atomic_compare_exchange amodra at gmail dot com
  0 siblings, 2 replies; 3+ messages in thread
From: sebastian.huber@embedded-brains.de @ 2015-07-14 11:17 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66867

            Bug ID: 66867
           Summary: Suboptimal code generation for C11
                    atomic_compare_exchange_strong_explicit()
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sebastian.huber@embedded-brains.de
  Target Milestone: ---

At least on ARM and PowerPC for the following test case

#include <stdatomic.h>

void f(atomic_uint *a)
{
  unsigned int e = 0;
  atomic_compare_exchange_strong_explicit(a, &e, 1, memory_order_relaxed,
memory_order_relaxed);
}

a superfluous stack frame and store is generated:

        .file   "test-cas.c"
        .machine ppc
        .section        ".text"
        .align 2
        .globl f
        .type   f, @function
f:
        stwu 1,-24(1) <- Superfluous
        li 9,0
        li 10,1
        stw 9,8(1) <- Superfluous
.L2:
        lwarx 9,0,3
        cmpwi 0,9,0
        bne- 0,.L3
        stwcx. 10,0,3
        bne- 0,.L2
.L3:
        addi 1,1,24 <- Superfluous
        blr
        .size   f, .-f
        .ident  "GCC: (GNU) 6.0.0 20150714 (experimental)"


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

* [Bug target/66867] Suboptimal code generation for C11 atomic_compare_exchange_strong_explicit()
  2015-07-14 11:17 [Bug c/66867] New: Suboptimal code generation for C11 atomic_compare_exchange_strong_explicit() sebastian.huber@embedded-brains.de
@ 2015-07-17 20:43 ` sebastian.huber@embedded-brains.de
  2015-09-21  7:17 ` [Bug target/66867] Suboptimal code generation for atomic_compare_exchange amodra at gmail dot com
  1 sibling, 0 replies; 3+ messages in thread
From: sebastian.huber@embedded-brains.de @ 2015-07-17 20:43 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66867

--- Comment #1 from Sebastian Huber <sebastian.huber@embedded-brains.de> ---
This problem is also present on x86.  The depreated
__sync_bool_compare_and_swap() produces better code.

#include <stdatomic.h>

void f(atomic_uint *a)
{
  unsigned int e = 0;
  atomic_compare_exchange_strong_explicit(a, &e, 1, memory_order_relaxed,
memory_order_relaxed);
}

void g(unsigned int *a)
{
  __sync_bool_compare_and_swap(a, 0, 1);
}

        .file   "cas.c"
        .section        .text.unlikely,"ax",@progbits
.LCOLDB0:
        .text
.LHOTB0:
        .p2align 4,,15
        .globl  f
        .type   f, @function
f:
.LFB0:
        .cfi_startproc
        movl    $1, %edx
        xorl    %eax, %eax
        movl    $0, -4(%rsp) <- Superfluous
        lock cmpxchgl   %edx, (%rdi)
        ret
        .cfi_endproc
.LFE0:
        .size   f, .-f
        .section        .text.unlikely
.LCOLDE0:
        .text
.LHOTE0:
        .section        .text.unlikely
.LCOLDB1:
        .text
.LHOTB1:
        .p2align 4,,15
        .globl  g
        .type   g, @function
g:
.LFB1:
        .cfi_startproc
        movl    $1, %edx
        xorl    %eax, %eax
        lock cmpxchgl   %edx, (%rdi)
        ret
        .cfi_endproc
.LFE1:
        .size   g, .-g
        .section        .text.unlikely
.LCOLDE1:
        .text
.LHOTE1:
        .ident  "GCC: (GNU) 6.0.0 20150717 (experimental)"
        .section        .note.GNU-stack,"",@progbits


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

* [Bug target/66867] Suboptimal code generation for atomic_compare_exchange
  2015-07-14 11:17 [Bug c/66867] New: Suboptimal code generation for C11 atomic_compare_exchange_strong_explicit() sebastian.huber@embedded-brains.de
  2015-07-17 20:43 ` [Bug target/66867] " sebastian.huber@embedded-brains.de
@ 2015-09-21  7:17 ` amodra at gmail dot com
  1 sibling, 0 replies; 3+ messages in thread
From: amodra at gmail dot com @ 2015-09-21  7:17 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66867

Alan Modra <amodra at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|                            |powerpc64*-*-*, x86_64-*-*
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2015-09-21
                 CC|                            |amodra at gmail dot com
            Summary|Suboptimal code generation  |Suboptimal code generation
                   |for C11                     |for atomic_compare_exchange
                   |atomic_compare_exchange_str |
                   |ong_explicit()              |
     Ever confirmed|0                           |1

--- Comment #2 from Alan Modra <amodra at gmail dot com> ---
Confirmed.  Here's another related testcase showing unnecessary stack memory
writes and reads on both powerpc64le and x86_64.

int test2 (int *ptr, int value, int comparand)
{
  __atomic_compare_exchange_n (ptr, &comparand, value,
                               false, __ATOMIC_RELAXED, __ATOMIC_RELAXED);
  return comparand;
}


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

end of thread, other threads:[~2015-09-21  7:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-14 11:17 [Bug c/66867] New: Suboptimal code generation for C11 atomic_compare_exchange_strong_explicit() sebastian.huber@embedded-brains.de
2015-07-17 20:43 ` [Bug target/66867] " sebastian.huber@embedded-brains.de
2015-09-21  7:17 ` [Bug target/66867] Suboptimal code generation for atomic_compare_exchange amodra at gmail dot com

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