I've committed this patch extends the nvptx atomic_fetch_<logic><mode> pattern to accept SImode arguments regardless of the -misa argument supplied. Tom had pre-approved this patch awhile ago. As the test case demonstrates, it only works 32-bit pointers.
While adding the new test case, I noticed that I named atomic-fetch-2.c incorrectly; there should be an underscore between atomic and fetch. This patch also fixes that. I tested this patch using both a standalone nvptx compiler and x86_64 Linux with nvptx offloading. Cesar
[nvptx] Add atomic_fetch* support for SImode arguments. 2018-09-17 Cesar Philippidis <ce...@codesourcery.com> Bernd Schmidt <bernds_...@t-online.de> gcc/ * config/nvptx/nvptx.md (atomic_fetch_<logic><mode>): Enable with SImode args. gcc/testsuite/ * gcc.target/nvptx/atomic-fetch-2.c: Rename to ... * gcc.target/nvptx/atomic_fetch-2.c: ... this. * gcc.target/nvptx/atomic_fetch-3.c: New test. --- gcc/config/nvptx/nvptx.md | 2 +- .../{atomic-fetch-2.c => atomic_fetch-2.c} | 0 .../gcc.target/nvptx/atomic_fetch-3.c | 24 +++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) rename gcc/testsuite/gcc.target/nvptx/{atomic-fetch-2.c => atomic_fetch-2.c} (100%) create mode 100644 gcc/testsuite/gcc.target/nvptx/atomic_fetch-3.c diff --git a/gcc/config/nvptx/nvptx.md b/gcc/config/nvptx/nvptx.md index dd6032d021b..ca00b1d8073 100644 --- a/gcc/config/nvptx/nvptx.md +++ b/gcc/config/nvptx/nvptx.md @@ -1449,7 +1449,7 @@ UNSPECV_LOCK)) (set (match_operand:SDIM 0 "nvptx_register_operand" "=R") (match_dup 1))] - "TARGET_SM35" + "<MODE>mode == SImode || TARGET_SM35" "%.\\tatom%A1.b%T0.<logic>\\t%0, %1, %2;" [(set_attr "atomic" "true")]) diff --git a/gcc/testsuite/gcc.target/nvptx/atomic-fetch-2.c b/gcc/testsuite/gcc.target/nvptx/atomic_fetch-2.c similarity index 100% rename from gcc/testsuite/gcc.target/nvptx/atomic-fetch-2.c rename to gcc/testsuite/gcc.target/nvptx/atomic_fetch-2.c diff --git a/gcc/testsuite/gcc.target/nvptx/atomic_fetch-3.c b/gcc/testsuite/gcc.target/nvptx/atomic_fetch-3.c new file mode 100644 index 00000000000..36a83ebba9b --- /dev/null +++ b/gcc/testsuite/gcc.target/nvptx/atomic_fetch-3.c @@ -0,0 +1,24 @@ +/* Test the nvptx atomic instructions for __atomic_fetch_OP for + SImode arguments. */ + +/* { dg-do compile } */ +/* { dg-options "-O2 -m32" } */ + +int +main() +{ + unsigned long a = ~0; + unsigned b = 0xa; + + __atomic_fetch_add (&a, b, 0); + __atomic_fetch_and (&a, b, 0); + __atomic_fetch_or (&a, b, 0); + __atomic_fetch_xor (&a, b, 0); + + return a; +} + +/* { dg-final { scan-assembler "atom.add.u32" } } */ +/* { dg-final { scan-assembler "atom.b32.and" } } */ +/* { dg-final { scan-assembler "atom.b32.or" } } */ +/* { dg-final { scan-assembler "atom.b32.xor" } } */ -- 2.17.1