diff mbox series

middle-end: Insert invariant instructions before the gsi [PR116812[

Message ID patch-18802-tamar@arm.com
State New
Headers show
Series middle-end: Insert invariant instructions before the gsi [PR116812[ | expand

Commit Message

Tamar Christina Sept. 23, 2024, 6:15 a.m. UTC
Hi All,

The new invariant statements should be inserted before the current
statement and not after.  This goes fine 99% of the time but when the
current statement is a gcond the control flow gets corrupted.

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

Ok for master?

Thanks,
Tamar

gcc/ChangeLog:

	PR tree-optimization/116812
	* tree-vect-slp.cc (vect_slp_region): Fix insertion.

gcc/testsuite/ChangeLog:

	PR tree-optimization/116812
	* gcc.dg/vect/pr116812.c: New test.

---




--

Comments

Richard Biener Sept. 23, 2024, 7:37 a.m. UTC | #1
On Mon, 23 Sep 2024, Tamar Christina wrote:

> Hi All,
> 
> The new invariant statements should be inserted before the current
> statement and not after.  This goes fine 99% of the time but when the
> current statement is a gcond the control flow gets corrupted.
> 
> Bootstrapped Regtested on aarch64-none-linux-gnu and no issues.
> 
> Ok for master?
> 
> Thanks,
> Tamar
> 
> gcc/ChangeLog:
> 
> 	PR tree-optimization/116812
> 	* tree-vect-slp.cc (vect_slp_region): Fix insertion.
> 
> gcc/testsuite/ChangeLog:
> 
> 	PR tree-optimization/116812
> 	* gcc.dg/vect/pr116812.c: New test.
> 
> ---
> diff --git a/gcc/testsuite/gcc.dg/vect/pr116812.c b/gcc/testsuite/gcc.dg/vect/pr116812.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..3e83c13d94bdb475828971efb5b6f2e5101eaebe
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/vect/pr116812.c
> @@ -0,0 +1,17 @@
> +/* { dg-do compile } */
> +/* { dg-additional-options "-O2 -fno-tree-dce -fno-tree-dse" } */
> +
> +int a, b, c, d, e, f[2], g, h;
> +int k(int j) { return 2 >> a ? 2 >> a : a; }
> +int main() {
> +  int i;
> +  for (; g; g = k(d = 0))
> +    ;
> +  if (a)
> +    b && h;
> +  for (e = 0; e < 2; e++)
> +    c = d & 1 ? d : 0;
> +  for (i = 0; i < 2; i++)
> +    f[i] = 0;
> +  return 0;
> +}
> diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc
> index 600987dd6e5d506aa5fbb02350f9dab77793d382..d08d2f84a00ed307e03fc1c027681d428e12fdd0 100644
> --- a/gcc/tree-vect-slp.cc
> +++ b/gcc/tree-vect-slp.cc
> @@ -9170,8 +9170,8 @@ vect_slp_region (vec<basic_block> bbs, vec<data_reference_p> datarefs,
>  
>  	      gimple_stmt_iterator gsi;
>  	      gsi = gsi_after_labels (bb_vinfo->bbs[0]);
> -	      gsi_insert_seq_after (&gsi, bb_vinfo->inv_pattern_def_seq,
> -				    GSI_CONTINUE_LINKING);
> +	      gsi_insert_seq_before (&gsi, bb_vinfo->inv_pattern_def_seq,
> +				     GSI_CONTINUE_LINKING);

Please use bb_vinfo->insert_seq_on_entry

OK with that change.
Richard.

>  	    }
>  	}
>        else
> 
> 
> 
> 
>
diff mbox series

Patch

diff --git a/gcc/testsuite/gcc.dg/vect/pr116812.c b/gcc/testsuite/gcc.dg/vect/pr116812.c
new file mode 100644
index 0000000000000000000000000000000000000000..3e83c13d94bdb475828971efb5b6f2e5101eaebe
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr116812.c
@@ -0,0 +1,17 @@ 
+/* { dg-do compile } */
+/* { dg-additional-options "-O2 -fno-tree-dce -fno-tree-dse" } */
+
+int a, b, c, d, e, f[2], g, h;
+int k(int j) { return 2 >> a ? 2 >> a : a; }
+int main() {
+  int i;
+  for (; g; g = k(d = 0))
+    ;
+  if (a)
+    b && h;
+  for (e = 0; e < 2; e++)
+    c = d & 1 ? d : 0;
+  for (i = 0; i < 2; i++)
+    f[i] = 0;
+  return 0;
+}
diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc
index 600987dd6e5d506aa5fbb02350f9dab77793d382..d08d2f84a00ed307e03fc1c027681d428e12fdd0 100644
--- a/gcc/tree-vect-slp.cc
+++ b/gcc/tree-vect-slp.cc
@@ -9170,8 +9170,8 @@  vect_slp_region (vec<basic_block> bbs, vec<data_reference_p> datarefs,
 
 	      gimple_stmt_iterator gsi;
 	      gsi = gsi_after_labels (bb_vinfo->bbs[0]);
-	      gsi_insert_seq_after (&gsi, bb_vinfo->inv_pattern_def_seq,
-				    GSI_CONTINUE_LINKING);
+	      gsi_insert_seq_before (&gsi, bb_vinfo->inv_pattern_def_seq,
+				     GSI_CONTINUE_LINKING);
 	    }
 	}
       else