Hi,

This patch adopts vectorization factor and vectype computation to statements 
operating with boolean operands.  For comparison compared values are used to 
estimate VF.  Other bool statements don't affect VF.

Thanks,
Ilya
--
2015-08-18  Ilya Enkovich  <enkovich....@gmail.com>

        * tree-vect-loop.c (vect_determine_vectorization_factor): Ignore
        statements with no non-bool args when computing vectorization
        factor.  Compute vectype for masks producers separately.
        (vect_transform_loop): Support scalar masks.


diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c
index 59c75af..89990e3 100644
--- a/gcc/tree-vect-loop.c
+++ b/gcc/tree-vect-loop.c
@@ -193,19 +193,21 @@ vect_determine_vectorization_factor (loop_vec_info 
loop_vinfo)
 {
   struct loop *loop = LOOP_VINFO_LOOP (loop_vinfo);
   basic_block *bbs = LOOP_VINFO_BBS (loop_vinfo);
-  int nbbs = loop->num_nodes;
+  unsigned nbbs = loop->num_nodes;
   unsigned int vectorization_factor = 0;
   tree scalar_type;
   gphi *phi;
   tree vectype;
   unsigned int nunits;
   stmt_vec_info stmt_info;
-  int i;
+  unsigned i;
   HOST_WIDE_INT dummy;
   gimple stmt, pattern_stmt = NULL;
   gimple_seq pattern_def_seq = NULL;
   gimple_stmt_iterator pattern_def_si = gsi_none ();
   bool analyze_pattern_stmt = false;
+  bool bool_result;
+  auto_vec<stmt_vec_info> mask_producers;
 
   if (dump_enabled_p ())
     dump_printf_loc (MSG_NOTE, vect_location,
@@ -424,6 +426,8 @@ vect_determine_vectorization_factor (loop_vec_info 
loop_vinfo)
              return false;
            }
 
+         bool_result = false;
+
          if (STMT_VINFO_VECTYPE (stmt_info))
            {
              /* The only case when a vectype had been already set is for stmts
@@ -444,6 +448,30 @@ vect_determine_vectorization_factor (loop_vec_info 
loop_vinfo)
                scalar_type = TREE_TYPE (gimple_call_arg (stmt, 3));
              else
                scalar_type = TREE_TYPE (gimple_get_lhs (stmt));
+
+             /* Bool ops don't participate in vectorization factor
+                computation.  For comparison use compared types to
+                compute a factor.  */
+             if (scalar_type == boolean_type_node)
+               {
+                 mask_producers.safe_push (stmt_info);
+                 bool_result = true;
+
+                 if (gimple_code (stmt) == GIMPLE_ASSIGN
+                     && TREE_CODE_CLASS (gimple_assign_rhs_code (stmt)) == 
tcc_comparison
+                     && TREE_TYPE (gimple_assign_rhs1 (stmt)) != 
boolean_type_node)
+                   scalar_type = TREE_TYPE (gimple_assign_rhs1 (stmt));
+                 else
+                   {
+                     if (!analyze_pattern_stmt && gsi_end_p (pattern_def_si))
+                       {
+                         pattern_def_seq = NULL;
+                         gsi_next (&si);
+                       }
+                     continue;
+                   }
+               }
+
              if (dump_enabled_p ())
                {
                  dump_printf_loc (MSG_NOTE, vect_location,
@@ -466,7 +494,8 @@ vect_determine_vectorization_factor (loop_vec_info 
loop_vinfo)
                  return false;
                }
 
-             STMT_VINFO_VECTYPE (stmt_info) = vectype;
+             if (!bool_result)
+               STMT_VINFO_VECTYPE (stmt_info) = vectype;
 
              if (dump_enabled_p ())
                {
@@ -479,8 +508,9 @@ vect_determine_vectorization_factor (loop_vec_info 
loop_vinfo)
          /* The vectorization factor is according to the smallest
             scalar type (or the largest vector size, but we only
             support one vector size per loop).  */
-         scalar_type = vect_get_smallest_scalar_type (stmt, &dummy,
-                                                      &dummy);
+         if (!bool_result)
+           scalar_type = vect_get_smallest_scalar_type (stmt, &dummy,
+                                                        &dummy);
          if (dump_enabled_p ())
            {
              dump_printf_loc (MSG_NOTE, vect_location,
@@ -555,6 +585,70 @@ vect_determine_vectorization_factor (loop_vec_info 
loop_vinfo)
     }
   LOOP_VINFO_VECT_FACTOR (loop_vinfo) = vectorization_factor;
 
+  for (i = 0; i < mask_producers.length (); i++)
+    {
+      tree mask_type = NULL;
+
+      stmt = STMT_VINFO_STMT (mask_producers[i]);
+
+      if (gimple_code (stmt) == GIMPLE_ASSIGN
+         && TREE_CODE_CLASS (gimple_assign_rhs_code (stmt)) == tcc_comparison
+         && TREE_TYPE (gimple_assign_rhs1 (stmt)) != boolean_type_node)
+       {
+         scalar_type = TREE_TYPE (gimple_assign_rhs1 (stmt));
+         vectype = get_vectype_for_scalar_type (scalar_type);
+         nunits = TYPE_VECTOR_SUBPARTS (vectype);
+         mask_type = build_nonstandard_integer_type (nunits, 1);
+       }
+      else
+       {
+         tree rhs;
+         ssa_op_iter iter;
+         gimple def_stmt;
+
+         FOR_EACH_SSA_TREE_OPERAND (rhs, stmt, iter, SSA_OP_USE)
+           {
+             def_stmt = SSA_NAME_DEF_STMT (rhs);
+             if (!def_stmt
+                 || !(stmt_info = vinfo_for_stmt (def_stmt))
+                 || !(vectype = STMT_VINFO_VECTYPE (stmt_info))
+                 || VECTOR_TYPE_P (vectype))
+               {
+                 if (dump_enabled_p ())
+                   {
+                     dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
+                                      "not vectorized: can't compute mask type 
"
+                                      "in statement, ");
+                     dump_gimple_stmt (MSG_MISSED_OPTIMIZATION,  TDF_SLIM, 
stmt,
+                                       0);
+                     dump_printf (MSG_MISSED_OPTIMIZATION, "\n");
+                   }
+                 return false;
+               }
+             if (!mask_type)
+               mask_type = vectype;
+             else if (TYPE_PRECISION (mask_type) != TYPE_PRECISION (vectype))
+               {
+                 if (dump_enabled_p ())
+                   {
+                     dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
+                                      "not vectorized: different sized masks "
+                                      "types in statement, ");
+                     dump_generic_expr (MSG_MISSED_OPTIMIZATION, TDF_SLIM,
+                                        mask_type);
+                     dump_printf (MSG_MISSED_OPTIMIZATION, " and ");
+                     dump_generic_expr (MSG_MISSED_OPTIMIZATION, TDF_SLIM,
+                                        vectype);
+                     dump_printf (MSG_MISSED_OPTIMIZATION, "\n");
+                   }
+                 return false;
+               }
+           }
+       }
+
+      STMT_VINFO_VECTYPE (mask_producers[i]) = mask_type;
+    }
+
   return true;
 }
 
@@ -6203,9 +6297,12 @@ vect_transform_loop (loop_vec_info loop_vinfo)
 
          if (STMT_VINFO_VECTYPE (stmt_info))
            {
-             unsigned int nunits
-               = (unsigned int)
+             unsigned int nunits;
+             if (VECTOR_TYPE_P (STMT_VINFO_VECTYPE (stmt_info)))
+               nunits = (unsigned int)
                  TYPE_VECTOR_SUBPARTS (STMT_VINFO_VECTYPE (stmt_info));
+             else
+               nunits = TYPE_PRECISION (STMT_VINFO_VECTYPE (stmt_info));
              if (!STMT_SLP_TYPE (stmt_info)
                  && nunits != (unsigned int) vectorization_factor
                  && dump_enabled_p ())

Reply via email to