public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Insert new bound in try_transform_to_exit_first_loop_alt
@ 2015-06-29 14:40 Tom de Vries
  2015-07-09 11:56 ` [PING][PATCH] " Tom de Vries
  0 siblings, 1 reply; 3+ messages in thread
From: Tom de Vries @ 2015-06-29 14:40 UTC (permalink / raw)
  To: Richard Biener; +Cc: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 278 bytes --]

Hi,

this patch allows try_transform_to_exit_first_loop_alt to handle the 
case that the new loop bound nit + 1 is not available as ssa-name n in 
the assignment nit = n - 1, by inserting the new loop bound.

Bootstrapped and reg-tested on x86_64.

OK for trunk?

Thanks,
- Tom

[-- Attachment #2: 0002-Insert-new-bound-in-try_transform_to_exit_first_loop.patch --]
[-- Type: text/x-patch, Size: 6433 bytes --]

Insert new bound in try_transform_to_exit_first_loop_alt

2015-06-29  Tom de Vries  <tom@codesourcery.com>

	* tree-parloops.c (try_transform_to_exit_first_loop_alt): If not found,
	insert nit + 1 bound.

	* testsuite/libgomp.fortran/parloops-exit-first-loop-alt-2.f95: New test.
	* testsuite/libgomp.fortran/parloops-exit-first-loop-alt.f95: New test.

	* gfortran.dg/parloops-exit-first-loop-alt-2.f95: New test.
	* gfortran.dg/parloops-exit-first-loop-alt.f95: New test.
---
 .../gfortran.dg/parloops-exit-first-loop-alt-2.f95 | 24 +++++++++++++
 .../gfortran.dg/parloops-exit-first-loop-alt.f95   | 25 +++++++++++++
 gcc/tree-parloops.c                                | 18 +++++++++-
 .../parloops-exit-first-loop-alt-2.f95             | 40 +++++++++++++++++++++
 .../parloops-exit-first-loop-alt.f95               | 41 ++++++++++++++++++++++
 5 files changed, 147 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gfortran.dg/parloops-exit-first-loop-alt-2.f95
 create mode 100644 gcc/testsuite/gfortran.dg/parloops-exit-first-loop-alt.f95
 create mode 100644 libgomp/testsuite/libgomp.fortran/parloops-exit-first-loop-alt-2.f95
 create mode 100644 libgomp/testsuite/libgomp.fortran/parloops-exit-first-loop-alt.f95

diff --git a/gcc/testsuite/gfortran.dg/parloops-exit-first-loop-alt-2.f95 b/gcc/testsuite/gfortran.dg/parloops-exit-first-loop-alt-2.f95
new file mode 100644
index 0000000..f26a6e3
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/parloops-exit-first-loop-alt-2.f95
@@ -0,0 +1,24 @@
+! { dg-additional-options "-O2" }
+! { dg-require-effective-target pthread }
+! { dg-additional-options "-ftree-parallelize-loops=2" }
+! { dg-additional-options "-fdump-tree-parloops" }
+
+! Constant bound, vector addition.
+
+subroutine foo ()
+  integer, parameter :: n = 1000
+  integer, dimension (0:n-1) :: a, b, c
+  common a, b, c
+  integer :: ii
+
+  do ii = 0, n - 1
+     c(ii) = a(ii) + b(ii) + 25
+  end do
+end subroutine foo
+
+! Three times plus 25:
+! - once in f._loopfn.0
+! - once in the parallel
+! - once in the low iteration count loop
+! Crucially, none for a peeled off last iteration following the parallel.
+! { dg-final { scan-tree-dump-times "(?n) \\+ 25;" 3 "parloops" } }
diff --git a/gcc/testsuite/gfortran.dg/parloops-exit-first-loop-alt.f95 b/gcc/testsuite/gfortran.dg/parloops-exit-first-loop-alt.f95
new file mode 100644
index 0000000..6dc8a38
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/parloops-exit-first-loop-alt.f95
@@ -0,0 +1,25 @@
+! { dg-additional-options "-O2" }
+! { dg-require-effective-target pthread }
+! { dg-additional-options "-ftree-parallelize-loops=2" }
+! { dg-additional-options "-fdump-tree-parloops" }
+
+! Variable bound, vector addition.
+
+subroutine foo (nr)
+  integer, intent(in) :: nr
+  integer, parameter :: n = 1000
+  integer, dimension (0:n-1) :: a, b, c
+  common a, b, c
+  integer :: ii
+
+  do ii = 0, nr - 1
+     c(ii) = a(ii) + b(ii) + 25
+  end do
+end subroutine foo
+
+! Three times plus 25:
+! - once in f._loopfn.0
+! - once in the parallel
+! - once in the low iteration count loop
+! Crucially, none for a peeled off last iteration following the parallel.
+! { dg-final { scan-tree-dump-times "(?n) \\+ 25;" 3 "parloops" } }
diff --git a/gcc/tree-parloops.c b/gcc/tree-parloops.c
index 32d059a..7a07c7d 100644
--- a/gcc/tree-parloops.c
+++ b/gcc/tree-parloops.c
@@ -1840,8 +1840,24 @@ try_transform_to_exit_first_loop_alt (struct loop *loop,
 	alt_bound = op1;
     }
 
+  /* If not found, insert nit + 1.  */
   if (alt_bound == NULL_TREE)
-    return false;
+    {
+      alt_bound = fold_build2 (PLUS_EXPR, nit_type, nit,
+			       build_int_cst_type (nit_type, 1));
+
+      gimple_seq pre = NULL, post = NULL;
+      push_gimplify_context (true);
+      gimplify_expr (&alt_bound, &pre, &post, is_gimple_reg,
+		     fb_rvalue);
+      pop_gimplify_context (NULL);
+
+      gimple_seq_add_seq (&pre, post);
+
+      gimple_stmt_iterator gsi
+	= gsi_last_bb (loop_preheader_edge (loop)->src);
+      gsi_insert_seq_after (&gsi, pre, GSI_CONTINUE_LINKING);
+    }
 
   transform_to_exit_first_loop_alt (loop, reduction_list, alt_bound);
   return true;
diff --git a/libgomp/testsuite/libgomp.fortran/parloops-exit-first-loop-alt-2.f95 b/libgomp/testsuite/libgomp.fortran/parloops-exit-first-loop-alt-2.f95
new file mode 100644
index 0000000..56add65
--- /dev/null
+++ b/libgomp/testsuite/libgomp.fortran/parloops-exit-first-loop-alt-2.f95
@@ -0,0 +1,40 @@
+! { dg-do run }
+! { dg-additional-options "-O2" }
+! { dg-additional-options "-ftree-parallelize-loops=2" }
+
+! Constant bound, vector addition.
+
+subroutine foo ()
+  integer, parameter :: n = 1000
+  integer, dimension (0:n-1) :: a, b, c
+  common a, b, c
+  integer :: ii
+
+  do ii = 0, n - 1
+     c(ii) = a(ii) + b(ii)
+  end do
+end subroutine foo
+
+program main
+  integer, parameter :: n = 1000
+  integer, parameter :: distrib = 10
+  integer, dimension (0:n-1) :: a, b, c
+  common a, b, c
+  integer :: i, j, k
+
+  do j = 0, ((n / distrib) -1)
+     do i = 0, distrib - 1
+	k = i + (distrib * j)
+	a(k) = k
+	b(k) = MODULO ((k * 3), 7)
+	c(k) = k * 2;
+     end do
+  end do
+
+  call foo ()
+
+  do i = 0, n - 1
+     if (c(i) .ne. (i + MODULO ((i * 3), 7))) call abort
+  end do
+
+end program
diff --git a/libgomp/testsuite/libgomp.fortran/parloops-exit-first-loop-alt.f95 b/libgomp/testsuite/libgomp.fortran/parloops-exit-first-loop-alt.f95
new file mode 100644
index 0000000..72b3c8d
--- /dev/null
+++ b/libgomp/testsuite/libgomp.fortran/parloops-exit-first-loop-alt.f95
@@ -0,0 +1,41 @@
+! { dg-do run }
+! { dg-additional-options "-O2" }
+! { dg-additional-options "-ftree-parallelize-loops=2" }
+
+! Variable bound, vector addition.
+
+subroutine foo (nr)
+  integer, intent(in) :: nr
+  integer, parameter :: n = 1000
+  integer, dimension (0:n-1) :: a, b, c
+  common a, b, c
+  integer :: ii
+
+  do ii = 0, nr - 1
+     c(ii) = a(ii) + b(ii)
+  end do
+end subroutine foo
+
+program main
+  integer, parameter :: n = 1000
+  integer, parameter :: distrib = 10
+  integer, dimension (0:n-1) :: a, b, c
+  common a, b, c
+  integer :: i, j, k
+
+  do j = 0, ((n / distrib) -1)
+     do i = 0, distrib - 1
+	k = i + (distrib * j)
+	a(k) = k
+	b(k) = MODULO ((k * 3), 7)
+	c(k) = k * 2;
+     end do
+  end do
+
+  call foo (n)
+
+  do i = 0, n - 1
+     if (c(i) .ne. (i + MODULO ((i * 3), 7))) call abort
+  end do
+
+end program
-- 
1.9.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-07-09 12:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-29 14:40 [PATCH] Insert new bound in try_transform_to_exit_first_loop_alt Tom de Vries
2015-07-09 11:56 ` [PING][PATCH] " Tom de Vries
2015-07-09 12:16   ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).