[gcc r17-2737] tree-optimization/126404 - fixup conversion detection in reductions

Richard Biener via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:3cd23c9fd60854cd9d160ce3b341a819025bfeb8

commit r17-2737-g3cd23c9fd60854cd9d160ce3b341a819025bfeb8
Author: Richard Biener <[email protected]>
Date:   Mon Jul 27 19:24:32 2026 +0200

    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:
---
 gcc/testsuite/gcc.dg/vect/vect-pr126404.c | 14 ++++++++++++++
 gcc/tree-vect-slp.cc                      |  7 ++++---
 2 files changed, 18 insertions(+), 3 deletions(-)

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 000000000000..4657d34baf38
--- /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 cc802f4f4cd9..e1112077c168 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 <gphi *> (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 <gphi *> (STMT_VINFO_STMT (next_stmt))))
 	;
-      else if (code != op.code)
+      else if (code != orig_op.code)
 	{
 	  fail = true;
 	  break;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.