diff mbox

Fix PR tree-optimization/51704

Message ID OF4DDDB52A.2BF8E3A1-ONC2257978.00444377-C2257978.004C4498@il.ibm.com
State New
Headers show

Commit Message

Ira Rosen Jan. 1, 2012, 1:53 p.m. UTC
Hi,

This patch adds a check that a statement is inside the loop/basic block
that is being analyzed before accessing its vect info.

Bootstrapped and tested on powerpc64-suse-linux.
Committed.

Ira

ChangeLog:

        PR tree-optimization/51704
        * tree-vect-slp.c (vect_detect_hybrid_slp_stmts): Check that
        a use is inside the basic block or loop before accessing its
        vect info.

testsuite/ChangeLog:

        PR tree-optimization/51704
        * gfortran.dg/vect/no-fre-no-copy-prop-O3-pr51704.f90: New.
        * gfortran.dg/vect/vect.exp: Run no-fre-no-copy-prop-O3-* with
        corresponding flags.

(See attached file: patch.txt)
diff mbox

Patch

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 182767)
+++ ChangeLog	(working copy)
@@ -1,3 +1,10 @@ 
+2012-01-01  Ira Rosen  <irar@il.ibm.com>
+
+	PR tree-optimization/51704
+	* tree-vect-slp.c (vect_detect_hybrid_slp_stmts): Check that
+	a use is inside the basic block or loop before accessing its
+	vect info.
+
 2012-01-01  Jan Hubicka  <jhjh@suse.cz>
 
 	PR rtl-optimization/51069
Index: testsuite/gfortran.dg/vect/no-fre-no-copy-prop-O3-pr51704.f90
===================================================================
--- testsuite/gfortran.dg/vect/no-fre-no-copy-prop-O3-pr51704.f90	(revision 0)
+++ testsuite/gfortran.dg/vect/no-fre-no-copy-prop-O3-pr51704.f90	(revision 0)
@@ -0,0 +1,57 @@ 
+! { dg-do compile }
+
+  integer, parameter :: q = 2
+  integer, parameter :: nx=3, ny=2*q, nz=5
+  integer, parameter, dimension(nx,ny,nz) :: p  = &
+        & reshape ((/ (i**2, i=1,size(p)) /), shape(p))
+  integer, parameter, dimension(   ny,nz) :: px = &
+        & reshape ((/ (( &
+        &       +      nx*(nx-1)*(2*nx-1)/6, &
+        &       j=0,ny-1), k=0,nz-1) /), shape(px))
+  integer, parameter, dimension(nx,   nz) :: py = &
+        & reshape ((/ (( &
+        &       +(nx   )**2*ny*(ny-1)*(2*ny-1)/6, &
+        &       i=0,nx-1), k=0,nz-1) /), shape(py))
+  integer, parameter, dimension(nx,ny   ) :: pz = &
+        & reshape ((/ (( &
+        &       +(nx*ny)**2*nz*(nz-1)*(2*nz-1)/6, &
+        &       i=0,nx-1), j=0,ny-1) /), shape(pz))
+  integer, dimension(nx,ny,nz) :: a
+  integer, dimension(nx,ny   ) :: az
+  if (sum(sum(sum(a,1),2),1) /= sum(a)) call abort
+  if (sum(sum(sum(a,3),1),1) /= sum(a)) call abort
+  if (any(1+sum(eid(a),1)+ax+sum( &
+        neid3(a), &
+        1)+1  /= 3*ax+2))        call abort
+  if (any(1+eid(sum(a,2))+ay+ &
+        neid2( &
+        sum(a,2) &
+        )+1  /= 3*ay+2))        call abort
+  if (any(sum(eid(sum(a,3))+az+2* &
+        neid2(az) &
+        ,1)+1 /= 4*sum(az,1)+1)) call abort
+contains
+  elemental function eid (x)
+    integer, intent(in) :: x
+  end function eid
+  function neid2 (x)
+    integer, intent(in) :: x(:,:)
+    integer             :: neid2(size(x,1),size(x,2))
+    neid2 = x
+  end function neid2
+  function neid3 (x)
+    integer, intent(in) :: x(:,:,:)
+    integer             :: neid3(size(x,1),size(x,2),size(x,3))
+  end function neid3
+  elemental subroutine set (o, i)
+    integer, intent(in)  :: i
+    integer, intent(out) :: o
+  end subroutine set
+  elemental subroutine tes (i, o)
+    integer, intent(in)  :: i
+    integer, intent(out) :: o
+  end subroutine tes
+end
+
+! { dg-final { cleanup-tree-dump "vect" } }
+
Index: testsuite/gfortran.dg/vect/vect.exp
===================================================================
--- testsuite/gfortran.dg/vect/vect.exp	(revision 182767)
+++ testsuite/gfortran.dg/vect/vect.exp	(working copy)
@@ -90,6 +90,12 @@  lappend DEFAULT_VECTCFLAGS "-Ofast"
 dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/Ofast-*.\[fF\]{,90,95,03,08} ]]  \
         "" $DEFAULT_VECTCFLAGS
 
