]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
middle-end: have vect_recog_cond_store_pattern use pattern statement for cond if...
authorTamar Christina <tamar.christina@arm.com>
Thu, 5 Sep 2024 09:36:55 +0000 (10:36 +0100)
committerTamar Christina <tamar.christina@arm.com>
Thu, 5 Sep 2024 09:36:55 +0000 (10:36 +0100)
When vectorizing a conditional operation we rely on the bool_recog pattern to
hit and convert the bool of the operand to a valid mask.

However we are currently not using the converted operand as this is in a pattern
statement.  This change updates it to look at the actual statement to be
vectorized so we pick up the pattern.

Note that there are no tests here since vectorization will fail until we
correctly lower all boolean conditionals early.

Tests for these are in the next patch, namely vect-conditional_store_5.c and
vect-conditional_store_6.c.  And the existing vect-conditional_store_[1-4].c
checks that the other cases are still handled correctly.

gcc/ChangeLog:

* tree-vect-patterns.cc (vect_recog_cond_store_pattern): Use pattern
statement.

gcc/tree-vect-patterns.cc

index 3162250bbdd6289742fa0bf0216f38de36086dc8..f7c3c623ea46ea09f4f86139d2a92bb6363aee3c 100644 (file)
@@ -6670,7 +6670,15 @@ vect_recog_cond_store_pattern (vec_info *vinfo,
   if (TREE_CODE (st_rhs) != SSA_NAME)
     return NULL;
 
-  gassign *cond_stmt = dyn_cast<gassign *> (SSA_NAME_DEF_STMT (st_rhs));
+  auto cond_vinfo = vinfo->lookup_def (st_rhs);
+
+  /* If the condition isn't part of the loop then bool recog wouldn't have seen
+     it and so this transformation may not be valid.  */
+  if (!cond_vinfo)
+    return NULL;
+
+  cond_vinfo = vect_stmt_to_vectorize (cond_vinfo);
+  gassign *cond_stmt = dyn_cast<gassign *> (STMT_VINFO_STMT (cond_vinfo));
   if (!cond_stmt || gimple_assign_rhs_code (cond_stmt) != COND_EXPR)
     return NULL;