vect: Fix COND_EXPRs involving variant booleans [PR94727]
authorRichard Sandiford <richard.sandiford@arm.com>
Tue, 28 Apr 2020 07:04:29 +0000 (08:04 +0100)
committerRichard Sandiford <richard.sandiford@arm.com>
Tue, 28 Apr 2020 07:04:29 +0000 (08:04 +0100)
The previous patch for this PR handled separate comparisons.
However, as arm targets show, the same fix is needed when
handling comparisons embedded in a VEC_COND_EXPR.

Here too, the problem is that vect_get_constant_vectors will
calculate its own vector type, using truth_type_for on the
STMT_VINFO_VECTYPE, and the vectoriable_* routines need to be
consistent with that.

2020-04-28  Richard Sandiford  <richard.sandiford@arm.com>

gcc/
PR tree-optimization/94727
* tree-vect-stmts.c (vect_is_simple_cond): If both comparison
operands are invariant booleans, use the mask type associated with the
STMT_VINFO_VECTYPE.  Use !slp_node instead of !vectype to exclude SLP.
(vectorizable_condition): Pass vectype unconditionally to
vect_is_simple_cond.

gcc/ChangeLog
gcc/tree-vect-stmts.c

index a98cb47a521d8844ece9844e0f9dbff8608d69dc..fe1ddac16eb35efca1a52cacb71610212af453f5 100644 (file)
@@ -1,3 +1,12 @@
+2020-04-28  Richard Sandiford  <richard.sandiford@arm.com>
+
+       PR tree-optimization/94727
+       * tree-vect-stmts.c (vect_is_simple_cond): If both comparison
+       operands are invariant booleans, use the mask type associated with the
+       STMT_VINFO_VECTYPE.  Use !slp_node instead of !vectype to exclude SLP.
+       (vectorizable_condition): Pass vectype unconditionally to
+       vect_is_simple_cond.
+
 2020-04-27  Jakub Jelinek  <jakub@redhat.com>
 
        PR target/94780
index 88a1e2c51d203118a9c79aa4b743e47b87a151a5..1984787bac46df86a92098f8f141acfe831f7d7e 100644 (file)
@@ -9942,16 +9942,21 @@ vect_is_simple_cond (tree cond, vec_info *vinfo, slp_tree slp_node,
   if (! *comp_vectype)
     {
       tree scalar_type = TREE_TYPE (lhs);
-      /* If we can widen the comparison to match vectype do so.  */
-      if (INTEGRAL_TYPE_P (scalar_type)
-         && vectype
-         && tree_int_cst_lt (TYPE_SIZE (scalar_type),
-                             TYPE_SIZE (TREE_TYPE (vectype))))
-       scalar_type = build_nonstandard_integer_type
-         (tree_to_uhwi (TYPE_SIZE (TREE_TYPE (vectype))),
-          TYPE_UNSIGNED (scalar_type));
-      *comp_vectype = get_vectype_for_scalar_type (vinfo, scalar_type,
-                                                  slp_node);
+      if (VECT_SCALAR_BOOLEAN_TYPE_P (scalar_type))
+       *comp_vectype = truth_type_for (vectype);
+      else
+       {
+         /* If we can widen the comparison to match vectype do so.  */
+         if (INTEGRAL_TYPE_P (scalar_type)
+             && !slp_node
+             && tree_int_cst_lt (TYPE_SIZE (scalar_type),
+                                 TYPE_SIZE (TREE_TYPE (vectype))))
+           scalar_type = build_nonstandard_integer_type
+             (tree_to_uhwi (TYPE_SIZE (TREE_TYPE (vectype))),
+              TYPE_UNSIGNED (scalar_type));
+         *comp_vectype = get_vectype_for_scalar_type (vinfo, scalar_type,
+                                                      slp_node);
+       }
     }
 
   return true;
@@ -10066,7 +10071,7 @@ vectorizable_condition (stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
   else_clause = gimple_assign_rhs3 (stmt);
 
   if (!vect_is_simple_cond (cond_expr, stmt_info->vinfo, slp_node,
-                           &comp_vectype, &dts[0], slp_node ? NULL : vectype)
+                           &comp_vectype, &dts[0], vectype)
       || !comp_vectype)
     return false;