diff mbox series

tree-optimization/97135 - fix dependence check in store-motion

Message ID nycvar.YFH.7.76.2009211406060.32737@elmra
State New
Headers show
Series tree-optimization/97135 - fix dependence check in store-motion | expand

Commit Message

Richard Biener Sept. 21, 2020, 12:06 p.m. UTC
The following fixes a dependence check where in the particular place
we cannot ignore self-dependences.

Bootstrapped / tested on x86_64-unknown-linux-gnu, pushed.

2020-09-21  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/97135
	* tree-ssa-loop-im.c (sm_seq_push_down): Do not ignore
	self-dependences.

	* gcc.dg/torture/pr97135.c: New testcase.
---
 gcc/testsuite/gcc.dg/torture/pr97135.c | 21 +++++++++++++++++++++
 gcc/tree-ssa-loop-im.c                 |  8 +++++---
 2 files changed, 26 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr97135.c
diff mbox series

Patch

diff --git a/gcc/testsuite/gcc.dg/torture/pr97135.c b/gcc/testsuite/gcc.dg/torture/pr97135.c
new file mode 100644
index 00000000000..223f4d05b85
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr97135.c
@@ -0,0 +1,21 @@ 
+/* { dg-do run } */
+
+long long e, *d = &e;
+int a, b, c;
+
+int
+main ()
+{
+  for (; c <= 5; c++)
+    for (b = 0; b <= 5; b++)
+      {
+	for (a = 1; a <= 5; a++)
+	  ;
+	*d = 0;
+	if (c)
+	  break;
+      }
+  if (a != 6)
+    __builtin_abort ();
+  return 0;
+}
diff --git a/gcc/tree-ssa-loop-im.c b/gcc/tree-ssa-loop-im.c
index f87c287d742..139c7e76e66 100644
--- a/gcc/tree-ssa-loop-im.c
+++ b/gcc/tree-ssa-loop-im.c
@@ -2232,9 +2232,11 @@  sm_seq_push_down (vec<seq_entry> &seq, unsigned ptr, unsigned *at)
 	  || (against.second == sm_other && against.from != NULL_TREE))
 	/* Found the tail of the sequence.  */
 	break;
-      if (!refs_independent_p (memory_accesses.refs_list[new_cand.first],
-			       memory_accesses.refs_list[against.first],
-			       false))
+      /* We may not ignore self-dependences here.  */
+      if (new_cand.first == against.first
+	  || !refs_independent_p (memory_accesses.refs_list[new_cand.first],
+				  memory_accesses.refs_list[against.first],
+				  false))
 	/* ???  Prune new_cand from the list of refs to apply SM to.  */
 	return false;
       std::swap (new_cand, against);