]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/121202 - fix vector stmt placement
authorRichard Biener <rguenther@suse.de>
Tue, 22 Jul 2025 11:02:03 +0000 (13:02 +0200)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 22 Jul 2025 12:14:53 +0000 (14:14 +0200)
When we have a vector shift with a scalar the shift operand can be
external - in that case we should not use the shift operand def
as hint where to place the vector shift instruction.  The ICE
in the PR is because stmt dominance queries only work inside of
the vector region.  But we should also never place stmts outside
of it.

PR tree-optimization/121202
* tree-vect-slp.cc (vect_schedule_slp_node): Do not take
an out-of-region stmt as "last".

* gcc.dg/pr121202.c: New testcase.

gcc/testsuite/gcc.dg/pr121202.c [new file with mode: 0644]
gcc/tree-vect-slp.cc

diff --git a/gcc/testsuite/gcc.dg/pr121202.c b/gcc/testsuite/gcc.dg/pr121202.c
new file mode 100644 (file)
index 0000000..30ecf4a
--- /dev/null
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -fno-tree-copy-prop" } */
+
+int a, b, c;
+int e(int f, int g) { return f >> g; }
+int h(int f) { return a > 1 ? 0 : f << a; }
+int main() {
+  while (c--)
+    b = e(h(1), a);
+  return 0;
+}
index 7ad56b9a848a5d6bbd6b11339cdec5977e01ed81..7776b2f1d8e6ea86f3befab02cfc80cb2b61f7b1 100644 (file)
@@ -11370,7 +11370,11 @@ vect_schedule_slp_node (vec_info *vinfo,
                  && !SSA_NAME_IS_DEFAULT_DEF (def))
                {
                  gimple *stmt = SSA_NAME_DEF_STMT (def);
-                 if (!last_stmt)
+                 if (gimple_uid (stmt) == -1u)
+                   /* If the stmt is not inside the region do not
+                      use it as possible insertion point.  */
+                   ;
+                 else if (!last_stmt)
                    last_stmt = stmt;
                  else if (vect_stmt_dominates_stmt_p (last_stmt, stmt))
                    last_stmt = stmt;