https://gcc.gnu.org/g:4d0c17354e42d57d3f94a7b66ab59299b076ee68
commit r15-10061-g4d0c17354e42d57d3f94a7b66ab59299b076ee68 Author: Richard Biener <rguent...@suse.de> Date: Tue Jul 22 13:02:03 2025 +0200 tree-optimization/121202 - fix vector stmt placement 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. (cherry picked from commit bdfb5cc5aa6959a6959fc0cf98da08db89c81032) Diff: --- gcc/testsuite/gcc.dg/pr121202.c | 11 +++++++++++ gcc/tree-vect-slp.cc | 6 +++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/gcc/testsuite/gcc.dg/pr121202.c b/gcc/testsuite/gcc.dg/pr121202.c new file mode 100644 index 000000000000..30ecf4a5e01a --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr121202.c @@ -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; +} diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc index f5286e6b819e..b2af2682e582 100644 --- a/gcc/tree-vect-slp.cc +++ b/gcc/tree-vect-slp.cc @@ -11258,7 +11258,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;