From: Tom de Vries Date: Fri, 10 Jul 2015 08:25:18 +0000 (+0000) Subject: Insert new bound in try_transform_to_exit_first_loop_alt X-Git-Tag: upstream/12.2.0~53618 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9f620bf1eaa3b4a0c0419d0245184b50d871dd3b;p=platform%2Fupstream%2Fgcc.git Insert new bound in try_transform_to_exit_first_loop_alt 2015-07-10 Tom de Vries * 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. From-SVN: r225655 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 20a1301..91bf101 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2015-07-10 Tom de Vries + + * tree-parloops.c (try_transform_to_exit_first_loop_alt): If not found, + insert nit + 1 bound. + 2015-07-10 Richard Biener * tree-if-conv.c (if_convertible_gimple_assign_stmt_p): diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 30717ce..59e446c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-07-10 Tom de Vries + + * gfortran.dg/parloops-exit-first-loop-alt-2.f95: New test. + * gfortran.dg/parloops-exit-first-loop-alt.f95: New test. + 2015-07-10 Richard Biener PR tree-optimization/66823 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 846077a..bda5d05 100644 --- a/gcc/tree-parloops.c +++ b/gcc/tree-parloops.c @@ -1828,8 +1828,18 @@ 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_stmt_iterator gsi = gsi_last_bb (loop_preheader_edge (loop)->src); + + alt_bound + = force_gimple_operand_gsi (&gsi, alt_bound, true, NULL_TREE, false, + GSI_CONTINUE_LINKING); + } transform_to_exit_first_loop_alt (loop, reduction_list, alt_bound); return true; diff --git a/libgomp/ChangeLog b/libgomp/ChangeLog index 34f3a1c..ff1fd17 100644 --- a/libgomp/ChangeLog +++ b/libgomp/ChangeLog @@ -1,3 +1,8 @@ +2015-07-10 Tom de Vries + + * testsuite/libgomp.fortran/parloops-exit-first-loop-alt-2.f95: New test. + * testsuite/libgomp.fortran/parloops-exit-first-loop-alt.f95: New test. + 2015-07-08 Thomas Schwinge PR libgomp/65099 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