public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] tree-optimization/115236 - more points-to *ANYTHING = x fixes
@ 2024-05-28 12:35 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2024-05-28 12:35 UTC (permalink / raw)
  To: gcc-patches

The stored-to ANYTHING handling has more holes, uncovered by treating
volatile accesses as ANYTHING.  We fail to properly build the
pred and succ graphs, in particular we may not elide direct nodes
from receiving from STOREDANYTHING.

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

	PR tree-optimization/115236
	* tree-ssa-structalias.cc (build_pred_graph): Properly
	handle *ANYTHING = X.
	(build_succ_graph): Likewise.  Do not elide direct nodes
	from receiving from STOREDANYTHING.

	* gcc.dg/pr115236.c: New testcase.
---
 gcc/testsuite/gcc.dg/pr115236.c | 12 ++++++++++++
 gcc/tree-ssa-structalias.cc     | 20 ++++++++++++++------
 2 files changed, 26 insertions(+), 6 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr115236.c

diff --git a/gcc/testsuite/gcc.dg/pr115236.c b/gcc/testsuite/gcc.dg/pr115236.c
new file mode 100644
index 00000000000..91edfab957a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr115236.c
@@ -0,0 +1,12 @@
+/* { dg-do run } */
+/* { dg-options "-O -fno-tree-fre" } */
+
+int a, *b = &a;
+int main()
+{
+  int *c, *volatile *d = &c;
+  *d = b;
+  if (c != &a)
+    __builtin_abort();
+  return 0;
+}
diff --git a/gcc/tree-ssa-structalias.cc b/gcc/tree-ssa-structalias.cc
index 9cec2c6cfd9..330e64e65da 100644
--- a/gcc/tree-ssa-structalias.cc
+++ b/gcc/tree-ssa-structalias.cc
@@ -1312,7 +1312,12 @@ build_pred_graph (void)
 	{
 	  /* *x = y.  */
 	  if (rhs.offset == 0 && lhs.offset == 0 && rhs.type == SCALAR)
-	    add_pred_graph_edge (graph, FIRST_REF_NODE + lhsvar, rhsvar);
+	    {
+	      if (lhs.var == anything_id)
+		add_pred_graph_edge (graph, storedanything_id, rhsvar);
+	      else
+		add_pred_graph_edge (graph, FIRST_REF_NODE + lhsvar, rhsvar);
+	    }
 	}
       else if (rhs.type == DEREF)
 	{
@@ -1398,7 +1403,12 @@ build_succ_graph (void)
       if (lhs.type == DEREF)
 	{
 	  if (rhs.offset == 0 && lhs.offset == 0 && rhs.type == SCALAR)
-	    add_graph_edge (graph, FIRST_REF_NODE + lhsvar, rhsvar);
+	    {
+	      if (lhs.var == anything_id)
+		add_graph_edge (graph, storedanything_id, rhsvar);
+	      else
+		add_graph_edge (graph, FIRST_REF_NODE + lhsvar, rhsvar);
+	    }
 	}
       else if (rhs.type == DEREF)
 	{
@@ -1418,13 +1428,11 @@ build_succ_graph (void)
 	}
     }
 
-  /* Add edges from STOREDANYTHING to all non-direct nodes that can
-     receive pointers.  */
+  /* Add edges from STOREDANYTHING to all nodes that can receive pointers.  */
   t = find (storedanything_id);
   for (i = integer_id + 1; i < FIRST_REF_NODE; ++i)
     {
-      if (!bitmap_bit_p (graph->direct_nodes, i)
-	  && get_varinfo (i)->may_have_pointers)
+      if (get_varinfo (i)->may_have_pointers)
 	add_graph_edge (graph, find (i), t);
     }
 
-- 
2.35.3

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

only message in thread, other threads:[~2024-05-28 12:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-28 12:35 [PATCH] tree-optimization/115236 - more points-to *ANYTHING = x fixes 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).