From: Richard Biener Date: Mon, 27 Jul 2026 17:24:32 +0000 (+0200) Subject: tree-optimization/126404 - fixup conversion detection in reductions X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3cd23c9fd60854cd9d160ce3b341a819025bfeb8;p=thirdparty%2Fgcc.git tree-optimization/126404 - fixup conversion detection in reductions The following makes sure to check the pattern stmt against being a conversion to skip but the original stmt for a mismatch in code. PR tree-optimization/126404 * tree-vect-slp.cc (vect_analyze_slp_reduc_chain): Fixup conversion detection. * gcc.dg/vect/vect-pr126404.c: New testcase. --- diff --git a/gcc/testsuite/gcc.dg/vect/vect-pr126404.c b/gcc/testsuite/gcc.dg/vect/vect-pr126404.c new file mode 100644 index 00000000000..4657d34baf3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-pr126404.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ + +unsigned ff(int g7) +{ + int v3 = 8; + int ob13; + int ov14; + do { + ob13 = __builtin_add_overflow(2, g7, &ov14); + g7 = 0; + v3 = __builtin_ctz(v3); + } while (ob13); + return v3; +} diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc index cc802f4f4cd..e1112077c16 100644 --- a/gcc/tree-vect-slp.cc +++ b/gcc/tree-vect-slp.cc @@ -4398,7 +4398,7 @@ vect_analyze_slp_reduc_chain (loop_vec_info vinfo, do { stmt_vec_info stmt = next_stmt; - gimple_match_op op; + gimple_match_op op, orig_op; if (!gimple_extract_op (STMT_VINFO_STMT (stmt), &op)) gcc_unreachable (); tree reduc_def = gimple_arg (STMT_VINFO_STMT (stmt), @@ -4406,14 +4406,15 @@ vect_analyze_slp_reduc_chain (loop_vec_info vinfo, next_stmt = vect_stmt_to_vectorize (vinfo->lookup_def (reduc_def)); gcc_assert (is_a (STMT_VINFO_STMT (next_stmt)) || STMT_VINFO_REDUC_IDX (next_stmt) != -1); - if (!gimple_extract_op (STMT_VINFO_STMT (vect_orig_stmt (stmt)), &op)) + if (!gimple_extract_op (STMT_VINFO_STMT (vect_orig_stmt (stmt)), + &orig_op)) gcc_unreachable (); if (CONVERT_EXPR_CODE_P (op.code) && tree_nop_conversion_p (op.type, TREE_TYPE (op.ops[0])) && (first || is_a (STMT_VINFO_STMT (next_stmt)))) ; - else if (code != op.code) + else if (code != orig_op.code) { fail = true; break;