+# With -fno-tree-copy-prop -fno-tree-fre -O3
+set DEFAULT_VECTCFLAGS $SAVED_DEFAULT_VECTCFLAGS
+lappend DEFAULT_VECTCFLAGS "-fno-tree-copy-prop" "-fno-tree-fre" "-O3"
+dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/no-fre-no-copy-prop-O3-*.\[fF\]{,90,95,03,08} ]]  \
+        "" $DEFAULT_VECTCFLAGS
+
 # Clean up.
 set dg-do-what-default ${save-dg-do-what-default}
 
Index: testsuite/ChangeLog
===================================================================
--- testsuite/ChangeLog	(revision 182767)
+++ testsuite/ChangeLog	(working copy)
@@ -1,3 +1,10 @@ 
+2012-01-01  Ira Rosen  <irar@il.ibm.com>
+
+	PR tree-optimization/51704
+	* gfortran.dg/vect/no-fre-no-copy-prop-O3-pr51704.f90: New.
+	* gfortran.dg/vect/vect.exp: Run no-fre-no-copy-prop-O3-* with
+	corresponding flags.
+
 2012-01-01  Jan Hubicka  <jh@suse.cz>
 
 	PR rtl-optimization/51069
Index: tree-vect-slp.c
===================================================================
--- tree-vect-slp.c	(revision 182767)
+++ tree-vect-slp.c	(working copy)
@@ -1,5 +1,5 @@ 
 /* SLP - Basic Block Vectorization
-   Copyright (C) 2007, 2008, 2009, 2010, 2011
+   Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012
    Free Software Foundation, Inc.
    Contributed by Dorit Naishlos <dorit@il.ibm.com>
    and Ira Rosen <irar@il.ibm.com>
@@ -1727,26 +1727,39 @@  static void
 vect_detect_hybrid_slp_stmts (slp_tree node)
 {
   int i;
-  gimple stmt;
+  VEC (gimple, heap) *stmts = SLP_TREE_SCALAR_STMTS (node);
+  gimple stmt = VEC_index (gimple, stmts, 0);
   imm_use_iterator imm_iter;
   gimple use_stmt;
-  stmt_vec_info stmt_vinfo; 
+  stmt_vec_info stmt_vinfo = vinfo_for_stmt (stmt);
   slp_void_p child;
+  loop_vec_info loop_vinfo = STMT_VINFO_LOOP_VINFO (stmt_vinfo);
+  struct loop *loop = NULL;
+  bb_vec_info bb_vinfo = STMT_VINFO_BB_VINFO (stmt_vinfo);
+  basic_block bb = NULL;
 
   if (!node)
     return;
 
+  if (loop_vinfo)
+    loop = LOOP_VINFO_LOOP (loop_vinfo);
+  else
+    bb = BB_VINFO_BB (bb_vinfo);
+
   FOR_EACH_VEC_ELT (gimple, SLP_TREE_SCALAR_STMTS (node), i, stmt)
     if (PURE_SLP_STMT (vinfo_for_stmt (stmt))
 	&& TREE_CODE (gimple_op (stmt, 0)) == SSA_NAME)
       FOR_EACH_IMM_USE_STMT (use_stmt, imm_iter, gimple_op (stmt, 0))
-	if ((stmt_vinfo = vinfo_for_stmt (use_stmt))
+	if (gimple_bb (use_stmt)
+            && ((loop && flow_bb_inside_loop_p (loop, gimple_bb (use_stmt)))
+		 || bb == gimple_bb (use_stmt))
+	    && (stmt_vinfo = vinfo_for_stmt (use_stmt))
 	    && !STMT_SLP_TYPE (stmt_vinfo)
             && (STMT_VINFO_RELEVANT (stmt_vinfo)
                 || VECTORIZABLE_CYCLE_DEF (STMT_VINFO_DEF_TYPE (stmt_vinfo)))
-            && !(gimple_code (use_stmt) == GIMPLE_PHI
-                 && STMT_VINFO_DEF_TYPE (vinfo_for_stmt (use_stmt)) 
-                     == vect_reduction_def))
+	    && !(gimple_code (use_stmt) == GIMPLE_PHI
+                 && STMT_VINFO_DEF_TYPE (stmt_vinfo)
+                  == vect_reduction_def))
 	  vect_mark_slp_stmts (node, hybrid, i);
 
   FOR_EACH_VEC_ELT (slp_void_p, SLP_TREE_CHILDREN (node), i, child)