tree-optimization/95295 - fix sinking after path merging in new SM code

Message ID nycvar.YFH.7.76.2005271456100.4397@zhemvz.fhfr.qr
State New
Headers show
Series
  • tree-optimization/95295 - fix sinking after path merging in new SM code
Related show

Commit Message

Richard Biener May 27, 2020, 12:56 p.m.
This fixes a missed sinking of remat stores across unrelated stores
after merging from different paths.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.

2020-05-27  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/95295
	* tree-ssa-loop-im.c (sm_seq_valid_bb): Fix sinking after
	merging stores from paths.

	* gcc.dg/torture/pr95295-3.c: New testcase.
---
 gcc/testsuite/gcc.dg/torture/pr95295-3.c | 16 ++++++++++++++++
 gcc/tree-ssa-loop-im.c                   |  8 ++++++--
 2 files changed, 22 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr95295-3.c

-- 
2.25.1

Patch

diff --git a/gcc/testsuite/gcc.dg/torture/pr95295-3.c b/gcc/testsuite/gcc.dg/torture/pr95295-3.c
new file mode 100644
index 00000000000..a506af9a63f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr95295-3.c
@@ -0,0 +1,16 @@ 
+/* { dg-do compile } */
+
+extern short var_15, var_20;
+extern int var_18, var_21, var_23;
+extern _Bool arr_2[];
+extern long arr_3[];
+void test()
+{
+  var_20 = 1;
+  for (int a = 0; a < 12; a += 2)
+    for (short b = 0; b < 8; b += 2) {
+      arr_2[b] = var_21 = var_18 ? var_15 : 0;
+      arr_3[b] = 8569;
+    }
+  var_23 = -1096835496;
+}
diff --git a/gcc/tree-ssa-loop-im.c b/gcc/tree-ssa-loop-im.c
index b399bd0f729..d33f5335e2b 100644
--- a/gcc/tree-ssa-loop-im.c
+++ b/gcc/tree-ssa-loop-im.c
@@ -2447,12 +2447,16 @@  sm_seq_valid_bb (class loop *loop, basic_block bb, tree vdef,
 	      unsigned id = first_edge_seq[i].first;
 	      seq.safe_push (first_edge_seq[i]);
 	      unsigned new_idx;
-	      if (first_edge_seq[i].second == sm_ord
+	      if ((first_edge_seq[i].second == sm_ord
+		   || (first_edge_seq[i].second == sm_other
+		       && first_edge_seq[i].from != NULL_TREE))
 		  && !sm_seq_push_down (seq, seq.length () - 1, &new_idx))
 		{
-		  bitmap_set_bit (refs_not_supported, id);
+		  if (first_edge_seq[i].second == sm_ord)
+		    bitmap_set_bit (refs_not_supported, id);
 		  /* Mark it sm_other.  */
 		  seq[new_idx].second = sm_other;
+		  seq[new_idx].from = NULL_TREE;
 		}
 	    }
 	  return 1;