public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-10681] tree-optimization/108821 - store motion and volatiles
@ 2023-05-02 13:24 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2023-05-02 13:24 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:bd0192968999661d103bb9d974a8ad3be4ef3d9b

commit r11-10681-gbd0192968999661d103bb9d974a8ad3be4ef3d9b
Author: Richard Biener <rguenther@suse.de>
Date:   Fri Feb 17 12:36:44 2023 +0100

    tree-optimization/108821 - store motion and volatiles
    
    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.c (sm_seq_valid_bb): We can also not
            move volatile accesses.
    
            * gcc.dg/tree-ssa/ssa-lim-24.c: New testcase.
    
    (cherry picked from commit 4c4f0f7acd6b96ee744ef598cbea5c7046a33654)

Diff:
---
 gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-24.c | 25 +++++++++++++++++++++++++
 gcc/tree-ssa-loop-im.c                     |  8 ++++++++
 2 files changed, 33 insertions(+)

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
index 00000000000..6b463490a91
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-24.c
@@ -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" } } */
diff --git a/gcc/tree-ssa-loop-im.c b/gcc/tree-ssa-loop-im.c
index 8b1b1b2bede..8ee6c1aca12 100644
--- a/gcc/tree-ssa-loop-im.c
+++ b/gcc/tree-ssa-loop-im.c
@@ -2463,6 +2463,14 @@ sm_seq_valid_bb (class loop *loop, basic_block bb, tree vdef,
       gcc_assert (data);
       if (data->ref == UNANALYZABLE_MEM_ID)
 	return -1;
+      /* Stop at memory references which we can't move.  */
+      else if (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);
+	  return 1;
+	}
       /* One of the stores we want to apply SM to and we've not yet seen.  */
       else if (bitmap_clear_bit (refs_not_in_seq, data->ref))
 	{

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

only message in thread, other threads:[~2023-05-02 13:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-02 13:24 [gcc r11-10681] tree-optimization/108821 - store motion and volatiles 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).