From 4ccc88e6b3810600b82d519967be74495b6431e1 Mon Sep 17 00:00:00 2001 From: Alexandre Oliva Date: Wed, 27 Jan 2016 05:43:00 -0200 Subject: [PR69466] fix loop vectorizer set_current_def slpeel_duplicate_current_defs_from_edges is often called with edges to blocks that were copied from one another, but it isn't always so. Check that their phi nodes match before calling set_current_def for any of them. for gcc/ChangeLog PR target/69466 * tree-vect-loop-manip.c (slpeel_duplicate_current_defs_from_edges): Skip if dest blocks don't have phi nodes for names for the same base variables. for gcc/testsuite/ChangeLog PR target/69466 * gfortran.dg/vect/pr69466.f90: New. --- gcc/testsuite/gfortran.dg/vect/pr69466.f90 | 42 ++++++++++++++++++++++++++++++ gcc/tree-vect-loop-manip.c | 16 ++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/vect/pr69466.f90 diff --git a/gcc/testsuite/gfortran.dg/vect/pr69466.f90 b/gcc/testsuite/gfortran.dg/vect/pr69466.f90 new file mode 100644 index 00000000000..a01950f1ac8 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/vect/pr69466.f90 @@ -0,0 +1,42 @@ +! { dg-do compile } +! { dg-additional-options "-march=core-avx2" { target x86_64-*-* i?86-*-* } } + + subroutine foo + + integer :: a, b, c, d, e + + integer, dimension(:), allocatable :: f, g, h + + call zoo (a) + call zoo (b) + call zoo (c) + + if(a == b) then + allocate(g(0:d-1), h(0:d-1)) + else + allocate(g(1), h(1)) + if (b /= 0) then + call zoo(b) + endif + endif + + if(a == b) then + do d=0,c-1 + e = e + g(d) + if(d == 0) then + h(d) = 0 + else + h(d) = h(d-1) + g(d-1) + endif + end do + endif + + if(a == b) then + allocate(f(e), g(e)) + endif + + if(a == 0) then + call boo(e) + endif + + end subroutine foo diff --git a/gcc/tree-vect-loop-manip.c b/gcc/tree-vect-loop-manip.c index f9fdf013e10..35c5435b76e 100644 --- a/gcc/tree-vect-loop-manip.c +++ b/gcc/tree-vect-loop-manip.c @@ -725,6 +725,22 @@ slpeel_duplicate_current_defs_from_edges (edge from, edge to) { gimple_stmt_iterator gsi_from, gsi_to; + /* Check that we're looking at two blocks with analogous PHI + nodes before changing anything. */ + for (gsi_from = gsi_start_phis (from->dest), + gsi_to = gsi_start_phis (to->dest); + !gsi_end_p (gsi_from) && !gsi_end_p (gsi_to); + gsi_next (&gsi_from), gsi_next (&gsi_to)) + { + gimple *from_phi = gsi_stmt (gsi_from); + gimple *to_phi = gsi_stmt (gsi_to); + if (SSA_NAME_VAR (PHI_RESULT (from_phi)) + != SSA_NAME_VAR (PHI_RESULT (to_phi))) + return; + } + if (gsi_end_p (gsi_from) != gsi_end_p (gsi_to)) + return; + for (gsi_from = gsi_start_phis (from->dest), gsi_to = gsi_start_phis (to->dest); !gsi_end_p (gsi_from) && !gsi_end_p (gsi_to); -- cgit v1.2.1