]> git.ipfire.org Git - thirdparty/gcc.git/commit
[nvptx] Handle pre-sm_7x shared atomic store using atomic exchange
authorTom de Vries <tdevries@suse.de>
Thu, 13 Jan 2022 12:13:44 +0000 (13:13 +0100)
committerTom de Vries <tdevries@suse.de>
Thu, 10 Feb 2022 09:10:44 +0000 (10:10 +0100)
commit3e7d4e82dc9fecb051e9ac422c312b26206d5ecd
treec936837997675c954294872736c8ea5ba16b0daf
parent5b2d679bbbcc2b976c6e228ba63afdf67c33164e
[nvptx] Handle pre-sm_7x shared atomic store using atomic exchange

The ptx isa specifies (for pre-sm_7x) that atomic operations on shared memory
locations do not guarantee atomicity with respect to normal store instructions
to the same address.

This can be fixed by:
- inserting barriers between normal stores and atomic operations to a common
  address
- using atom.exch to store to locations accessed by other atomic operations.

It's not clearly spelled out which barriers are needed, and a barrier seem more
expensive than atomic exchange.

Implement the pre-sm_7x shared atomic store using atomic exchange.

That includes stores using generic addressing, since those may also point to
shared memory.

Tested on x86-64 with nvptx accelerator.

gcc/ChangeLog:

2022-02-02  Tom de Vries  <tdevries@suse.de>

* config/nvptx/nvptx-protos.h (nvptx_mem_maybe_shared_p): Declare.
* config/nvptx/nvptx.cc (nvptx_mem_data_area): New static function.
(nvptx_mem_maybe_shared_p): New function.
* config/nvptx/nvptx.md (define_expand "atomic_store<mode>"): New
define_expand.

gcc/testsuite/ChangeLog:

2022-02-02  Tom de Vries  <tdevries@suse.de>

* gcc.target/nvptx/atomic-store-1.c: New test.
* gcc.target/nvptx/atomic-store-3.c: New test.
* gcc.target/nvptx/stack-atomics-run.c: Update.
gcc/config/nvptx/nvptx-protos.h
gcc/config/nvptx/nvptx.cc
gcc/config/nvptx/nvptx.md
gcc/testsuite/gcc.target/nvptx/atomic-store-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/nvptx/atomic-store-3.c [new file with mode: 0644]
gcc/testsuite/gcc.target/nvptx/stack-atomics-run.c