diff mbox series

Fix PR91790 by considering different first_stmt_info for realign

Message ID 9109e540-b08a-1849-89b7-e7c7d310e34a@linux.ibm.com
State New
Headers show
Series Fix PR91790 by considering different first_stmt_info for realign | expand

Commit Message

Kewen.Lin Nov. 27, 2019, 6:07 a.m. UTC
Hi,

As PR91790 exposed, when we have one slp node whose first_stmt_info_for_drptr
is different from first_stmt_info, it's possible that the first_stmt DR isn't
initialized yet before stmt SLP_TREE_SCALAR_STMTS[0] of slp node. So we
shouldn't use first_stmt_info for vect_setup_realignment, instead we can use
the one based on first_stmt_info_for_drptr DR with additional adjustment by
bumping the distance from first_stmt DR.

Bootstrapped and tested on powerpc64le-linux-gnu (P8LE) and
ppc64-redhat-linux (P7BE) which need to use realign_load.

Is it ok for trunk? and backport to GCC 9 after some burn-in time?

BR,
Kewen

----

gcc/ChangeLog

2019-11-27  Kewen Lin  <linkw@gcc.gnu.org>

	PR tree-optimization/91790
	* gcc/tree-vect-stmts.c (vectorizable_load): Use the adjusted DR for
	vect_setup_realignment when first_stmt_info is different from
	first_stmt_info_for_drptr.

Comments

Richard Biener Nov. 27, 2019, 7:53 a.m. UTC | #1
On Wed, 27 Nov 2019, Kewen.Lin wrote:

> Hi,
> 
> As PR91790 exposed, when we have one slp node whose first_stmt_info_for_drptr
> is different from first_stmt_info, it's possible that the first_stmt DR isn't
> initialized yet before stmt SLP_TREE_SCALAR_STMTS[0] of slp node. So we
> shouldn't use first_stmt_info for vect_setup_realignment, instead we can use
> the one based on first_stmt_info_for_drptr DR with additional adjustment by
> bumping the distance from first_stmt DR.
> 
> Bootstrapped and tested on powerpc64le-linux-gnu (P8LE) and
> ppc64-redhat-linux (P7BE) which need to use realign_load.
> 
> Is it ok for trunk? and backport to GCC 9 after some burn-in time?

OK.

Thanks,
Richard.
diff mbox series

Patch

diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c
index fb669cd..422947b 100644
--- a/gcc/tree-vect-stmts.c
+++ b/gcc/tree-vect-stmts.c
@@ -9186,18 +9186,27 @@  vectorizable_load (stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
       compute_in_loop = true;
     }
 
+  bool diff_first_stmt_info
+    = first_stmt_info_for_drptr && first_stmt_info != first_stmt_info_for_drptr;
+
   if ((alignment_support_scheme == dr_explicit_realign_optimized
        || alignment_support_scheme == dr_explicit_realign)
       && !compute_in_loop)
     {
-      msq = vect_setup_realignment (first_stmt_info, gsi, &realignment_token,
-				    alignment_support_scheme, NULL_TREE,
-				    &at_loop);
+      /* If we have different first_stmt_info, we can't set up realignment
+	 here, since we can't guarantee first_stmt_info DR has been
+	 initialized yet, use first_stmt_info_for_drptr DR by bumping the
+	 distance from first_stmt_info DR instead as below.  */
+      if (!diff_first_stmt_info)
+	msq = vect_setup_realignment (first_stmt_info, gsi, &realignment_token,
+				      alignment_support_scheme, NULL_TREE,
+				      &at_loop);
       if (alignment_support_scheme == dr_explicit_realign_optimized)
 	{
 	  phi = as_a <gphi *> (SSA_NAME_DEF_STMT (msq));
 	  byte_offset = size_binop (MINUS_EXPR, TYPE_SIZE_UNIT (vectype),
 				    size_one_node);
+	  gcc_assert (!first_stmt_info_for_drptr);
 	}
     }
   else
@@ -9253,8 +9262,7 @@  vectorizable_load (stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
 	      dataref_ptr = unshare_expr (DR_BASE_ADDRESS (first_dr_info->dr));
 	      dataref_offset = build_int_cst (ref_type, 0);
 	    }
-	  else if (first_stmt_info_for_drptr
-		   && first_stmt_info != first_stmt_info_for_drptr)
+	  else if (diff_first_stmt_info)
 	    {
 	      dataref_ptr
 		= vect_create_data_ref_ptr (first_stmt_info_for_drptr,
@@ -9271,6 +9279,14 @@  vectorizable_load (stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
 					    DR_INIT (ptrdr)));
 	      dataref_ptr = bump_vector_ptr (dataref_ptr, ptr_incr, gsi,
 					     stmt_info, diff);
+	      if (alignment_support_scheme == dr_explicit_realign)
+		{
+		  msq = vect_setup_realignment (first_stmt_info_for_drptr, gsi,
+						&realignment_token,
+						alignment_support_scheme,
+						dataref_ptr, &at_loop);
+		  gcc_assert (!compute_in_loop);
+		}
 	    }
 	  else if (STMT_VINFO_GATHER_SCATTER_P (stmt_info))
 	    vect_get_gather_scatter_ops (loop, stmt_info, &gs_info,