aboutsummaryrefslogtreecommitdiff
path: root/libgomp
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2006-12-04 11:26:00 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2006-12-04 11:26:00 +0100
commit22568cc62cabbea1eec20ef65e1da9b0caaa6f02 (patch)
treef94786a4fcf50b6049962a9a01cc79e07e724e65 /libgomp
parentd3c673c74acfcc0202b0013677ef280e76fffb72 (diff)
downloadgcc-22568cc62cabbea1eec20ef65e1da9b0caaa6f02.zip
gcc-22568cc62cabbea1eec20ef65e1da9b0caaa6f02.tar.gz
gcc-22568cc62cabbea1eec20ef65e1da9b0caaa6f02.tar.bz2
re PR middle-end/29947 (OpenMP parallel for fails for reversed loop range)
PR libgomp/29947 * omp-low.c (expand_omp_for_static_nochunk, expand_omp_for_static_chunk): Do all arithmetics in signed rather than unsigned type. * loop.c (gomp_loop_init): Make parameters signed. Set ws->end to start if there shouldn't be any loop iterations. (gomp_loop_ordered_static_start): Remove start == end test. * testsuite/libgomp.c/pr29947-1.c: New test. * testsuite/libgomp.c/pr29947-2.c: New test. From-SVN: r119485
Diffstat (limited to 'libgomp')
-rw-r--r--libgomp/ChangeLog9
-rw-r--r--libgomp/loop.c12
-rw-r--r--libgomp/testsuite/libgomp.c/pr29947-1.c328
-rw-r--r--libgomp/testsuite/libgomp.c/pr29947-2.c328
4 files changed, 670 insertions, 7 deletions
diff --git a/libgomp/ChangeLog b/libgomp/ChangeLog
index 7b19325..7d6cce6 100644
--- a/libgomp/ChangeLog
+++ b/libgomp/ChangeLog
@@ -1,3 +1,12 @@
+2006-12-04 Jakub Jelinek <jakub@redhat.com>
+
+ PR libgomp/29947
+ * loop.c (gomp_loop_init): Make parameters signed. Set ws->end to
+ start if there shouldn't be any loop iterations.
+ (gomp_loop_ordered_static_start): Remove start == end test.
+ * testsuite/libgomp.c/pr29947-1.c: New test.
+ * testsuite/libgomp.c/pr29947-2.c: New test.
+
2006-12-02 Eric Botcazou <ebotcazou@libertysurf.fr>
* configure.tgt: Force initial-exec TLS model on Linux only.
diff --git a/libgomp/loop.c b/libgomp/loop.c
index 3d1b1ef..58fd9a8 100644
--- a/libgomp/loop.c
+++ b/libgomp/loop.c
@@ -34,13 +34,14 @@
/* Initialize the given work share construct from the given arguments. */
static inline void
-gomp_loop_init (struct gomp_work_share *ws, unsigned long start,
- unsigned long end, unsigned long incr,
- enum gomp_schedule_type sched, unsigned long chunk_size)
+gomp_loop_init (struct gomp_work_share *ws, long start, long end, long incr,
+ enum gomp_schedule_type sched, long chunk_size)
{
ws->sched = sched;
ws->chunk_size = chunk_size;
- ws->end = end;
+ /* Canonicalize loops that have zero iterations to ->next == ->end. */
+ ws->end = ((incr > 0 && start > end) || (incr < 0 && start < end))
+ ? start : end;
ws->incr = incr;
ws->next = start;
}
@@ -148,9 +149,6 @@ gomp_loop_ordered_static_start (long start, long end, long incr,
{
struct gomp_thread *thr = gomp_thread ();
- if (start == end)
- return false;
-
if (gomp_work_share_start (true))
{
gomp_loop_init (thr->ts.work_share, start, end, incr,
diff --git a/libgomp/testsuite/libgomp.c/pr29947-1.c b/libgomp/testsuite/libgomp.c/pr29947-1.c
new file mode 100644
index 0000000..78b40ac
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c/pr29947-1.c
@@ -0,0 +1,328 @@
+/* PR libgomp/29947 */
+/* { dg-options "-O2 -fopenmp" } */
+/* { dg-do run } */
+
+extern void abort (void);
+
+int cnt;
+
+void
+test1 (long j1, long k1, long j2, long k2)
+{
+ long i, e = 0, c = 0;
+#pragma omp parallel reduction (+:e,c)
+ {
+#pragma omp for schedule (dynamic)
+ for (i = j1; i <= k1; ++i)
+ {
+ if (i < j2 || i > k2)
+ ++e;
+ ++c;
+ }
+#pragma omp atomic
+ ++cnt;
+ }
+ if (e || (c != j2 > k2 ? 0 : k2 - j2 + 1))
+ abort ();
+}
+
+void
+test2 (long j1, long k1, long j2, long k2)
+{
+ long i, e = 0, c = 0;
+#pragma omp parallel reduction (+:e,c)
+ {
+#pragma omp for schedule (dynamic)
+ for (i = k1; i >= j1; --i)
+ {
+ if (i < j2 || i > k2)
+ ++e;
+ ++c;
+ }
+#pragma omp atomic
+ ++cnt;
+ }
+ if (e || (c != j2 > k2 ? 0 : k2 - j2 + 1))
+ abort ();
+}
+
+void
+test3 (long j1, long k1, long j2, long k2)
+{
+ long i, e = 0, c = 0;
+#pragma omp parallel reduction (+:e,c)
+ {
+#pragma omp for schedule (guided)
+ for (i = j1; i <= k1; ++i)
+ {
+ if (i < j2 || i > k2)
+ ++e;
+ ++c;
+ }
+#pragma omp atomic
+ ++cnt;
+ }
+ if (e || (c != j2 > k2 ? 0 : k2 - j2 + 1))
+ abort ();
+}
+
+void
+test4 (long j1, long k1, long j2, long k2)
+{
+ long i, e = 0, c = 0;
+#pragma omp parallel reduction (+:e,c)
+ {
+#pragma omp for schedule (guided)
+ for (i = k1; i >= j1; --i)
+ {
+ if (i < j2 || i > k2)
+ ++e;
+ ++c;
+ }
+#pragma omp atomic
+ ++cnt;
+ }
+ if (e || (c != j2 > k2 ? 0 : k2 - j2 + 1))
+ abort ();
+}
+
+void
+test5 (long j1, long k1, long j2, long k2)
+{
+ long i, e = 0, c = 0;
+#pragma omp parallel reduction (+:e,c)
+ {
+#pragma omp for schedule (dynamic) ordered
+ for (i = j1; i <= k1; ++i)
+ {
+ if (i < j2 || i > k2)
+ ++e;
+#pragma omp ordered
+ ++c;
+ }
+#pragma omp atomic
+ ++cnt;
+ }
+ if (e || (c != j2 > k2 ? 0 : k2 - j2 + 1))
+ abort ();
+}
+
+void
+test6 (long j1, long k1, long j2, long k2)
+{
+ long i, e = 0, c = 0;
+#pragma omp parallel reduction (+:e,c)
+ {
+#pragma omp for schedule (dynamic) ordered
+ for (i = k1; i >= j1; --i)
+ {
+ if (i < j2 || i > k2)
+ ++e;
+#pragma omp ordered
+ ++c;
+ }
+#pragma omp atomic
+ ++cnt;
+ }
+ if (e || (c != j2 > k2 ? 0 : k2 - j2 + 1))
+ abort ();
+}
+
+void
+test7 (long j1, long k1, long j2, long k2)
+{
+ long i, e = 0, c = 0;
+#pragma omp parallel reduction (+:e,c)
+ {
+#pragma omp for schedule (guided) ordered
+ for (i = j1; i <= k1; ++i)
+ {
+ if (i < j2 || i > k2)
+ ++e;
+#pragma omp ordered
+ ++c;
+ }
+#pragma omp atomic
+ ++cnt;
+ }
+ if (e || (c != j2 > k2 ? 0 : k2 - j2 + 1))
+ abort ();
+}
+
+void
+test8 (long j1, long k1, long j2, long k2)
+{
+ long i, e = 0, c = 0;
+#pragma omp parallel reduction (+:e,c)
+ {
+#pragma omp for schedule (guided) ordered
+ for (i = k1; i >= j1; --i)
+ {
+ if (i < j2 || i > k2)
+ ++e;
+#pragma omp ordered
+ ++c;
+ }
+#pragma omp atomic
+ ++cnt;
+ }
+ if (e || (c != j2 > k2 ? 0 : k2 - j2 + 1))
+ abort ();
+}
+
+void
+test9 (long j1, long k1, long j2, long k2)
+{
+ long i, e = 0, c = 0;
+#pragma omp parallel for reduction (+:e,c) schedule (dynamic)
+ for (i = j1; i <= k1; ++i)
+ {
+ if (i < j2 || i > k2)
+ ++e;
+ ++c;
+ }
+ if (e || (c != j2 > k2 ? 0 : k2 - j2 + 1))
+ abort ();
+}
+
+void
+test10 (long j1, long k1, long j2, long k2)
+{
+ long i, e = 0, c = 0;
+#pragma omp parallel for reduction (+:e,c) schedule (dynamic)
+ for (i = k1; i >= j1; --i)
+ {
+ if (i < j2 || i > k2)
+ ++e;
+ ++c;
+ }
+ if (e || (c != j2 > k2 ? 0 : k2 - j2 + 1))
+ abort ();
+}
+
+void
+test11 (long j1, long k1, long j2, long k2)
+{
+ long i, e = 0, c = 0;
+#pragma omp parallel for reduction (+:e,c) schedule (guided)
+ for (i = j1; i <= k1; ++i)
+ {
+ if (i < j2 || i > k2)
+ ++e;
+ ++c;
+ }
+ if (e || (c != j2 > k2 ? 0 : k2 - j2 + 1))
+ abort ();
+}
+
+void
+test12 (long j1, long k1, long j2, long k2)
+{
+ long i, e = 0, c = 0;
+#pragma omp parallel for reduction (+:e,c) schedule (guided)
+ for (i = k1; i >= j1; --i)
+ {
+ if (i < j2 || i > k2)
+ ++e;
+ ++c;
+ }
+ if (e || (c != j2 > k2 ? 0 : k2 - j2 + 1))
+ abort ();
+}
+
+void
+test13 (long j1, long k1, long j2, long k2)
+{
+ long i, e = 0, c = 0;
+#pragma omp parallel for reduction (+:e,c) schedule (dynamic) ordered
+ for (i = j1; i <= k1; ++i)
+ {
+ if (i < j2 || i > k2)
+ ++e;
+#pragma omp ordered
+ ++c;
+ }
+ if (e || (c != j2 > k2 ? 0 : k2 - j2 + 1))
+ abort ();
+}
+
+void
+test14 (long j1, long k1, long j2, long k2)
+{
+ long i, e = 0, c = 0;
+#pragma omp parallel for reduction (+:e,c) schedule (dynamic) ordered
+ for (i = k1; i >= j1; --i)
+ {
+ if (i < j2 || i > k2)
+ ++e;
+#pragma omp ordered
+ ++c;
+ }
+ if (e || (c != j2 > k2 ? 0 : k2 - j2 + 1))
+ abort ();
+}
+
+void
+test15 (long j1, long k1, long j2, long k2)
+{
+ long i, e = 0, c = 0;
+#pragma omp parallel for reduction (+:e,c) schedule (guided) ordered
+ for (i = j1; i <= k1; ++i)
+ {
+ if (i < j2 || i > k2)
+ ++e;
+#pragma omp ordered
+ ++c;
+ }
+ if (e || (c != j2 > k2 ? 0 : k2 - j2 + 1))
+ abort ();
+}
+
+void
+test16 (long j1, long k1, long j2, long k2)
+{
+ long i, e = 0, c = 0;
+#pragma omp parallel for reduction (+:e,c) schedule (guided) ordered
+ for (i = k1; i >= j1; --i)
+ {
+ if (i < j2 || i > k2)
+ ++e;
+#pragma omp ordered
+ ++c;
+ }
+ if (e || (c != j2 > k2 ? 0 : k2 - j2 + 1))
+ abort ();
+}
+
+int
+__attribute__((noinline))
+test (long j1, long k1, long j2, long k2)
+{
+ test1 (j1, k1, j2, k2);
+ test2 (j1, k1, j2, k2);
+ test3 (j1, k1, j2, k2);
+ test4 (j1, k1, j2, k2);
+ test5 (j1, k1, j2, k2);
+ test6 (j1, k1, j2, k2);
+ test7 (j1, k1, j2, k2);
+ test8 (j1, k1, j2, k2);
+ test9 (j1, k1, j2, k2);
+ test10 (j1, k1, j2, k2);
+ test11 (j1, k1, j2, k2);
+ test12 (j1, k1, j2, k2);
+ test13 (j1, k1, j2, k2);
+ test14 (j1, k1, j2, k2);
+ test15 (j1, k1, j2, k2);
+ test16 (j1, k1, j2, k2);
+ return cnt;
+}
+
+int
+main (void)
+{
+ test (1, 5, 1, 5);
+ test (5, 5, 5, 5);
+ test (5, 4, 5, 4);
+ test (5, 1, 5, 1);
+ return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c/pr29947-2.c b/libgomp/testsuite/libgomp.c/pr29947-2.c
new file mode 100644
index 0000000..231cd5d
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c/pr29947-2.c
@@ -0,0 +1,328 @@
+/* PR libgomp/29947 */
+/* { dg-options "-O2 -fopenmp" } */
+/* { dg-do run } */
+
+extern void abort (void);
+
+int cnt;
+
+void
+test1 (long j1, long k1, long j2, long k2)
+{
+ long i, e = 0, c = 0;
+#pragma omp parallel reduction (+:e,c)
+ {
+#pragma omp for schedule (static)
+ for (i = j1; i <= k1; ++i)
+ {
+ if (i < j2 || i > k2)
+ ++e;
+ ++c;
+ }
+#pragma omp atomic
+ ++cnt;
+ }
+ if (e || (c != j2 > k2 ? 0 : k2 - j2 + 1))
+ abort ();
+}
+
+void
+test2 (long j1, long k1, long j2, long k2)
+{
+ long i, e = 0, c = 0;
+#pragma omp parallel reduction (+:e,c)
+ {
+#pragma omp for schedule (static)
+ for (i = k1; i >= j1; --i)
+ {
+ if (i < j2 || i > k2)
+ ++e;
+ ++c;
+ }
+#pragma omp atomic
+ ++cnt;
+ }
+ if (e || (c != j2 > k2 ? 0 : k2 - j2 + 1))
+ abort ();
+}
+
+void
+test3 (long j1, long k1, long j2, long k2)
+{
+ long i, e = 0, c = 0;
+#pragma omp parallel reduction (+:e,c)
+ {
+#pragma omp for schedule (static, 1)
+ for (i = j1; i <= k1; ++i)
+ {
+ if (i < j2 || i > k2)
+ ++e;
+ ++c;
+ }
+#pragma omp atomic
+ ++cnt;
+ }
+ if (e || (c != j2 > k2 ? 0 : k2 - j2 + 1))
+ abort ();
+}
+
+void
+test4 (long j1, long k1, long j2, long k2)
+{
+ long i, e = 0, c = 0;
+#pragma omp parallel reduction (+:e,c)
+ {
+#pragma omp for schedule (static, 1)
+ for (i = k1; i >= j1; --i)
+ {
+ if (i < j2 || i > k2)
+ ++e;
+ ++c;
+ }
+#pragma omp atomic
+ ++cnt;
+ }
+ if (e || (c != j2 > k2 ? 0 : k2 - j2 + 1))
+ abort ();
+}
+
+void
+test5 (long j1, long k1, long j2, long k2)
+{
+ long i, e = 0, c = 0;
+#pragma omp parallel reduction (+:e,c)
+ {
+#pragma omp for schedule (static) ordered
+ for (i = j1; i <= k1; ++i)
+ {
+ if (i < j2 || i > k2)
+ ++e;
+#pragma omp ordered
+ ++c;
+ }
+#pragma omp atomic
+ ++cnt;
+ }
+ if (e || (c != j2 > k2 ? 0 : k2 - j2 + 1))
+ abort ();
+}
+
+void
+test6 (long j1, long k1, long j2, long k2)
+{
+ long i, e = 0, c = 0;
+#pragma omp parallel reduction (+:e,c)
+ {
+#pragma omp for schedule (static) ordered
+ for (i = k1; i >= j1; --i)
+ {
+ if (i < j2 || i > k2)
+ ++e;
+#pragma omp ordered
+ ++c;
+ }
+#pragma omp atomic
+ ++cnt;
+ }
+ if (e || (c != j2 > k2 ? 0 : k2 - j2 + 1))
+ abort ();
+}
+
+void
+test7 (long j1, long k1, long j2, long k2)
+{
+ long i, e = 0, c = 0;
+#pragma omp parallel reduction (+:e,c)
+ {
+#pragma omp for schedule (static, 1) ordered
+ for (i = j1; i <= k1; ++i)
+ {
+ if (i < j2 || i > k2)
+ ++e;
+#pragma omp ordered
+ ++c;
+ }
+#pragma omp atomic
+ ++cnt;
+ }
+ if (e || (c != j2 > k2 ? 0 : k2 - j2 + 1))
+ abort ();
+}
+
+void
+test8 (long j1, long k1, long j2, long k2)
+{
+ long i, e = 0, c = 0;
+#pragma omp parallel reduction (+:e,c)
+ {
+#pragma omp for schedule (static, 1) ordered
+ for (i = k1; i >= j1; --i)
+ {
+ if (i < j2 || i > k2)
+ ++e;
+#pragma omp ordered
+ ++c;
+ }
+#pragma omp atomic
+ ++cnt;
+ }
+ if (e || (c != j2 > k2 ? 0 : k2 - j2 + 1))
+ abort ();
+}
+
+void
+test9 (long j1, long k1, long j2, long k2)
+{
+ long i, e = 0, c = 0;
+#pragma omp parallel for reduction (+:e,c) schedule (static)
+ for (i = j1; i <= k1; ++i)
+ {
+ if (i < j2 || i > k2)
+ ++e;
+ ++c;
+ }
+ if (e || (c != j2 > k2 ? 0 : k2 - j2 + 1))
+ abort ();
+}
+
+void
+test10 (long j1, long k1, long j2, long k2)
+{
+ long i, e = 0, c = 0;
+#pragma omp parallel for reduction (+:e,c) schedule (static)
+ for (i = k1; i >= j1; --i)
+ {
+ if (i < j2 || i > k2)
+ ++e;
+ ++c;
+ }
+ if (e || (c != j2 > k2 ? 0 : k2 - j2 + 1))
+ abort ();
+}
+
+void
+test11 (long j1, long k1, long j2, long k2)
+{
+ long i, e = 0, c = 0;
+#pragma omp parallel for reduction (+:e,c) schedule (static, 1)
+ for (i = j1; i <= k1; ++i)
+ {
+ if (i < j2 || i > k2)
+ ++e;
+ ++c;
+ }
+ if (e || (c != j2 > k2 ? 0 : k2 - j2 + 1))
+ abort ();
+}
+
+void
+test12 (long j1, long k1, long j2, long k2)
+{
+ long i, e = 0, c = 0;
+#pragma omp parallel for reduction (+:e,c) schedule (static, 1)
+ for (i = k1; i >= j1; --i)
+ {
+ if (i < j2 || i > k2)
+ ++e;
+ ++c;
+ }
+ if (e || (c != j2 > k2 ? 0 : k2 - j2 + 1))
+ abort ();
+}
+
+void
+test13 (long j1, long k1, long j2, long k2)
+{
+ long i, e = 0, c = 0;
+#pragma omp parallel for reduction (+:e,c) schedule (static) ordered
+ for (i = j1; i <= k1; ++i)
+ {
+ if (i < j2 || i > k2)
+ ++e;
+#pragma omp ordered
+ ++c;
+ }
+ if (e || (c != j2 > k2 ? 0 : k2 - j2 + 1))
+ abort ();
+}
+
+void
+test14 (long j1, long k1, long j2, long k2)
+{
+ long i, e = 0, c = 0;
+#pragma omp parallel for reduction (+:e,c) schedule (static) ordered
+ for (i = k1; i >= j1; --i)
+ {
+ if (i < j2 || i > k2)
+ ++e;
+#pragma omp ordered
+ ++c;
+ }
+ if (e || (c != j2 > k2 ? 0 : k2 - j2 + 1))
+ abort ();
+}
+
+void
+test15 (long j1, long k1, long j2, long k2)
+{
+ long i, e = 0, c = 0;
+#pragma omp parallel for reduction (+:e,c) schedule (static, 1) ordered
+ for (i = j1; i <= k1; ++i)
+ {
+ if (i < j2 || i > k2)
+ ++e;
+#pragma omp ordered
+ ++c;
+ }
+ if (e || (c != j2 > k2 ? 0 : k2 - j2 + 1))
+ abort ();
+}
+
+void
+test16 (long j1, long k1, long j2, long k2)
+{
+ long i, e = 0, c = 0;
+#pragma omp parallel for reduction (+:e,c) schedule (static, 1) ordered
+ for (i = k1; i >= j1; --i)
+ {
+ if (i < j2 || i > k2)
+ ++e;
+#pragma omp ordered
+ ++c;
+ }
+ if (e || (c != j2 > k2 ? 0 : k2 - j2 + 1))
+ abort ();
+}
+
+int
+__attribute__((noinline))
+test (long j1, long k1, long j2, long k2)
+{
+ test1 (j1, k1, j2, k2);
+ test2 (j1, k1, j2, k2);
+ test3 (j1, k1, j2, k2);
+ test4 (j1, k1, j2, k2);
+ test5 (j1, k1, j2, k2);
+ test6 (j1, k1, j2, k2);
+ test7 (j1, k1, j2, k2);
+ test8 (j1, k1, j2, k2);
+ test9 (j1, k1, j2, k2);
+ test10 (j1, k1, j2, k2);
+ test11 (j1, k1, j2, k2);
+ test12 (j1, k1, j2, k2);
+ test13 (j1, k1, j2, k2);
+ test14 (j1, k1, j2, k2);
+ test15 (j1, k1, j2, k2);
+ test16 (j1, k1, j2, k2);
+ return cnt;
+}
+
+int
+main (void)
+{
+ test (1, 5, 1, 5);
+ test (5, 5, 5, 5);
+ test (5, 4, 5, 4);
+ test (5, 1, 5, 1);
+ return 0;
+}