https://gcc.gnu.org/g:187bccedfc454304f7e35697baa5337c59fa2a58

commit r16-4650-g187bccedfc454304f7e35697baa5337c59fa2a58
Author: Richard Biener <[email protected]>
Date:   Mon Oct 27 11:31:32 2025 +0100

    tree-optimization/122419 - reduction chain with conversion as op
    
    The following deals with reduction detection handling a non-noop
    conversion as reduction operation and makes the reduction chain
    chain re-discovery handle this situation the same.
    
            PR tree-optimization/122419
            * tree-vect-slp.cc (vect_analyze_slp_reduc_chain): Only
            skip noop conversions.
    
            * gcc.dg/vect/pr122419.c: New testcase.

Diff:
---
 gcc/testsuite/gcc.dg/vect/pr122419.c | 9 +++++++++
 gcc/tree-vect-slp.cc                 | 1 +
 2 files changed, 10 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/vect/pr122419.c 
b/gcc/testsuite/gcc.dg/vect/pr122419.c
new file mode 100644
index 000000000000..b428cfb18129
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr122419.c
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+
+int a;
+long b;
+void c()
+{
+  for (; b; b--)
+    a = (char)a;
+}
diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc
index 31d84857d493..e02b3379bb46 100644
--- a/gcc/tree-vect-slp.cc
+++ b/gcc/tree-vect-slp.cc
@@ -4217,6 +4217,7 @@ vect_analyze_slp_reduc_chain (loop_vec_info vinfo,
       if (!gimple_extract_op (STMT_VINFO_STMT (vect_orig_stmt (stmt)), &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))))
        ;

Reply via email to