diff mbox series

middle-end: Mark all control flow as used_in_scope.

Message ID patch-18073-tamar@arm.com
State New
Headers show
Series middle-end: Mark all control flow as used_in_scope. | expand

Commit Message

Tamar Christina Dec. 11, 2023, 10:22 a.m. UTC
Hi All,

While compiling SPECCPU 2017 I ran accross the reason (I had forgotten) why my
initial patch marked all control statements as used in scope and not just
gconds:  There are other statements that can introduce multiple exits, like
switch statements.   If we ignore them as not relevant we never get a chance to
reject them later as not vectorizable.  Becuase they are marked as not relevant
we crash or produce invalid code.

The fix is to mark all control statements as used in scope, and then we
later reject them as not vectorizable.

Bootstrapped Regtested on aarch64-none-linux-gnu and no issues.

Ok for master?

Thanks,
Tamar

gcc/ChangeLog:

	* tree-vect-stmts.cc (vect_stmt_relevant_p): Mark all control flow as
	used in scope.

gcc/testsuite/ChangeLog:

	* gcc.dg/vect/vect-early-break_89.c: New test.

--- inline copy of patch -- 
diff --git a/gcc/testsuite/gcc.dg/vect/vect-early-break_89.c b/gcc/testsuite/gcc.dg/vect/vect-early-break_89.c
new file mode 100644
index 0000000000000000000000000000000000000000..d33f3d94c096ffc53e4e82a28c3db058633fb21d




--
diff --git a/gcc/testsuite/gcc.dg/vect/vect-early-break_89.c b/gcc/testsuite/gcc.dg/vect/vect-early-break_89.c
new file mode 100644
index 0000000000000000000000000000000000000000..d33f3d94c096ffc53e4e82a28c3db058633fb21d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/vect-early-break_89.c
@@ -0,0 +1,18 @@
+/* { dg-require-effective-target vect_int } */
+
+char *a;
+extern void d();
+void b() {
+  int c = 0;
+  while (c < 16) {
+    switch (a[c]) {
+    case '"':
+    case '\'':
+      c++;
+      continue;
+    }
+    break;
+  }
+  if (c)
+    d();
+}
diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index 72f271658e357bd562eb29087735825eb5ab0dc0..98704b7cea8a93f5beae7a55c85085c049e54152 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -361,7 +361,7 @@ vect_stmt_relevant_p (stmt_vec_info stmt_info, loop_vec_info loop_vinfo,
 
   /* cond stmt other than loop exit cond.  */
   gimple *stmt = STMT_VINFO_STMT (stmt_info);
-  if (is_a <gcond *> (stmt)
+  if (is_ctrl_stmt (stmt)
       && LOOP_VINFO_LOOP_IV_COND (loop_vinfo) != stmt
       && (!loop->inner || gimple_bb (stmt)->loop_father == loop))
     *relevant = vect_used_in_scope;

Comments

Richard Biener Dec. 11, 2023, 10:43 a.m. UTC | #1
On Mon, 11 Dec 2023, Tamar Christina wrote:

> Hi All,
> 
> While compiling SPECCPU 2017 I ran accross the reason (I had forgotten) why my
> initial patch marked all control statements as used in scope and not just
> gconds:  There are other statements that can introduce multiple exits, like
> switch statements.   If we ignore them as not relevant we never get a chance to
> reject them later as not vectorizable.  Becuase they are marked as not relevant
> we crash or produce invalid code.
> 
> The fix is to mark all control statements as used in scope, and then we
> later reject them as not vectorizable.
> 
> Bootstrapped Regtested on aarch64-none-linux-gnu and no issues.
> 
> Ok for master?

OK

> Thanks,
> Tamar
> 
> gcc/ChangeLog:
> 
> 	* tree-vect-stmts.cc (vect_stmt_relevant_p): Mark all control flow as
> 	used in scope.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* gcc.dg/vect/vect-early-break_89.c: New test.
> 
> --- inline copy of patch -- 
> diff --git a/gcc/testsuite/gcc.dg/vect/vect-early-break_89.c b/gcc/testsuite/gcc.dg/vect/vect-early-break_89.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..d33f3d94c096ffc53e4e82a28c3db058633fb21d
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/vect/vect-early-break_89.c
> @@ -0,0 +1,18 @@
> +/* { dg-require-effective-target vect_int } */
> +
> +char *a;
> +extern void d();
> +void b() {
> +  int c = 0;
> +  while (c < 16) {
> +    switch (a[c]) {
> +    case '"':
> +    case '\'':
> +      c++;
> +      continue;
> +    }
> +    break;
> +  }
> +  if (c)
> +    d();
> +}
> diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
> index 72f271658e357bd562eb29087735825eb5ab0dc0..98704b7cea8a93f5beae7a55c85085c049e54152 100644
> --- a/gcc/tree-vect-stmts.cc
> +++ b/gcc/tree-vect-stmts.cc
> @@ -361,7 +361,7 @@ vect_stmt_relevant_p (stmt_vec_info stmt_info, loop_vec_info loop_vinfo,
>  
>    /* cond stmt other than loop exit cond.  */
>    gimple *stmt = STMT_VINFO_STMT (stmt_info);
> -  if (is_a <gcond *> (stmt)
> +  if (is_ctrl_stmt (stmt)
>        && LOOP_VINFO_LOOP_IV_COND (loop_vinfo) != stmt
>        && (!loop->inner || gimple_bb (stmt)->loop_father == loop))
>      *relevant = vect_used_in_scope;
> 
> 
> 
> 
>
diff mbox series

Patch

--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/vect-early-break_89.c
@@ -0,0 +1,18 @@ 
+/* { dg-require-effective-target vect_int } */
+
+char *a;
+extern void d();
+void b() {
+  int c = 0;
+  while (c < 16) {
+    switch (a[c]) {
+    case '"':
+    case '\'':
+      c++;
+      continue;
+    }
+    break;
+  }
+  if (c)
+    d();
+}
diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index 72f271658e357bd562eb29087735825eb5ab0dc0..98704b7cea8a93f5beae7a55c85085c049e54152 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -361,7 +361,7 @@  vect_stmt_relevant_p (stmt_vec_info stmt_info, loop_vec_info loop_vinfo,
 
   /* cond stmt other than loop exit cond.  */
   gimple *stmt = STMT_VINFO_STMT (stmt_info);
-  if (is_a <gcond *> (stmt)
+  if (is_ctrl_stmt (stmt)
       && LOOP_VINFO_LOOP_IV_COND (loop_vinfo) != stmt
       && (!loop->inner || gimple_bb (stmt)->loop_father == loop))
     *relevant = vect_used_in_scope;