From: Richard Sandiford Date: Fri, 29 Nov 2019 14:47:20 +0000 (+0000) Subject: Improve tree-vect-patterns.c handling of boolean comparisons X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ce19a4822794992097deab96bf15bf78ff481ea1;p=gcc.git Improve tree-vect-patterns.c handling of boolean comparisons vect_recog_bool_pattern assumed that a comparison between two booleans should always become a comparison of vector mask types (implemented as an XOR_EXPR). But if the booleans in question are generated as data values (e.g. because they're loaded directly from memory), we should treat them like ordinary integers instead, just as we do for boolean logic ops whose operands are loaded from memory. vect_get_mask_type_for_stmt already handled this case: /* We may compare boolean value loaded as vector of integers. Fix mask_type in such case. */ if (mask_type && !VECTOR_BOOLEAN_TYPE_P (mask_type) && gimple_code (stmt) == GIMPLE_ASSIGN && TREE_CODE_CLASS (gimple_assign_rhs_code (stmt)) == tcc_comparison) mask_type = truth_type_for (mask_type); and not handling it here complicated later patches. The initial list of targets for vect_bool_cmp is deliberately conservative. 2019-11-29 Richard Sandiford gcc/ * doc/sourcebuild.texi (vect_bool_cmp): Document. * tree-vect-patterns.c (search_type_for_mask_1): If neither operand to a boolean comparison is a natural vector mask, handle both operands like normal integers instead. gcc/testsuite/ * gcc.dg/vect/vect-bool-cmp-2.c: New test. * lib/target-supports.exp (check_effective_target_vect_bool_cmp): New effective target procedure. From-SVN: r278847 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 76fafa832e7..92c7622e30b 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2019-11-29 Richard Sandiford + + * doc/sourcebuild.texi (vect_bool_cmp): Document. + * tree-vect-patterns.c (search_type_for_mask_1): If neither + operand to a boolean comparison is a natural vector mask, + handle both operands like normal integers instead. + 2019-11-29 Richard Biener * tree-ssa-sccvn.c (vn_walk_cb_data::push_partial_def): Bail diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi index a30db0de88f..3950c82c685 100644 --- a/gcc/doc/sourcebuild.texi +++ b/gcc/doc/sourcebuild.texi @@ -1522,6 +1522,10 @@ Target does not support a vector add instruction on @code{int}. @item vect_no_bitwise Target does not support vector bitwise instructions. +@item vect_bool_cmp +Target supports comparison of @code{bool} vectors for at least one +vector length. + @item vect_char_add Target supports addition of @code{char} vectors for at least one vector length. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a096fa635f1..8c06ec3318d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2019-11-29 Richard Sandiford + + * gcc.dg/vect/vect-bool-cmp-2.c: New test. + * lib/target-supports.exp (check_effective_target_vect_bool_cmp): New + effective target procedure. + 2019-11-29 Tobias Burnus * fortran.dg/goacc/common-block-3.f90: Check that unused common-block diff --git a/gcc/testsuite/gcc.dg/vect/vect-bool-cmp-2.c b/gcc/testsuite/gcc.dg/vect/vect-bool-cmp-2.c new file mode 100644 index 00000000000..1fb57ff945e --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-bool-cmp-2.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ + +void +f (_Bool *restrict x, _Bool *restrict y) +{ + for (int i = 0; i < 128; ++i) + x[i] = x[i] == y[i]; +} + +/* { dg-final { scan-tree-dump "loop vectorized" "vect" { target vect_bool_cmp } } } */ diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp index a4418a31516..8f25d331270 100644 --- a/gcc/testsuite/lib/target-supports.exp +++ b/gcc/testsuite/lib/target-supports.exp @@ -5749,6 +5749,16 @@ proc check_effective_target_vect_bswap { } { || [istarget amdgcn-*-*] }}] } +# Return 1 if the target supports comparison of bool vectors for at +# least one vector length. + +proc check_effective_target_vect_bool_cmp { } { + return [check_cached_effective_target_indexed vect_bool_cmp { + expr { [istarget i?86-*-*] || [istarget x86_64-*-*] + || [istarget aarch64*-*-*] + || [is-effective-target arm_neon] }}] +} + # Return 1 if the target supports addition of char vectors for at least # one vector length. diff --git a/gcc/tree-vect-patterns.c b/gcc/tree-vect-patterns.c index e4cfe858163..6985214d435 100644 --- a/gcc/tree-vect-patterns.c +++ b/gcc/tree-vect-patterns.c @@ -3944,7 +3944,8 @@ search_type_for_mask_1 (tree var, vec_info *vinfo, vinfo, cache); if (!res || (res2 && TYPE_PRECISION (res) > TYPE_PRECISION (res2))) res = res2; - break; + if (res) + break; } comp_vectype = get_vectype_for_scalar_type (vinfo, TREE_TYPE (rhs1));