This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[gomp] Limit the empty parallel optimization to -O+ and only when no COPYIN clauses are present
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Richard Henderson <rth at redhat dot com>, Diego Novillo <dnovillo at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Mon, 7 Nov 2005 12:39:30 -0500
- Subject: [gomp] Limit the empty parallel optimization to -O+ and only when no COPYIN clauses are present
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
I think we shouldn't be doing so big transformations at -O0.
Optimized out parallel will be very visible in the debugger.
Also, as Richard pointed out, I think we should preserve COPYIN
clause effects that are documented to be visible in the next
parallel assuming conditions are met.
Ok for gomp?
2005-11-07 Jakub Jelinek <jakub@redhat.com>
* omp-low.c (scan_omp_parallel): Only optimize empty
parallels if optimize > 0 and only when they don't contain
COPYIN clauses.
testsuite/
* gcc.dg/gomp/empty.c: Add -O to dg-options.
libgomp/
* testsuite/libgomp.dg/copyin-3.c: New test.
--- gcc/omp-low.c.jj 2005-11-07 08:48:17.000000000 +0100
+++ gcc/omp-low.c 2005-11-07 17:32:05.000000000 +0100
@@ -832,8 +832,11 @@ scan_omp_parallel (tree *stmt_p, omp_con
omp_context *ctx;
tree name;
- /* Ignore parallel directives with empty bodies. */
- if (empty_body_p (OMP_PARALLEL_BODY (*stmt_p)))
+ /* Ignore parallel directives with empty bodies, unless there
+ are copyin clauses. */
+ if (optimize > 0
+ && empty_body_p (OMP_PARALLEL_BODY (*stmt_p))
+ && find_omp_clause (OMP_CLAUSES (*stmt_p), OMP_CLAUSE_COPYIN) == NULL)
{
*stmt_p = build_empty_stmt ();
return;
--- gcc/testsuite/gcc.dg/gomp/empty.c.jj 2005-11-01 19:57:11.000000000 +0100
+++ gcc/testsuite/gcc.dg/gomp/empty.c 2005-11-07 18:15:07.000000000 +0100
@@ -1,5 +1,5 @@
/* { dg-do compile } */
-/* { dg-options "-fopenmp -fdump-tree-omplower" } */
+/* { dg-options "-O -fopenmp -fdump-tree-omplower" } */
main()
{
--- libgomp/testsuite/libgomp.dg/copyin-3.c.jj 2005-11-07 17:27:49.000000000 +0100
+++ libgomp/testsuite/libgomp.dg/copyin-3.c 2005-11-07 17:31:07.000000000 +0100
@@ -0,0 +1,41 @@
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+#include <omp.h>
+#include <stdlib.h>
+
+int thr;
+#pragma omp threadprivate (thr)
+
+int
+test (int l)
+{
+ return l || (thr != omp_get_thread_num () * 2);
+}
+
+int
+main (void)
+{
+ int l = 0;
+
+ omp_set_dynamic (0);
+ omp_set_num_threads (6);
+
+ thr = 8;
+ /* Broadcast the value to all threads. */
+#pragma omp parallel copyin (thr)
+ ;
+
+#pragma omp parallel reduction (||:l)
+ {
+ /* Now test if the broadcast succeeded. */
+ l = thr != 8;
+ thr = omp_get_thread_num () * 2;
+#pragma omp barrier
+ l = test (l);
+ }
+
+ if (l)
+ abort ();
+ return 0;
+}
Jakub