]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/126404 - fixup conversion detection in reductions
authorRichard Biener <rguenther@suse.de>
Mon, 27 Jul 2026 17:24:32 +0000 (19:24 +0200)
committerRichard Biener <rguenther@suse.de>
Tue, 28 Jul 2026 05:58:47 +0000 (07:58 +0200)
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.

gcc/testsuite/gcc.dg/vect/vect-pr126404.c [new file with mode: 0644]
gcc/tree-vect-slp.cc

diff --git a/gcc/testsuite/gcc.dg/vect/vect-pr126404.c b/gcc/testsuite/gcc.dg/vect/vect-pr126404.c
new file mode 100644 (file)
index 0000000..4657d34
--- /dev/null
@@ -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;
+}
index cc802f4f4cd922678874f4b1a62e25a180bd3b01..e1112077c1688a7b052a42ee21f7cd10c8afcb18 100644 (file)
@@ -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;