]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/113431 - wrong dependence with invariant load
authorRichard Biener <rguenther@suse.de>
Wed, 17 Jan 2024 13:05:42 +0000 (14:05 +0100)
committerRichard Biener <rguenther@suse.de>
Thu, 18 Jan 2024 07:31:41 +0000 (08:31 +0100)
The vectorizer dependence analysis is confused with invariant loads
when figuring whether the circumstances are so that we preserve
scalar stmt execution order.  The following rectifies this.

PR tree-optimization/113431
* tree-vect-data-refs.cc (vect_preserves_scalar_order_p):
When there is an invariant load we might not preserve
scalar order.

* gcc.dg/vect/pr113431.c: New testcase.

gcc/testsuite/gcc.dg/vect/pr113431.c [new file with mode: 0644]
gcc/tree-vect-data-refs.cc

diff --git a/gcc/testsuite/gcc.dg/vect/pr113431.c b/gcc/testsuite/gcc.dg/vect/pr113431.c
new file mode 100644 (file)
index 0000000..04448d9
--- /dev/null
@@ -0,0 +1,18 @@
+/* { dg-additional-options "-O3 -fdump-tree-slp1-details" } */
+
+#include "tree-vect.h"
+
+int a[2][9];
+int b;
+int main()
+{
+  check_vect ();
+  for (b = 0; b < 2; b++)
+    for (long e = 8; e > 0; e--)
+      a[b][e] = a[0][1] == 0;
+  if (a[1][1] != 0)
+    __builtin_abort ();
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump-times "optimized: basic block part vectorized" 2 "slp1" { target vect_int } } } */
index 0495842b35050d024018c08a150d04a6dce0a86d..f592aeb8028afd4fd70e2175104efab2a2c0d82e 100644 (file)
@@ -282,6 +282,12 @@ vect_preserves_scalar_order_p (dr_vec_info *dr_info_a, dr_vec_info *dr_info_b)
       && !STMT_VINFO_GROUPED_ACCESS (stmtinfo_b))
     return true;
 
+  /* If there is a loop invariant read involved we might vectorize it in
+     the prologue, breaking scalar oder with respect to the in-loop store.  */
+  if ((DR_IS_READ (dr_info_a->dr) && integer_zerop (DR_STEP (dr_info_a->dr)))
+      || (DR_IS_READ (dr_info_b->dr) && integer_zerop (DR_STEP (dr_info_b->dr))))
+    return false;
+
   /* STMT_A and STMT_B belong to overlapping groups.  All loads are
      emitted at the position of the first scalar load.
      Stores in a group are emitted at the position of the last scalar store.