[committed] tree-optimization/128377 - SLP inserts before returns-twice call

Message ID q6r80097-r47p-nr28-8q26-q7003s025r07@fhfr.qr
State New
Headers
Series [committed] tree-optimization/128377 - SLP inserts before returns-twice call |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_simplebootstrap_build--master-aarch64-bootstrap fail Patch failed to apply
linaro-tcwg-bot/tcwg_gcc_build--master-arm fail Patch failed to apply

Commit Message

Richard Biener Nov. 3, 2026, 12:06 p.m. UTC
  The following adjusts vec_info::insert_seq_on_entry to deal with
the case where the SLP region starts at a block with a returns-twice
call.  That cannot participate in vectorization and we have to insert
after it.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

	PR tree-optimization/128377
	* tree-vectorizer.cc (vec_info::insert_seq_on_entry): Advance
	the iterator if the region starts with a returns-twice call.

	* gcc.dg/vect/bb-slp-pr128377.c: New testcase.
---
 gcc/testsuite/gcc.dg/vect/bb-slp-pr128377.c | 23 +++++++++++++++++++++
 gcc/tree-vectorizer.cc                      |  7 +++++--
 2 files changed, 28 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/vect/bb-slp-pr128377.c
  

Patch

diff --git a/gcc/testsuite/gcc.dg/vect/bb-slp-pr128377.c b/gcc/testsuite/gcc.dg/vect/bb-slp-pr128377.c
new file mode 100644
index 00000000000..dad4683f975
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/bb-slp-pr128377.c
@@ -0,0 +1,23 @@ 
+/* { dg-do compile } */
+
+extern int rt (void) __attribute__ ((returns_twice, leaf));
+extern void bar (void);
+
+void
+f (int *out, int x, int y, int c)
+{
+  bar ();
+  switch (c)
+    {
+    case 1:
+      rt ();
+      out[0] = x + 1;
+      out[1] = y + 2;
+      out[2] = x + 3;
+      out[3] = y + 4;
+      break;
+    case 2:
+      bar ();
+      break;
+    }
+}
diff --git a/gcc/tree-vectorizer.cc b/gcc/tree-vectorizer.cc
index 8c824e4ee33..e089adddca0 100644
--- a/gcc/tree-vectorizer.cc
+++ b/gcc/tree-vectorizer.cc
@@ -694,8 +694,11 @@  vec_info::insert_seq_on_entry (stmt_vec_info context, gimple_seq seq)
     }
   else
     {
-      gimple_stmt_iterator gsi_region_begin
-	= gsi_after_labels (bbs[0]);
+      gimple_stmt_iterator gsi_region_begin = gsi_after_labels (bbs[0]);
+      /* If the regions starts with a returns-twice call insert afte that.  */
+      if (gcall *call = safe_dyn_cast <gcall *> (gsi_stmt (gsi_region_begin)))
+	if (gimple_call_flags (call) & ECF_RETURNS_TWICE)
+	  gsi_next (&gsi_region_begin);
       gsi_insert_seq_before (&gsi_region_begin, seq, GSI_SAME_STMT);
     }
 }