From da2bf62d9e2a25f2d6a99176144c250b51fbdee7 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Wed, 9 Feb 2022 10:55:18 +0100 Subject: tree-optimization/104445 - check for vector extraction support This adds a missing check to epilogue reduction re-use, namely that we can do hi/lo extracts from the vector when demoting it to the epilogue vector size. I've chosen to add a can_vec_extract helper to optabs-query.h, in the future we might want to simplify the vectorizers life by handling vector-from-vector extraction via BIT_FIELD_REFs during RTL expansion via the mode punning when the vec_extract is not directly supported. I'm not 100% sure we can always do the punning of the vec_extract result to a vector mode of the same size, but then I'm also not sure how to check for that (the vectorizer doesn't in other places it does that at the moment, but I suppose we eventually just go through memory there)? 2022-02-09 Richard Biener PR tree-optimization/104445 PR tree-optimization/102832 * optabs-query.h (can_vec_extract): New. * optabs-query.cc (can_vec_extract): Likewise. * tree-vect-loop.cc (vect_find_reusable_accumulator): Check we can extract a hi/lo part from the larger vector, rework check iteration from larger to smaller sizes. * gcc.dg/vect/pr104445.c: New testcase. --- gcc/tree-vect-loop.cc | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'gcc/tree-vect-loop.cc') diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc index 4860bfd..896218f 100644 --- a/gcc/tree-vect-loop.cc +++ b/gcc/tree-vect-loop.cc @@ -4997,17 +4997,21 @@ vect_find_reusable_accumulator (loop_vec_info loop_vinfo, if (!constant_multiple_p (TYPE_VECTOR_SUBPARTS (old_vectype), TYPE_VECTOR_SUBPARTS (vectype), &m)) return false; - /* Check the intermediate vector types are available. */ - while (m > 2) + /* Check the intermediate vector types and operations are available. */ + tree prev_vectype = old_vectype; + poly_uint64 intermediate_nunits = TYPE_VECTOR_SUBPARTS (old_vectype); + while (known_gt (intermediate_nunits, TYPE_VECTOR_SUBPARTS (vectype))) { - m /= 2; + intermediate_nunits = exact_div (intermediate_nunits, 2); tree intermediate_vectype = get_related_vectype_for_scalar_type - (TYPE_MODE (vectype), TREE_TYPE (vectype), - exact_div (TYPE_VECTOR_SUBPARTS (old_vectype), m)); + (TYPE_MODE (vectype), TREE_TYPE (vectype), intermediate_nunits); if (!intermediate_vectype || !directly_supported_p (STMT_VINFO_REDUC_CODE (reduc_info), - intermediate_vectype)) + intermediate_vectype) + || !can_vec_extract (TYPE_MODE (prev_vectype), + TYPE_MODE (intermediate_vectype))) return false; + prev_vectype = intermediate_vectype; } /* Non-SLP reductions might apply an adjustment after the reduction -- cgit v1.1