CTZ pattern recognition can recurse through a temporary pattern
stmt but that will fail to be detected as part of a reduction
because the setup is partial. This causes the reduction chain
to break due to multiple uses. Avoid recursing in case the original
pattern is for a reduction.
Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.
PR tree-optimization/126404
* tree-vect-patterns.cc (vect_recog_popcount_clz_ctz_ffs_pattern):
Avoid recursing to vect_recog_ctz_ffs_pattern with a reduction.
* gcc.dg/vect/vect-pr126404.c: Adjust.
---
gcc/testsuite/gcc.dg/vect/vect-pr126404.c | 1 +
gcc/tree-vect-patterns.cc | 5 +++++
2 files changed, 6 insertions(+)
diff --git a/gcc/testsuite/gcc.dg/vect/vect-pr126404.c
b/gcc/testsuite/gcc.dg/vect/vect-pr126404.c
index 4657d34baf3..ea7187c0c44 100644
--- a/gcc/testsuite/gcc.dg/vect/vect-pr126404.c
+++ b/gcc/testsuite/gcc.dg/vect/vect-pr126404.c
@@ -1,4 +1,5 @@
/* { dg-do compile } */
+/* { dg-additional-options "-march=x86-64-v4" { target { x86_64-*-* i?86-*-* }
} } */
unsigned ff(int g7)
{
diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc
index e0fbe252163..c57e215be57 100644
--- a/gcc/tree-vect-patterns.cc
+++ b/gcc/tree-vect-patterns.cc
@@ -2258,6 +2258,11 @@ vect_recog_popcount_clz_ctz_ffs_pattern (vec_info *vinfo,
bool supported
= direct_internal_fn_supported_p (ifn, vec_type, OPTIMIZE_FOR_SPEED);
+ /* We cannot rely on the reduction check in vect_recog_ctz_ffs_pattern
+ because we do not set up the temporary pattern stmt finally for
+ the recursive analysis. */
+ if (!supported && vect_is_reduction (stmt_vinfo))
+ return NULL;
if (!supported)
switch (ifn)
{
--
2.51.0