From: Richard Biener Date: Tue, 6 Jan 2026 12:25:10 +0000 (+0100) Subject: tree-optimization/123221 - ICE with conversion reduction X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a74a0db75acd5118d8fd89e0f0fc4f2cd55e9317;p=thirdparty%2Fgcc.git tree-optimization/123221 - ICE with conversion reduction The following avoids ICEing with a reduction only consisting of noop-conversions. PR tree-optimization/123221 * tree-vect-loop.cc (vectorizable_reduction): When we did not find the non-conversion reduction operation, bail. * gcc.dg/vect/vect-pr123221.c: New testcase. --- diff --git a/gcc/testsuite/gcc.dg/vect/vect-pr123221.c b/gcc/testsuite/gcc.dg/vect/vect-pr123221.c new file mode 100644 index 00000000000..642517926d0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-pr123221.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-fno-tree-pre" } */ + +int a, d; +struct { + char b; +} c; +int main() +{ + int f; + for (; d; d++) + c.b = f = a ? c.b : 0; + return 0; +} diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc index a82949745e8..994d1a3ee74 100644 --- a/gcc/tree-vect-loop.cc +++ b/gcc/tree-vect-loop.cc @@ -7123,6 +7123,13 @@ vectorizable_reduction (loop_vec_info loop_vinfo, } reduc_chain_length++; } + if (!slp_for_stmt_info) + { + if (dump_enabled_p ()) + dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, + "only noop-conversions in the reduction chain.\n"); + return false; + } stmt_info = SLP_TREE_REPRESENTATIVE (slp_for_stmt_info); /* PHIs should not participate in patterns. */