public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "thiago at kde dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/102566] [i386] GCC should emit LOCK BTS for simple bit-test-and-set operations with std::atomic
Date: Mon, 04 Oct 2021 23:25:24 +0000	[thread overview]
Message-ID: <bug-102566-4-YYuZmPtcsm@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-102566-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #11 from Thiago Macieira <thiago at kde dot org> ---
$ for ((i=0;i<32;++i)); do ~/dev/gcc/bin/gcc "-DCONSTANT=(1<<$i)" -S -o - -O2
/tmp/test.cpp | grep bts; done 
        lock btsl       $0, (%rdi)
        lock btsl       $1, (%rdi)
        lock btsl       $2, (%rdi)
        lock btsl       $3, (%rdi)
        lock btsl       $4, (%rdi)
        lock btsl       $5, (%rdi)
        lock btsl       $6, (%rdi)
        lock btsl       $7, (%rdi)
        lock btsl       $8, (%rdi)
        lock btsl       $9, (%rdi)
        lock btsl       $10, (%rdi)
        lock btsl       $11, (%rdi)
        lock btsl       $12, (%rdi)
        lock btsl       $13, (%rdi)
        lock btsl       $14, (%rdi)
        lock btsl       $15, (%rdi)
        lock btsl       $16, (%rdi)
        lock btsl       $17, (%rdi)
        lock btsl       $18, (%rdi)
        lock btsl       $19, (%rdi)
        lock btsl       $20, (%rdi)
        lock btsl       $21, (%rdi)
        lock btsl       $22, (%rdi)
        lock btsl       $23, (%rdi)
        lock btsl       $24, (%rdi)
        lock btsl       $25, (%rdi)
        lock btsl       $26, (%rdi)
        lock btsl       $27, (%rdi)
        lock btsl       $28, (%rdi)
        lock btsl       $29, (%rdi)
        lock btsl       $30, (%rdi)
        lock btsl       $31, (%rdi)

And after changing to long:

$ for ((i=32;i<64;++i)); do ~/dev/gcc/bin/gcc "-DCONSTANT=(1L<<$i)" -S -o - -O2
/tmp/test.cpp | grep bts; done
        lock btsq       $32, (%rdi)
        lock btsq       $33, (%rdi)
        lock btsq       $34, (%rdi)
        lock btsq       $35, (%rdi)
        lock btsq       $36, (%rdi)
        lock btsq       $37, (%rdi)
        lock btsq       $38, (%rdi)
        lock btsq       $39, (%rdi)
        lock btsq       $40, (%rdi)
        lock btsq       $41, (%rdi)
        lock btsq       $42, (%rdi)
        lock btsq       $43, (%rdi)
        lock btsq       $44, (%rdi)
        lock btsq       $45, (%rdi)
        lock btsq       $46, (%rdi)
        lock btsq       $47, (%rdi)
        lock btsq       $48, (%rdi)
        lock btsq       $49, (%rdi)
        lock btsq       $50, (%rdi)
        lock btsq       $51, (%rdi)
        lock btsq       $52, (%rdi)
        lock btsq       $53, (%rdi)
        lock btsq       $54, (%rdi)
        lock btsq       $55, (%rdi)
        lock btsq       $56, (%rdi)
        lock btsq       $57, (%rdi)
        lock btsq       $58, (%rdi)
        lock btsq       $59, (%rdi)
        lock btsq       $60, (%rdi)
        lock btsq       $61, (%rdi)
        lock btsq       $62, (%rdi)
        lock btsq       $63, (%rdi)

But:

$ cat /tmp/test2.cpp 
#include <atomic>
bool tbit(std::atomic<long> &i)
{
  return i.fetch_or(1, std::memory_order_relaxed) & (~1);
}
$ ~/dev/gcc/bin/gcc -S -o - -O2 /tmp/test2.cpp
        .file   "test.cpp"
        .text
/tmp/test.cpp: In function ‘bool tbit(std::atomic<long int>&)’:
/tmp/test.cpp:2:6: error: type mismatch in binary expression
    2 | bool tbit(std::atomic<long> &i)
      |      ^~~~
long int

long unsigned int

__int_type

_9 = _6 & -2;
during GIMPLE pass: fab
/tmp/test.cpp:2:6: internal compiler error: verify_gimple failed
0x119fbba verify_gimple_in_cfg(function*, bool)
        /home/tjmaciei/src/gcc/gcc/tree-cfg.c:5576
0x106ced7 execute_function_todo
        /home/tjmaciei/src/gcc/gcc/passes.c:2042
0x106d8fb execute_todo
        /home/tjmaciei/src/gcc/gcc/passes.c:2096
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

  parent reply	other threads:[~2021-10-04 23:25 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-02 16:08 [Bug target/102566] New: " thiago at kde dot org
2021-10-02 20:30 ` [Bug target/102566] " pinskia at gcc dot gnu.org
2021-10-03 12:56 ` hjl.tools at gmail dot com
2021-10-03 13:06 ` hjl.tools at gmail dot com
2021-10-03 13:19 ` [Bug tree-optimization/102566] " hjl.tools at gmail dot com
2021-10-03 15:10 ` hjl.tools at gmail dot com
2021-10-03 16:45 ` [Bug middle-end/102566] " hjl.tools at gmail dot com
2021-10-03 22:36 ` hjl.tools at gmail dot com
2021-10-04 15:58 ` thiago at kde dot org
2021-10-04 16:10 ` thiago at kde dot org
2021-10-04 16:13 ` thiago at kde dot org
2021-10-04 21:46 ` hjl.tools at gmail dot com
2021-10-04 23:25 ` thiago at kde dot org [this message]
2021-10-04 23:26 ` thiago at kde dot org
2021-10-05  4:40 ` hjl.tools at gmail dot com
2021-10-05 15:23 ` hjl.tools at gmail dot com
2021-10-05 15:57 ` thiago at kde dot org
2021-10-05 16:02 ` pinskia at gcc dot gnu.org
2021-10-05 19:26 ` hjl.tools at gmail dot com
2021-10-05 19:30 ` hjl.tools at gmail dot com
2021-10-05 19:36 ` thiago at kde dot org
2021-10-06  8:00 ` jakub at gcc dot gnu.org
2021-10-06 15:40 ` thiago at kde dot org
2021-10-06 15:47 ` hjl.tools at gmail dot com
2021-10-06 15:54 ` thiago at kde dot org
2021-10-06 16:05 ` hjl.tools at gmail dot com
2021-10-07 15:18 ` thiago at kde dot org
2021-10-07 15:19 ` hjl.tools at gmail dot com
2021-10-07 15:35 ` thiago at kde dot org
2021-10-10 13:51 ` hjl.tools at gmail dot com
2021-10-22  3:31 ` crazylht at gmail dot com
2021-11-04 21:24 ` thiago at kde dot org
2021-11-10  9:17 ` cvs-commit at gcc dot gnu.org
2022-10-29 10:53 ` marko.makela at mariadb dot com
2022-10-31  2:42 ` crazylht at gmail dot com
2022-11-01  8:41 ` marko.makela at mariadb dot com
2022-11-01 16:46 ` hjl.tools at gmail dot com
2022-11-07 19:20 ` cvs-commit at gcc dot gnu.org
2023-01-18 18:49 ` hjl.tools at gmail dot com
2023-01-18 22:30 ` hjl.tools 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-102566-4-YYuZmPtcsm@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).