From c18c98c0ade56bc46ce65bbf5cdff26a2577c990 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Wed, 7 May 2008 09:28:14 +0200 Subject: re PR middle-end/36106 (#pragma omp atomic issues with floating point types) PR middle-end/36106 * omp-low.c (expand_omp_atomic_pipeline): Load value using the integral type rather than floating point, then VIEW_CONVERT_EXPR to the floating point type. * testsuite/libgomp.c/atomic-5.c: New test. * testsuite/libgomp.c/atomic-6.c: New test. * testsuite/libgomp.c/autopar-1.c: New test. From-SVN: r135027 --- libgomp/testsuite/libgomp.c/atomic-5.c | 40 ++++++++++++++++++++++++++++++ libgomp/testsuite/libgomp.c/atomic-6.c | 36 +++++++++++++++++++++++++++ libgomp/testsuite/libgomp.c/autopar-1.c | 44 +++++++++++++++++++++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 libgomp/testsuite/libgomp.c/atomic-5.c create mode 100644 libgomp/testsuite/libgomp.c/atomic-6.c create mode 100644 libgomp/testsuite/libgomp.c/autopar-1.c (limited to 'libgomp/testsuite') diff --git a/libgomp/testsuite/libgomp.c/atomic-5.c b/libgomp/testsuite/libgomp.c/atomic-5.c new file mode 100644 index 0000000..3b4b0f1 --- /dev/null +++ b/libgomp/testsuite/libgomp.c/atomic-5.c @@ -0,0 +1,40 @@ +/* PR middle-end/36106 */ +/* { dg-options "-O2" } */ +/* { dg-options "-O2 -mcx16" { target { { i?86-*-* x86_64-*-* } && lp64 } } } */ + +#ifdef __x86_64__ +# include "../../../gcc/config/i386/cpuid.h" +#endif + +extern void abort (void); + +int __attribute__((noinline)) +do_test (void) +{ + long double d = .0L; + int i; + #pragma omp parallel for shared (d) + for (i = 0; i < 10; i++) + #pragma omp atomic + d += 1.0L; + if (d != 10.0L) + abort (); + return 0; +} + +int +main (void) +{ +#ifdef __x86_64__ + unsigned int eax, ebx, ecx, edx; + + if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx)) + return 0; + + if (ecx & bit_CMPXCHG16B) + do_test (); +#else + do_test (); +#endif + return 0; +} diff --git a/libgomp/testsuite/libgomp.c/atomic-6.c b/libgomp/testsuite/libgomp.c/atomic-6.c new file mode 100644 index 0000000..949fc3d --- /dev/null +++ b/libgomp/testsuite/libgomp.c/atomic-6.c @@ -0,0 +1,36 @@ +/* PR middle-end/36106 */ +/* { dg-options "-O2" } */ +/* { dg-options "-O2 -march=i586" { target { { i?86-*-* x86_64-*-* } && ilp32 } } } */ + +#ifdef __i386__ +# include "../../../gcc/config/i386/cpuid.h" +#endif + +extern void abort (void); + +union { unsigned long long l; double d; } u = { .l = 0x7ff0000000072301ULL }; + +int __attribute__((noinline)) +do_test (void) +{ +#pragma omp atomic + u.d += 1.0L; + return 0; +} + +int +main (void) +{ +#ifdef __i386__ + unsigned int eax, ebx, ecx, edx; + + if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx)) + return 0; + + if (edx & bit_CMPXCHG8B) + do_test (); +#else + do_test (); +#endif + return 0; +} diff --git a/libgomp/testsuite/libgomp.c/autopar-1.c b/libgomp/testsuite/libgomp.c/autopar-1.c new file mode 100644 index 0000000..e56549b --- /dev/null +++ b/libgomp/testsuite/libgomp.c/autopar-1.c @@ -0,0 +1,44 @@ +/* { dg-do run } */ +/* { dg-options "-ftree-parallelize-loops=4 -O2 -ffast-math" } */ + +extern void abort (void); + +double d[1024], e[1024]; +int f[1024], g[1024]; + +double __attribute__((noinline)) +foo (void) +{ + double s = 0.0; + int i; + for (i = 0; i < 1024; i++) + s += d[i] - e[i]; + return s; +} + +int __attribute__((noinline)) +bar (void) +{ + int s = 0, i; + for (i = 0; i < 1024; i++) + s += f[i] - g[i]; + return s; +} + +int +main (void) +{ + int i; + for (i = 0; i < 1024; i++) + { + d[i] = i * 2; + e[i] = i; + f[i] = i * 2; + g[i] = i; + } + if (foo () != 1023 * 1024 / 2) + abort (); + if (bar () != 1023 * 1024 / 2) + abort (); + return 0; +} -- cgit v1.1