From 1bb2f23d5345a4669457125b39e1dc5e17df567a Mon Sep 17 00:00:00 2001 From: jakub Date: Thu, 1 Sep 2016 11:46:57 +0000 Subject: Backported from mainline 2016-08-30 Jakub Jelinek PR tree-optimization/72866 * tree-vect-patterns.c (search_type_for_mask): Turn into a small wrapper, move all code to ... (search_type_for_mask_1): ... this new function. Add caching and adjust recursive calls. * gcc.dg/vect/pr72866.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-6-branch@239931 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/tree-vect-patterns.c | 46 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-) (limited to 'gcc/tree-vect-patterns.c') diff --git a/gcc/tree-vect-patterns.c b/gcc/tree-vect-patterns.c index d08b4547756..c2a6f0d3fd5 100644 --- a/gcc/tree-vect-patterns.c +++ b/gcc/tree-vect-patterns.c @@ -3177,13 +3177,11 @@ adjust_bool_pattern (tree var, tree out_type, tree trueval, } -/* Return the proper type for converting bool VAR into - an integer value or NULL_TREE if no such type exists. - The type is chosen so that converted value has the - same number of elements as VAR's vector type. */ +/* Helper for search_type_for_mask. */ static tree -search_type_for_mask (tree var, vec_info *vinfo) +search_type_for_mask_1 (tree var, vec_info *vinfo, + hash_map &cache) { gimple *def_stmt; enum vect_def_type dt; @@ -3208,6 +3206,10 @@ search_type_for_mask (tree var, vec_info *vinfo) if (!is_gimple_assign (def_stmt)) return NULL_TREE; + tree *c = cache.get (def_stmt); + if (c) + return *c; + rhs_code = gimple_assign_rhs_code (def_stmt); rhs1 = gimple_assign_rhs1 (def_stmt); @@ -3216,14 +3218,15 @@ search_type_for_mask (tree var, vec_info *vinfo) case SSA_NAME: case BIT_NOT_EXPR: CASE_CONVERT: - res = search_type_for_mask (rhs1, vinfo); + res = search_type_for_mask_1 (rhs1, vinfo, cache); break; case BIT_AND_EXPR: case BIT_IOR_EXPR: case BIT_XOR_EXPR: - res = search_type_for_mask (rhs1, vinfo); - res2 = search_type_for_mask (gimple_assign_rhs2 (def_stmt), vinfo); + res = search_type_for_mask_1 (rhs1, vinfo, cache); + res2 = search_type_for_mask_1 (gimple_assign_rhs2 (def_stmt), vinfo, + cache); if (!res || (res2 && TYPE_PRECISION (res) > TYPE_PRECISION (res2))) res = res2; break; @@ -3235,8 +3238,9 @@ search_type_for_mask (tree var, vec_info *vinfo) if (TREE_CODE (TREE_TYPE (rhs1)) == BOOLEAN_TYPE) { - res = search_type_for_mask (rhs1, vinfo); - res2 = search_type_for_mask (gimple_assign_rhs2 (def_stmt), vinfo); + res = search_type_for_mask_1 (rhs1, vinfo, cache); + res2 = search_type_for_mask_1 (gimple_assign_rhs2 (def_stmt), + vinfo, cache); if (!res || (res2 && TYPE_PRECISION (res) > TYPE_PRECISION (res2))) res = res2; break; @@ -3244,12 +3248,18 @@ search_type_for_mask (tree var, vec_info *vinfo) comp_vectype = get_vectype_for_scalar_type (TREE_TYPE (rhs1)); if (comp_vectype == NULL_TREE) - return NULL_TREE; + { + res = NULL_TREE; + break; + } mask_type = get_mask_type_for_scalar_type (TREE_TYPE (rhs1)); if (!mask_type || !expand_vec_cmp_expr_p (comp_vectype, mask_type)) - return NULL_TREE; + { + res = NULL_TREE; + break; + } if (TREE_CODE (TREE_TYPE (rhs1)) != INTEGER_TYPE || !TYPE_UNSIGNED (TREE_TYPE (rhs1))) @@ -3262,9 +3272,21 @@ search_type_for_mask (tree var, vec_info *vinfo) } } + cache.put (def_stmt, res); return res; } +/* Return the proper type for converting bool VAR into + an integer value or NULL_TREE if no such type exists. + The type is chosen so that converted value has the + same number of elements as VAR's vector type. */ + +static tree +search_type_for_mask (tree var, vec_info *vinfo) +{ + hash_map cache; + return search_type_for_mask_1 (var, vinfo, cache); +} /* Function vect_recog_bool_pattern -- cgit v1.2.1