tree-optimization/95295 - fix wrong-code with SM
authorRichard Biener <rguenther@suse.de>
Mon, 25 May 2020 08:09:44 +0000 (10:09 +0200)
committerRichard Biener <rguenther@suse.de>
Mon, 25 May 2020 11:39:26 +0000 (13:39 +0200)
We failed to compare the rematerialized store values when merging
paths after walking PHIs.

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

PR tree-optimization/95295
* tree-ssa-loop-im.c (sm_seq_valid_bb): Compare remat stores
RHSes and drop to full sm_other if they are not equal.

* gcc.dg/torture/pr95295-1.c: New testcase.
* gcc.dg/torture/pr95295-2.c: Likewise.
* gcc.dg/torture/pr95283.c: Likewise.

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr95283.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/pr95295-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/pr95295-2.c [new file with mode: 0644]
gcc/tree-ssa-loop-im.c

index 1e037dabe4974b15e3a8a56d2a04577803f29eb1..150dc096c7a63b0c15998e78f80a20d20d1f51bf 100644 (file)
@@ -1,3 +1,9 @@
+2020-05-25  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/95295
+       * tree-ssa-loop-im.c (sm_seq_valid_bb): Compare remat stores
+       RHSes and drop to full sm_other if they are not equal.
+
 2020-05-25  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/95271
index abe0f32be3e464a0de086bb5e818770a39519a75..cba153f166e73f9076c66713a0b9055c1d89137f 100644 (file)
@@ -1,3 +1,10 @@
+2020-05-25  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/95295
+       * gcc.dg/torture/pr95295-1.c: New testcase.
+       * gcc.dg/torture/pr95295-2.c: Likewise.
+       * gcc.dg/torture/pr95283.c: Likewise.
+
 2020-05-25  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/95271
diff --git a/gcc/testsuite/gcc.dg/torture/pr95283.c b/gcc/testsuite/gcc.dg/torture/pr95283.c
new file mode 100644 (file)
index 0000000..950d3b0
--- /dev/null
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+
+short c;
+_Bool d;
+unsigned e, f;
+char g, h;
+extern _Bool i[];
+void j()
+{
+  for (char a = 0; a < 100; a++)
+    for (char b = 0; b < 20; b += 2)
+      {
+       if (e)
+         d = f = 0;
+       else
+         g = i[8] = 0;
+       h = c;
+      }
+}
diff --git a/gcc/testsuite/gcc.dg/torture/pr95295-1.c b/gcc/testsuite/gcc.dg/torture/pr95295-1.c
new file mode 100644 (file)
index 0000000..76a19f3
--- /dev/null
@@ -0,0 +1,15 @@
+/* { dg-do run } */
+/* { dg-additional-sources "pr95295-2.c" } */
+
+extern int var_4, a;
+extern unsigned var_9;
+extern short arr_272[];
+void test()
+{
+  for (int b = 0; b < 9; b++)
+    for (int c = 0; c < 9; c += 4)
+      {
+       arr_272[c] = var_9 ? var_4 : 0;
+       a = 0;
+      }
+}
diff --git a/gcc/testsuite/gcc.dg/torture/pr95295-2.c b/gcc/testsuite/gcc.dg/torture/pr95295-2.c
new file mode 100644 (file)
index 0000000..80caeb8
--- /dev/null
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+
+int a;
+int var_4 = 1;
+unsigned var_9 = 8;
+short arr_272[20];
+void test();
+int main()
+{
+  test();
+  if (arr_272[4] != 1)
+    __builtin_abort ();
+  return 0;
+}
index fcca099355a797efd6533edd354c21a36d23212d..b399bd0f7297f8b822383b6176f62cc42a325ceb 100644 (file)
@@ -2402,6 +2402,7 @@ sm_seq_valid_bb (class loop *loop, basic_block bb, tree vdef,
                      if (edge_seq[i].second == sm_ord)
                        bitmap_set_bit (refs_not_supported, edge_seq[i].first);
                      first_edge_seq[i].second = sm_other;
+                     first_edge_seq[i].from = NULL_TREE;
                    }
                  /* sm_other prevails.  */
                  else if (first_edge_seq[i].second != edge_seq[i].second)
@@ -2410,7 +2411,14 @@ sm_seq_valid_bb (class loop *loop, basic_block bb, tree vdef,
                      gcc_assert (bitmap_bit_p (refs_not_supported,
                                                first_edge_seq[i].first));
                      first_edge_seq[i].second = sm_other;
+                     first_edge_seq[i].from = NULL_TREE;
                    }
+                 else if (first_edge_seq[i].second == sm_other
+                          && first_edge_seq[i].from != NULL_TREE
+                          && (edge_seq[i].from == NULL_TREE
+                              || !operand_equal_p (first_edge_seq[i].from,
+                                                   edge_seq[i].from, 0)))
+                   first_edge_seq[i].from = NULL_TREE;
                }
              /* Any excess elements become sm_other since they are now
                 coonditionally executed.  */