tree-optimization/108821 - store motion and volatiles
authorRichard Biener <rguenther@suse.de>
Fri, 17 Feb 2023 11:36:44 +0000 (12:36 +0100)
committerRichard Biener <rguenther@suse.de>
Fri, 17 Feb 2023 11:36:44 +0000 (12:36 +0100)
The following fixes store motion to not re-issue volatile stores
to preserve TBAA behavior since that will result in the number
of volatile accesses changing.

PR tree-optimization/108821
* tree-ssa-loop-im.cc (sm_seq_valid_bb): We can also not
move volatile accesses.

* gcc.dg/tree-ssa/ssa-lim-24.c: New testcase.

gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-24.c [new file with mode: 0644]
gcc/tree-ssa-loop-im.cc

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-24.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-24.c
new file mode 100644 (file)
index 0000000..6b46349
--- /dev/null
@@ -0,0 +1,25 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-lim2-details -fdump-tree-optimized" } */
+
+extern volatile int *x;
+static int gCrc;
+
+static int __attribute__((noinline)) crc16Add(int crc, int b)
+{
+  return crc + b;
+}
+
+void f(int data, int dataSz)
+{
+  int i;
+
+  for(i=0;i<dataSz;i++)
+  {
+    gCrc = crc16Add(gCrc, data);
+    *x = data;
+  }
+}
+
+/* { dg-final { scan-tree-dump "Executing store motion of gCrc" "lim2" } } */
+/* { dg-final { scan-tree-dump-not "Re-issueing" "lim2" } } */
+/* { dg-final { scan-tree-dump-times "\\*x" 1 "optimized" } } */
index 784f6f0..86ce6ac 100644 (file)
@@ -2605,7 +2605,9 @@ sm_seq_valid_bb (class loop *loop, basic_block bb, tree vdef,
       if (data->ref == UNANALYZABLE_MEM_ID)
        return -1;
       /* Stop at memory references which we can't move.  */
-      else if (memory_accesses.refs_list[data->ref]->mem.ref == error_mark_node)
+      else if (memory_accesses.refs_list[data->ref]->mem.ref == error_mark_node
+              || TREE_THIS_VOLATILE
+                   (memory_accesses.refs_list[data->ref]->mem.ref))
        {
          /* Mark refs_not_in_seq as unsupported.  */
          bitmap_ior_into (refs_not_supported, refs_not_in_seq);