https://gcc.gnu.org/g:87905f63a6521eef1f38082e2368e18c637ef092

commit r15-3959-g87905f63a6521eef1f38082e2368e18c637ef092
Author: Tamar Christina <tamar.christ...@arm.com>
Date:   Mon Sep 30 13:06:24 2024 +0100

    middle-end: check explicitly for external or constants when checking for 
loop invariant [PR116817]
    
    The previous check if a value was external was checking
    !vect_get_internal_def (vinfo, var) but this of course isn't completely 
right
    as they could reductions etc.
    
    This changes the check to just explicitly look at externals and constants.
    Note that reductions remain unhandled here, but we don't support codegen of
    boolean reductions today anyway.
    
    So at the time we do then this would have the be handled as well in 
lowering.
    
    gcc/ChangeLog:
    
            PR tree-optimization/116817
            * tree-vect-patterns.cc (vect_recog_bool_pattern): Check for const 
or
            externals.
    
    gcc/testsuite/ChangeLog:
    
            PR tree-optimization/116817
            * g++.dg/vect/pr116817.cc: New test.

Diff:
---
 gcc/testsuite/g++.dg/vect/pr116817.cc | 16 ++++++++++++++++
 gcc/tree-vect-patterns.cc             |  5 ++++-
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/g++.dg/vect/pr116817.cc 
b/gcc/testsuite/g++.dg/vect/pr116817.cc
new file mode 100644
index 000000000000..7e28982fb138
--- /dev/null
+++ b/gcc/testsuite/g++.dg/vect/pr116817.cc
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-O3" } */
+
+int main_ulData0;
+unsigned *main_pSrcBuffer;
+int main(void) {
+  int iSrc = 0;
+  bool bData0;
+  for (; iSrc < 4; iSrc++) {
+    if (bData0)
+      main_pSrcBuffer[iSrc] = main_ulData0;
+    else
+      main_pSrcBuffer[iSrc] = 0;
+    bData0 = !bData0;
+  }
+}
diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc
index e7e877dd2adb..b174ff1e705c 100644
--- a/gcc/tree-vect-patterns.cc
+++ b/gcc/tree-vect-patterns.cc
@@ -6062,12 +6062,15 @@ vect_recog_bool_pattern (vec_info *vinfo,
       if (get_vectype_for_scalar_type (vinfo, type) == NULL_TREE)
        return NULL;
 
+      enum vect_def_type dt;
       if (check_bool_pattern (var, vinfo, bool_stmts))
        var = adjust_bool_stmts (vinfo, bool_stmts, type, stmt_vinfo);
       else if (integer_type_for_mask (var, vinfo))
        return NULL;
       else if (TREE_CODE (TREE_TYPE (var)) == BOOLEAN_TYPE
-              && !vect_get_internal_def (vinfo, var))
+              && vect_is_simple_use (var, vinfo, &dt)
+              && (dt == vect_external_def
+                  || dt == vect_constant_def))
        {
          /* If the condition is already a boolean then manually convert it to a
             mask of the given integer type but don't set a vectype.  */

Reply via email to