tree-optimization/97500 - avoid SLP backedges for inductions
authorRichard Biener <rguenther@suse.de>
Wed, 21 Oct 2020 08:54:54 +0000 (10:54 +0200)
committerRichard Biener <rguenther@suse.de>
Wed, 21 Oct 2020 09:43:06 +0000 (11:43 +0200)
Inductions are not vectorized as cycle but materialized from SCEV data.
Filling in backedge SLP nodes confuses this process.

2020-10-21  Richard Biener  <rguenther@suse.de>

PR tree-optimization/97500
* tree-vect-slp.c (vect_analyze_slp_backedges): Do not
fill backedges for inductions.

* gfortran.dg/pr97500.f90: New testcase.

gcc/testsuite/gfortran.dg/pr97500.f90 [new file with mode: 0644]
gcc/tree-vect-slp.c

diff --git a/gcc/testsuite/gfortran.dg/pr97500.f90 b/gcc/testsuite/gfortran.dg/pr97500.f90
new file mode 100644 (file)
index 0000000..d63b861
--- /dev/null
@@ -0,0 +1,35 @@
+! { dg-do run }
+! { dg-additional-options "-ftree-vectorize -fno-guess-branch-probability" }
+module testmod
+  implicit none
+
+  contains
+
+  subroutine foo(n)
+    integer, intent(in) :: n
+    real :: r(0:n,-n:n), a(0:n,-n:n), dj
+    integer :: k, j
+
+    ! initialize with some dummy values
+    do j = -n, n
+      a(:, j) = j
+      r(:,j) = j + 1
+    end do
+
+    ! here be dragons
+    do k = 0, n
+      dj = r(k, k - 2) * a(k, k - 2)
+      r(k,k) = a(k, k - 1) * dj
+    enddo
+
+    if (r(0,0) .ne. -2.) STOP 1
+
+  end subroutine
+
+end module
+
+program test
+  use testmod
+  implicit none
+  call foo(5)
+end program
index 0c1447e7aa0d7984302c60e9df27a5fc8986157b..e3f94cb8a2d1abe0e54df399ad78645a7d48d29c 100644 (file)
@@ -2380,6 +2380,12 @@ vect_analyze_slp_backedges (vec_info *vinfo, slp_tree node,
     if (child)
       vect_analyze_slp_backedges (vinfo, child, bst_map, visited);
 
+  /* Inductions are not vectorized by vectorizing their defining cycle
+     but by materializing the values from SCEV data.  */
+  if (STMT_VINFO_DEF_TYPE (SLP_TREE_REPRESENTATIVE (node))
+      == vect_induction_def)
+    return;
+
   if (gphi *phi = dyn_cast <gphi *> (SLP_TREE_REPRESENTATIVE (node)->stmt))
     for (unsigned i = 0; i < gimple_phi_num_args (phi); ++i)
       {