Optimize expand_omp_for_static_chunk for chunk_size one
authorTom de Vries <tom@codesourcery.com>
Mon, 24 Aug 2015 13:14:17 +0000 (13:14 +0000)
committerTom de Vries <vries@gcc.gnu.org>
Mon, 24 Aug 2015 13:14:17 +0000 (13:14 +0000)
2015-08-24  Tom de Vries  <tom@codesourcery.com>

PR tree-optimization/65468
* omp-low.c (expand_omp_for_static_chunk): Remove inner loop if
chunk_size is one.

* gcc.dg/gomp/static-chunk-size-one.c: New test.

* testsuite/libgomp.c/static-chunk-size-one.c: New test.

From-SVN: r227124

gcc/ChangeLog
gcc/omp-low.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/gomp/static-chunk-size-one.c [new file with mode: 0644]
libgomp/ChangeLog
libgomp/testsuite/libgomp.c/static-chunk-size-one.c [new file with mode: 0644]

index 7d25402cb228082aff25285a8bb4596a321a0a93..d1a9e3a5b13c9e5f47ec26bda3d81f41b59bd18c 100644 (file)
@@ -1,3 +1,9 @@
+2015-08-24  Tom de Vries  <tom@codesourcery.com>
+
+       PR tree-optimization/65468
+       * omp-low.c (expand_omp_for_static_chunk): Remove inner loop if
+       chunk_size is one.
+
 2015-08-24  Nathan Sidwell  <nathan@acm.org>
 
        * config/nvptx/nvptx.c (walk_args_for_param): Revert previous
index d181101d6cf4355ed7512351397158eee117bd9c..19f34ec4f07e0991cfe82b17fb0593506834ffba 100644 (file)
@@ -7204,9 +7204,14 @@ expand_omp_for_static_chunk (struct omp_region *region,
          assign_stmt = gimple_build_assign (vback, t);
          gsi_insert_before (&gsi, assign_stmt, GSI_SAME_STMT);
 
-         t = build2 (fd->loop.cond_code, boolean_type_node,
-                     DECL_P (vback) && TREE_ADDRESSABLE (vback)
-                     ? t : vback, e);
+         if (tree_int_cst_equal (fd->chunk_size, integer_one_node))
+           t = build2 (EQ_EXPR, boolean_type_node,
+                       build_int_cst (itype, 0),
+                       build_int_cst (itype, 1));
+         else
+           t = build2 (fd->loop.cond_code, boolean_type_node,
+                       DECL_P (vback) && TREE_ADDRESSABLE (vback)
+                       ? t : vback, e);
          gsi_insert_before (&gsi, gimple_build_cond_empty (t), GSI_SAME_STMT);
        }
 
index 6235844f53482e4ec06bed412de549a030784ecd..36fc88ffa9a00399da40b8b42019b561127d6ff1 100644 (file)
@@ -1,3 +1,8 @@
+2015-08-24  Tom de Vries  <tom@codesourcery.com>
+
+       PR tree-optimization/65468
+       * gcc.dg/gomp/static-chunk-size-one.c: New test.
+
 2015-08-23  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
 
        PR libfortran/54572
diff --git a/gcc/testsuite/gcc.dg/gomp/static-chunk-size-one.c b/gcc/testsuite/gcc.dg/gomp/static-chunk-size-one.c
new file mode 100644 (file)
index 0000000..e82de77
--- /dev/null
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-fopenmp -O2 -fdump-tree-optimized -fno-tree-pre" } */
+
+int
+bar ()
+{
+  int a = 0, i;
+
+#pragma omp parallel for num_threads (3) reduction (+:a) schedule(static, 1)
+  for (i = 0; i < 10; i++)
+    a += i;
+
+  return a;
+}
+
+/* Two phis for reduction, one in loop header, one in loop exit.  One phi for iv
+   in loop header.  */
+/* { dg-final { scan-tree-dump-times "PHI" 3 "optimized" } } */
index bd9111b86a9d1d6c4a0cdd504b13435e2e16101f..43aaa524c2aaaddaae21063215c7b9b8ce9919c3 100644 (file)
@@ -1,3 +1,8 @@
+2015-08-24  Tom de Vries  <tom@codesourcery.com>
+
+       PR tree-optimization/65468
+       * testsuite/libgomp.c/static-chunk-size-one.c: New test.
+
 2015-08-24  Joost VandeVondele  <vondele@gnu.gcc.org>
 
        PR libgomp/66761
diff --git a/libgomp/testsuite/libgomp.c/static-chunk-size-one.c b/libgomp/testsuite/libgomp.c/static-chunk-size-one.c
new file mode 100644 (file)
index 0000000..9ed7b83
--- /dev/null
@@ -0,0 +1,23 @@
+extern void abort ();
+
+int
+bar ()
+{
+  int a = 0, i;
+
+#pragma omp parallel for num_threads (3) reduction (+:a) schedule(static, 1)
+  for (i = 0; i < 10; i++)
+    a += i;
+
+  return a;
+}
+
+int
+main (void)
+{
+  int res;
+  res = bar ();
+  if (res != 45)
+    abort ();
+  return 0;
+}