Improve tree-vect-patterns.c handling of boolean comparisons
authorRichard Sandiford <richard.sandiford@arm.com>
Fri, 29 Nov 2019 14:47:20 +0000 (14:47 +0000)
committerRichard Sandiford <rsandifo@gcc.gnu.org>
Fri, 29 Nov 2019 14:47:20 +0000 (14:47 +0000)
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  <richard.sandiford@arm.com>

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

gcc/ChangeLog
gcc/doc/sourcebuild.texi
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/vect/vect-bool-cmp-2.c [new file with mode: 0644]
gcc/testsuite/lib/target-supports.exp
gcc/tree-vect-patterns.c

index 76fafa832e78bf2dba98611a9ed34e8773e8b42f..92c7622e30b760381cb5cbc00d8fc8fce1cec4e0 100644 (file)
@@ -1,3 +1,10 @@
+2019-11-29  Richard Sandiford  <richard.sandiford@arm.com>
+
+       * 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  <rguenther@suse.de>
 
        * tree-ssa-sccvn.c (vn_walk_cb_data::push_partial_def): Bail
index a30db0de88f991606071c67ed6c37691cac8dde4..3950c82c685d55cb8aada0465b5337555fafbd92 100644 (file)
@@ -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.
index a096fa635f19c8738a52b23cb5765a4f9a946bf5..8c06ec3318dafe239343bc09474bc09cc9874b82 100644 (file)
@@ -1,3 +1,9 @@
+2019-11-29  Richard Sandiford  <richard.sandiford@arm.com>
+
+       * 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  <tobias@codesourcery.com>
 
        * 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 (file)
index 0000000..1fb57ff
--- /dev/null
@@ -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 } } } */
index a4418a3151677a2a45275463b9828db7e7755b28..8f25d3312701ba03ab6abcfed4f1722d766bbb0d 100644 (file)
@@ -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.
 
index e4cfe8581636d5262763eb777409edef05a161f4..6985214d4358ef1c75b7796cf7054c9f5008977b 100644 (file)
@@ -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));