From: Richard Biener Date: Tue, 2 Sep 2025 07:50:14 +0000 (+0200) Subject: tree-optimization/121754 - ICE with vect_reduc_type and nested cycle X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=861b7c054e5f356722e6e1a1b043de5d7a412499;p=thirdparty%2Fgcc.git tree-optimization/121754 - ICE with vect_reduc_type and nested cycle The reduction guard isn't correct, STMT_VINFO_REDUC_DEF also exists for nested cycles not part of reductions but there's no reduction info for them. PR tree-optimization/121754 * tree-vectorizer.h (vect_reduc_type): Simplify to not ICE on nested cycles. * gcc.dg/vect/pr121754.c: New testcase. * gcc.target/aarch64/vect-pr121754.c: Likewise. --- diff --git a/gcc/testsuite/gcc.dg/vect/pr121754.c b/gcc/testsuite/gcc.dg/vect/pr121754.c new file mode 100644 index 00000000000..775abda76c5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr121754.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ + +float a; +void +fn1 (int b) +{ + for (; b < 10; b++) + { + a = 01.; + for (int c = 0; c < 2000; c++) + a *= 0.99; + } +} diff --git a/gcc/testsuite/gcc.target/aarch64/vect-pr121754.c b/gcc/testsuite/gcc.target/aarch64/vect-pr121754.c new file mode 100644 index 00000000000..8b6a757780d --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/vect-pr121754.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -ftree-vectorize -mcpu=neoverse-v2" } */ + +float a; +void +fn1 (int b) +{ + for (; b < 10; b++) + { + a = 01.; + for (int c = 0; c < 2000; c++) + a *= 0.99; + } +} diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h index 87ffe497008..df805c6ade9 100644 --- a/gcc/tree-vectorizer.h +++ b/gcc/tree-vectorizer.h @@ -2923,13 +2923,9 @@ vect_reduc_type (vec_info *vinfo, slp_tree node) { if (loop_vec_info loop_vinfo = dyn_cast (vinfo)) { - stmt_vec_info stmt_info = SLP_TREE_REPRESENTATIVE (node); - if (STMT_VINFO_REDUC_DEF (stmt_info)) - { - vect_reduc_info reduc_info - = info_for_reduction (loop_vinfo, node); - return int (VECT_REDUC_INFO_TYPE (reduc_info)); - } + vect_reduc_info reduc_info = info_for_reduction (loop_vinfo, node); + if (reduc_info) + return int (VECT_REDUC_INFO_TYPE (reduc_info)); } return -1; }