gcc/libgomp/testsuite/libgomp.c-c++-common/reduction-16.c
Tom de Vries 4ac7b66958 [libgomp, nvptx] Add __sync_compare_and_swap_16
As reported here
( https://gcc.gnu.org/pipermail/gcc-patches/2020-September/553070.html  ),
when running test-case libgomp.c-c++-common/reduction-16.c for powerpc host
with nvptx accelerator, we run into:
...
unresolved symbol __sync_val_compare_and_swap_16
...

I can reproduce the problem on x86_64 with a trigger patch that:
- initializes ix86_isa_flags2 to TARGET_ISA2_CX16
- enables define_expand "atomic_load<mode>" in gcc/config/i386/sync.md
  for TImode

The problem is that omp-expand.c generates atomic builtin calls based on
checks whether those are supported on the host, which forces the target to
support these, even though those checks fail for the accelerator target.

Fix this by:
- adding a __sync_val_compare_and_swap_16 in libgomp for nvptx,
  which falls back onto libatomic's __atomic_compare_and_swap_16
- adding -foffload=-latomic in the test-case

Tested libgomp on x86_64-linux with nvptx accelerator.

Tested libgomp with trigger patch on x86_64-linux with nvptx accelerator.

libgomp/ChangeLog:

	* config/nvptx/atomic.c: New file.  Add
	__sync_val_compare_and_swap_16.
	* testsuite/libgomp.c-c++-common/reduction-16.c: Add -latomic for
	target offload_target_nvptx.
2020-09-14 08:28:56 +02:00

55 lines
1.0 KiB
C

/* { dg-do run } */
/* { dg-additional-options "-foffload=-latomic" { target offload_target_nvptx } } */
#include <stdlib.h>
#define N 512
#define GENERATE_TEST(T) \
int test_##T (void) \
{ \
T a[N], res = 0; \
\
for (int i = 0; i < N; ++i) \
a[i] = i & 1; \
\
_Pragma("omp target teams distribute reduction(||:res) defaultmap(tofrom:scalar)") \
for (int i = 0; i < N; ++i) \
res = res || a[i]; \
\
/* res should be non-zero. */\
if (!res) \
return 1; \
\
_Pragma("omp target teams distribute reduction(&&:res) defaultmap(tofrom:scalar)") \
for (int i = 0; i < N; ++i) \
res = res && a[i]; \
\
/* res should be zero. */ \
return res; \
}
GENERATE_TEST(char)
GENERATE_TEST(short)
GENERATE_TEST(int)
GENERATE_TEST(long)
#ifdef __SIZEOF_INT128__
GENERATE_TEST(__int128)
#endif
int main(void)
{
if (test_char ())
abort ();
if (test_short ())
abort ();
if (test_int ())
abort ();
if (test_long ())
abort ();
#ifdef __SIZEOF_INT128__
if (test___int128 ())
abort ();
#endif
}