]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/101105 - fix runtime alias test optimization
authorRichard Biener <rguenther@suse.de>
Wed, 23 Jun 2021 10:43:03 +0000 (12:43 +0200)
committerRichard Biener <rguenther@suse.de>
Fri, 25 Jun 2021 07:04:06 +0000 (09:04 +0200)
We were ignoring DR_STEP for VF == 1 which is OK only in case
the scalar order is preserved or both DR steps are the same.

2021-06-23  Richard Biener  <rguenther@suse.de>

PR tree-optimization/101105
* tree-vect-data-refs.c (vect_prune_runtime_alias_test_list):
Only ignore steps when they are equal or scalar order is preserved.

* gcc.dg/torture/pr101105.c: New testcase.

(cherry picked from commit 50374fdacbd121bc4a61b073e559208ff61bee06)

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

diff --git a/gcc/testsuite/gcc.dg/torture/pr101105.c b/gcc/testsuite/gcc.dg/torture/pr101105.c
new file mode 100644 (file)
index 0000000..9222351
--- /dev/null
@@ -0,0 +1,19 @@
+/* { dg-do run } */
+
+short a;
+int b[5][4] = {2, 2};
+int d;
+short e(int f) { return f == 0 || a && f == 1 ? 0 : a; }
+int main() {
+  int g, h;
+  g = 3;
+  for (; g >= 0; g--) {
+    h = 3;
+    for (; h >= 0; h--)
+      b[g][h] = b[0][1] && e(1);
+  }
+  d = b[0][1];
+  if (d != 0)
+    __builtin_abort ();
+  return 0;
+}
index 97c8577ebe720cf857d811c70eccf60c7655509c..9366660e3ff3b3833ef7b0644bcbef17d478e785 100644 (file)
@@ -3487,9 +3487,9 @@ vect_prune_runtime_alias_test_list (loop_vec_info loop_vinfo)
   /* Step values are irrelevant for aliasing if the number of vector
      iterations is equal to the number of scalar iterations (which can
      happen for fully-SLP loops).  */
-  bool ignore_step_p = known_eq (LOOP_VINFO_VECT_FACTOR (loop_vinfo), 1U);
+  bool vf_one_p = known_eq (LOOP_VINFO_VECT_FACTOR (loop_vinfo), 1U);
 
-  if (!ignore_step_p)
+  if (!vf_one_p)
     {
       /* Convert the checks for nonzero steps into bound tests.  */
       tree value;
@@ -3542,6 +3542,11 @@ vect_prune_runtime_alias_test_list (loop_vec_info loop_vinfo)
 
       bool preserves_scalar_order_p
        = vect_preserves_scalar_order_p (dr_info_a, dr_info_b);
+      bool ignore_step_p
+         = (vf_one_p
+            && (preserves_scalar_order_p
+                || operand_equal_p (DR_STEP (dr_info_a->dr),
+                                    DR_STEP (dr_info_b->dr))));
 
       /* Skip the pair if inter-iteration dependencies are irrelevant
         and intra-iteration dependencies are guaranteed to be honored.  */