[nvptx] Fix .local atomic regressions
authorTom de Vries <tdevries@suse.de>
Thu, 3 Feb 2022 13:00:02 +0000 (14:00 +0100)
committerTom de Vries <tdevries@suse.de>
Tue, 8 Feb 2022 08:54:30 +0000 (09:54 +0100)
commit04b54cc486cc6fcc40380445e500eaf46d7901dc
treee9b9461242182dd61d5342588d3e6b1673fc92f0
parent0af7ef050aed9f678d70d79931ede38374fde863
[nvptx] Fix .local atomic regressions

In PR target/104364, two problems were reported:
- in muniform-simt mode, an atom.cas insn is no longer executed in the
  "master lane" only.
- in msoft-stack mode, an __atomic_compare_exchange_n on stack memory is
  translated assuming it accesses local memory, while that's not the case.

Fix these by:
- ensuring that all insns with atomic attribute are also predicable, such
  that the validate_change in nvptx_reorg_uniform_simt will succeed, and
  asserting that it does, and
- guarding the local atomics implementation with a new function
  nvptx_mem_local_p that correctly handles msoft-stack.

Tested on x86_64 with nvptx accelerator.

gcc/ChangeLog:

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

PR target/104364
* config/nvptx/nvptx-protos.h (nvptx_mem_local_p): Declare.
* config/nvptx/nvptx.cc (nvptx_reorg_uniform_simt): Assert that
change is validated.
(nvptx_mem_local_p): New function.
* config/nvptx/nvptx.md: Use nvptx_mem_local_p.
(define_c_enum "unspecv"): Add UNSPECV_CAS_LOCAL.
(define_insn "atomic_compare_and_swap<mode>_1_local"): New
non-atomic, non-predicable define_insn, factored out of ...
(define_insn "atomic_compare_and_swap<mode>_1"): ... here.
Make predicable again.
(define_expand "atomic_compare_and_swap<mode>"): Use
atomic_compare_and_swap<mode>_1_local.

gcc/testsuite/ChangeLog:

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

PR target/104364
* gcc.target/nvptx/softstack-2.c: New test.
* gcc.target/nvptx/uniform-simt-1.c: New test.
gcc/config/nvptx/nvptx-protos.h
gcc/config/nvptx/nvptx.cc
gcc/config/nvptx/nvptx.md
gcc/testsuite/gcc.target/nvptx/softstack-2.c [new file with mode: 0644]
gcc/testsuite/gcc.target/nvptx/uniform-simt-1.c [new file with mode: 0644]