]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
middle-end: check explicitly for external or constants when checking for loop invaria...
authorTamar Christina <tamar.christina@arm.com>
Mon, 30 Sep 2024 12:06:24 +0000 (13:06 +0100)
committerTamar Christina <tamar.christina@arm.com>
Mon, 30 Sep 2024 12:06:24 +0000 (13:06 +0100)
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.

gcc/testsuite/g++.dg/vect/pr116817.cc [new file with mode: 0644]
gcc/tree-vect-patterns.cc

diff --git a/gcc/testsuite/g++.dg/vect/pr116817.cc b/gcc/testsuite/g++.dg/vect/pr116817.cc
new file mode 100644 (file)
index 0000000..7e28982
--- /dev/null
@@ -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;
+  }
+}
index e7e877dd2adb55262822f1660f8d92b42d44e6d0..b174ff1e705cec8e7bb414c760eb170ca98222cb 100644 (file)
@@ -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.  */