public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenther at suse dot de" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/96189] Failure to use eflags from cmpxchg on x86
Date: Thu, 16 Jul 2020 07:23:22 +0000	[thread overview]
Message-ID: <bug-96189-4-a22IfGdwyR@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-96189-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #6 from rguenther at suse dot de <rguenther at suse dot de> ---
On July 16, 2020 9:05:52 AM GMT+02:00, ubizjak at gmail dot com
<gcc-bugzilla@gcc.gnu.org> wrote:
>https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96189
>
>Uroš Bizjak <ubizjak at gmail dot com> changed:
>
>           What    |Removed                     |Added
>----------------------------------------------------------------------------
>              CC|                            |jakub at gcc dot gnu.org,
>               |                            |rguenth at gcc dot gnu.org
>             Status|RESOLVED                    |REOPENED
>         Resolution|FIXED                       |---
>
>--- Comment #5 from Uroš Bizjak <ubizjak at gmail dot com> ---
>Hm...
>
>Please note that peephole2 scanning require exact RTL sequences, and
>already
>fails for e.g.:
>
>_Bool
>foo (unsigned int *x, unsigned int z)
>{
>  unsigned int y = 0;
>  __atomic_compare_exchange_n (x, &y, z, 0, __ATOMIC_RELAXED,
>__ATOMIC_RELAXED);
>  return y == 0;
>}
>
>(which is used in a couple of places throughout glibc), due to early
>peephole2
>optimization that converts:
>
>(insn 7 4 8 2 (set (reg:SI 0 ax [90])
>        (const_int 0 [0])) "cmpx0.c":5:3 75 {*movsi_internal}
>
>to:
>
>(insn 31 4 8 2 (parallel [
>            (set (reg:DI 0 ax [90])
>                (const_int 0 [0]))
>            (clobber (reg:CC 17 flags))
>
>Other than that, the required sequence is broken quite often by various
>reloads, due to the complexity of CMPXCHG insn.
>
>However, __atomic_compare_exchange_n returns a boolean value that is
>exactly
>what the first function is testing, so the following two functions are
>equivalent:
>
>--cut here--
>_Bool
>foo (unsigned int *x, unsigned int y, unsigned int z)
>{
>  unsigned int old_y = y;
>  __atomic_compare_exchange_n (x, &y, z, 0, __ATOMIC_RELAXED,
>__ATOMIC_RELAXED);
>  return y == old_y;
>}
>
>_Bool
>bar (unsigned int *x, unsigned int y, unsigned int z)
>{
>  return __atomic_compare_exchange_n (x, &y, z, 0, __ATOMIC_RELAXED,
>__ATOMIC_RELAXED);
>}
>--cut here--
>
>I wonder, if the above transformation can happen on the tree level, so
>it would
>apply universally for all targets, and would also handle CMPXCHG[8,16]B
>doubleword instructions on x86 targets.
>
>Let's ask experts.

In principle value numbering can make the comparison available at the cmpxchg
and replace the later comparison. We've pondered with this trick for memcpy
results for example. 

Richard.

  parent reply	other threads:[~2020-07-16  7:23 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-13 19:44 [Bug target/96189] New: " gabravier at gmail dot com
2020-07-13 19:55 ` [Bug target/96189] " gabravier at gmail dot com
2020-07-15  6:41 ` ubizjak at gmail dot com
2020-07-15 20:01 ` ubizjak at gmail dot com
2020-07-15 20:02 ` ubizjak at gmail dot com
2020-07-16  7:05 ` ubizjak at gmail dot com
2020-07-16  7:23 ` rguenther at suse dot de [this message]
2020-07-16 18:13 ` cvs-commit at gcc dot gnu.org
2020-11-20 15:12 ` ubizjak at gmail dot com

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-96189-4-a22IfGdwyR@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: link
Be 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).