https://gcc.gnu.org/g:a50f54c0d06139d791b875e09471f2fc03af5b04

commit r15-3479-ga50f54c0d06139d791b875e09471f2fc03af5b04
Author: Tamar Christina <tamar.christ...@arm.com>
Date:   Thu Sep 5 10:36:55 2024 +0100

    middle-end: have vect_recog_cond_store_pattern use pattern statement for 
cond if available
    
    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.

Diff:
---
 gcc/tree-vect-patterns.cc | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc
index 3162250bbdd..f7c3c623ea4 100644
--- a/gcc/tree-vect-patterns.cc
+++ b/gcc/tree-vect-patterns.cc
@@ -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;

Reply via email to