From: Richard Biener <rguenther@suse.de>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] tree-optimization/108821 - store motion and volatiles
Date: Fri, 17 Feb 2023 11:38:42 +0000 (UTC) [thread overview]
Message-ID: <20230217113842.kCnkGNuOKHtqu_TUAy82gnJ4mDmDBQopAagBFrGpj6Q@z> (raw)
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.
Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed to trunk.
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 | 25 ++++++++++++++++++++++
gcc/tree-ssa-loop-im.cc | 4 +++-
2 files changed, 28 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-24.c
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.cc b/gcc/tree-ssa-loop-im.cc
index 784f6f04e7d..86ce6acb023 100644
--- a/gcc/tree-ssa-loop-im.cc
+++ b/gcc/tree-ssa-loop-im.cc
@@ -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);
--
2.35.3
reply other threads:[~2023-02-17 11:38 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230217113842.kCnkGNuOKHtqu_TUAy82gnJ4mDmDBQopAagBFrGpj6Q@z \
--to=rguenther@suse.de \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).