diff mbox series

Fix PR83867

Message ID alpine.LSU.2.20.1801161610540.32271@zhemvz.fhfr.qr
State New
Headers show
Series Fix PR83867 | expand

Commit Message

Richard Biener Jan. 16, 2018, 3:11 p.m. UTC
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.

Richard.

2018-01-16  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/83867
	* tree-vect-stmts.c (vect_transform_stmt): Precompute
	nested_in_vect_loop_p since the scalar stmt may get invalidated.

	* gcc.dg/vect/pr83867.c: New testcase.
diff mbox series

Patch

Index: gcc/tree-vect-stmts.c
===================================================================
--- gcc/tree-vect-stmts.c	(revision 256722)
+++ gcc/tree-vect-stmts.c	(working copy)
@@ -9426,6 +9426,11 @@  vect_transform_stmt (gimple *stmt, gimpl
   gcc_assert (slp_node || !PURE_SLP_STMT (stmt_info));
   gimple *old_vec_stmt = STMT_VINFO_VEC_STMT (stmt_info);
 
+  bool nested_p = (STMT_VINFO_LOOP_VINFO (stmt_info)
+		   && nested_in_vect_loop_p
+		        (LOOP_VINFO_LOOP (STMT_VINFO_LOOP_VINFO (stmt_info)),
+			 stmt));
+
   switch (STMT_VINFO_TYPE (stmt_info))
     {
     case type_demotion_vec_info_type:
@@ -9525,9 +9530,7 @@  vect_transform_stmt (gimple *stmt, gimpl
   /* Handle inner-loop stmts whose DEF is used in the loop-nest that
      is being vectorized, but outside the immediately enclosing loop.  */
   if (vec_stmt
-      && STMT_VINFO_LOOP_VINFO (stmt_info)
-      && nested_in_vect_loop_p (LOOP_VINFO_LOOP (
-                                STMT_VINFO_LOOP_VINFO (stmt_info)), stmt)
+      && nested_p
       && STMT_VINFO_TYPE (stmt_info) != reduc_vec_info_type
       && (STMT_VINFO_RELEVANT (stmt_info) == vect_used_in_outer
           || STMT_VINFO_RELEVANT (stmt_info) ==
Index: gcc/testsuite/gcc.dg/vect/pr83867.c
===================================================================
--- gcc/testsuite/gcc.dg/vect/pr83867.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/vect/pr83867.c	(working copy)
@@ -0,0 +1,20 @@ 
+/* { dg-do compile } */
+/* { dg-additional-options "-O -ftrapv" } */
+
+int
+k5 (int u5, int aw)
+{
+  int v6;
+
+  while (u5 < 1)
+    {
+      while (v6 < 4)
+	++v6;
+
+      v6 = 0;
+      aw += u5 > 0;
+      ++u5;
+    }
+
+  return aw;
+}