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.

Bootstrapped and tested on x86-64-unknown-linux-gnu, pushed.

        PR tree-optimization/122419
        * tree-vect-slp.cc (vect_analyze_slp_reduc_chain): Only
        skip noop conversions.

        * gcc.dg/vect/pr122419.c: New testcase.
---
 gcc/testsuite/gcc.dg/vect/pr122419.c | 9 +++++++++
 gcc/tree-vect-slp.cc                 | 1 +
 2 files changed, 10 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/vect/pr122419.c

diff --git a/gcc/testsuite/gcc.dg/vect/pr122419.c 
b/gcc/testsuite/gcc.dg/vect/pr122419.c
new file mode 100644
index 00000000000..b428cfb1812
--- /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 df2afaa9ead..fca1442f019 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))))
        ;
-- 
2.51.0

Reply via email to