public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-5444] tree-optimization/112281 - loop distribution and zero dependence distances
@ 2023-11-14 12:50 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2023-11-14 12:50 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:5ea2965b499f9e491e45db19fedbccfccb75076a

commit r14-5444-g5ea2965b499f9e491e45db19fedbccfccb75076a
Author: Richard Biener <rguenther@suse.de>
Date:   Tue Nov 14 11:37:13 2023 +0100

    tree-optimization/112281 - loop distribution and zero dependence distances
    
    We currently distribute
    
      for (c = 2; c; c--)
        for (e = 0; e < 2; e++) {
          d[c] = b = d[c + 1];
          d[c + 1].a = 0;
        }
    
    in a wrong way where the inner loop zero dependence distance should
    make us preserve stmt execution order.  We fail to do so since we
    only look for a fully zero distance vector rather than looking at
    the innermost loop distance.  This is somewhat similar to PR87022
    where we instead looked at the outermost loop distance and changed
    this to what we do now.  The following switches us to look at the
    innermost loop distance.
    
            PR tree-optimization/112281
            * tree-loop-distribution.cc (pg_add_dependence_edges):
            Preserve stmt order when the innermost loop has exact
            overlap.
    
            * gcc.dg/torture/pr112281.c: New testcase.

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr112281.c | 19 +++++++++++++++++++
 gcc/tree-loop-distribution.cc           |  7 ++++---
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/torture/pr112281.c b/gcc/testsuite/gcc.dg/torture/pr112281.c
new file mode 100644
index 00000000000..3f0a61a9376
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr112281.c
@@ -0,0 +1,19 @@
+/* { dg-do run } */
+/* { dg-additional-options "-ftree-loop-distribution" } */
+
+struct {
+  int : 8;
+  int a;
+} b, d[4] = {{0}, {0}, {0}, {5}};
+int c, e;
+int main()
+{
+  for (c = 2; c; c--)
+    for (e = 0; e < 2; e++) {
+      d[c] = b = d[c + 1];
+      d[c + 1].a = 0;
+    }
+  if (b.a != 0)
+    __builtin_abort();
+  return 0;
+}
diff --git a/gcc/tree-loop-distribution.cc b/gcc/tree-loop-distribution.cc
index 8abfa992070..8e92af61c57 100644
--- a/gcc/tree-loop-distribution.cc
+++ b/gcc/tree-loop-distribution.cc
@@ -2163,9 +2163,10 @@ loop_distribution::pg_add_dependence_edges (struct graph *rdg, int dir,
 		 gcc.dg/tree-ssa/pr94969.c.  */
 	      if (DDR_NUM_DIST_VECTS (ddr) != 1)
 		this_dir = 2;
-	      /* If the overlap is exact preserve stmt order.  */
-	      else if (lambda_vector_zerop (DDR_DIST_VECT (ddr, 0),
-					    DDR_NB_LOOPS (ddr)))
+	      /* If the dependence distance is zero in the innermost
+		 loop preserve stmt order.  */
+	      else if (DDR_DIST_VECT (ddr, 0)
+			 [DDR_LOOP_NEST (ddr).length () - 1] == 0)
 		;
 	      /* Else as the distance vector is lexicographic positive swap
 		 the dependence direction.  */

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-11-14 12:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-14 12:50 [gcc r14-5444] tree-optimization/112281 - loop distribution and zero dependence distances Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).