public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-9258] tree-optimization/102970 - remap cliques when translating over backedges
@ 2021-11-22  8:00 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2021-11-22  8:00 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:2936f551adec1d8f8c731d013e1b0d9d3f1e824a

commit r11-9258-g2936f551adec1d8f8c731d013e1b0d9d3f1e824a
Author: Richard Biener <rguenther@suse.de>
Date:   Wed Nov 3 13:26:48 2021 +0100

    tree-optimization/102970 - remap cliques when translating over backedges
    
    The following makes sure to remap (or rather drop for simplicity)
    dependence info encoded in MR_DEPENDENCE_CLIQUE when PRE PHI translation
    translates a reference over a backedge since that ends up interleaving
    two different loop iterations which boils down to two different
    inline copies.
    
    2021-11-03  Richard Biener  <rguenther@suse.de>
    
            PR tree-optimization/102970
            * tree-ssa-pre.c (phi_translate_1): Drop clique and base
            when translating a MEM_REF over a backedge.
    
            * g++.dg/opt/pr102970.C: New testcase.
    
    (cherry picked from commit 1967fd8f2197f2b0334ab0fbc26abc3d9efe56c9)

Diff:
---
 gcc/testsuite/g++.dg/opt/pr102970.C | 60 +++++++++++++++++++++++++++++++++++++
 gcc/tree-ssa-pre.c                  | 15 ++++++++++
 2 files changed, 75 insertions(+)

diff --git a/gcc/testsuite/g++.dg/opt/pr102970.C b/gcc/testsuite/g++.dg/opt/pr102970.C
new file mode 100644
index 00000000000..cf5b0ed70b4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/opt/pr102970.C
@@ -0,0 +1,60 @@
+// { dg-do run }
+// { dg-require-effective-target c++11 }
+// { dg-options "-O2 -funroll-loops -fno-tree-vectorize" }
+
+#include <vector>
+#include <algorithm>
+#include <cassert>
+
+struct box {
+   box(int xmin, int xmax, int ymin, int ymax) noexcept
+      : m_xmin(xmin),
+        m_xmax(xmax),
+        m_ymin(ymin),
+        m_ymax(ymax) {
+   }
+
+   box(box const & o) noexcept
+      : m_xmin(o.m_xmin),
+        m_xmax(o.m_xmax),
+        m_ymin(o.m_ymin),
+        m_ymax(o.m_ymax) { }
+
+   int m_xmin;
+   int m_xmax;
+   int m_ymin;
+   int m_ymax;
+};
+
+
+int main() {
+    std::vector<box> vRects{ // requires 18 elements
+        { 900, 11, 22, 33 },
+        { 901, 11, 22, 33 },
+        { 902, 11, 22, 33 },
+        { 903, 11, 22, 33 },
+        { 704, 11, 22, 33 },
+        { 705, 11, 22, 33 },
+        { 706, 11, 22, 33 },
+        { 707, 11, 22, 33 },
+        { 808, 11, 22, 33 },
+        { 809, 11, 22, 33 },
+        { 810, 11, 22, 33 },
+        { 811, 11, 22, 33 },
+        { 812, 11, 22, 33 },
+        { 813, 11, 22, 33 },
+        { 814, 11, 22, 33 },
+        { 815, 11, 22, 33 },
+        { 816, 11, 22, 33 },
+        { 817, 11, 22, 33 },
+        { 818, 11, 22, 33 },
+    };
+
+    std::stable_sort(vRects.begin(), vRects.end(),
+		     [](auto const &r1, auto const &r2) -> bool
+      {
+        if (r2.m_xmax==0||r2.m_ymin==0||r2.m_ymax==0){__builtin_abort();}
+        return r1.m_xmin < r2.m_xmin;
+      });
+  return 0;
+}
diff --git a/gcc/tree-ssa-pre.c b/gcc/tree-ssa-pre.c
index 2aedc31e1d7..4f05c42e210 100644
--- a/gcc/tree-ssa-pre.c
+++ b/gcc/tree-ssa-pre.c
@@ -1609,6 +1609,21 @@ phi_translate_1 (bitmap_set_t dest,
 		newoperands.release ();
 		return NULL;
 	      }
+	    /* When we translate a MEM_REF across a backedge and we have
+	       restrict info that's not from our functions parameters
+	       we have to remap it since we now may deal with a different
+	       instance where the dependence info is no longer valid.
+	       See PR102970.  Note instead of keeping a remapping table
+	       per backedge we simply throw away restrict info.  */
+	    if ((newop.opcode == MEM_REF
+		 || newop.opcode == TARGET_MEM_REF)
+		&& newop.clique > 1
+		&& (e->flags & EDGE_DFS_BACK))
+	      {
+		newop.clique = 0;
+		newop.base = 0;
+		changed = true;
+	      }
 	    if (!changed)
 	      continue;
 	    if (!newoperands.exists ())


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

only message in thread, other threads:[~2021-11-22  8:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-22  8:00 [gcc r11-9258] tree-optimization/102970 - remap cliques when translating over backedges 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).