public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] tree-optimization/105971 - less surprising refs_may_alias_p_2
@ 2022-06-15 11:13 Richard Biener
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Biener @ 2022-06-15 11:13 UTC (permalink / raw)
  To: gcc-patches

When DSE asks whether __real a is using __imag a it gets a surprising
result when a is a FUNCTION_DECL.  The following makes sure this case
is less surprising to callers but keeping the bail-out for the
non-decl case where it is true that PTA doesn't track aliases to code
correctly.

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

2022-06-15  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/105971
	* tree-ssa-alias.cc (refs_may_alias_p_2): Put bail-out for
	FUNCTION_DECL and LABEL_DECL refs after decl-decl disambiguation
	to leak less surprising alias results.

	* gcc.dg/torture/pr106971.c: New testcase.
---
 gcc/testsuite/gcc.dg/torture/pr106971.c | 12 ++++++++++++
 gcc/tree-ssa-alias.cc                   | 18 +++++++++---------
 2 files changed, 21 insertions(+), 9 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr106971.c

diff --git a/gcc/testsuite/gcc.dg/torture/pr106971.c b/gcc/testsuite/gcc.dg/torture/pr106971.c
new file mode 100644
index 00000000000..33f21056e62
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr106971.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+
+void a()
+{
+  int b;
+  int c;
+  int d = (__INTPTR_TYPE__)a;
+  _Complex float *e = (_Complex float *)a;
+  for (;;) {
+    (*e += d) / b ?: 0;
+  }
+}
diff --git a/gcc/tree-ssa-alias.cc b/gcc/tree-ssa-alias.cc
index 063f1893851..b1e7a2d5afc 100644
--- a/gcc/tree-ssa-alias.cc
+++ b/gcc/tree-ssa-alias.cc
@@ -2397,15 +2397,6 @@ refs_may_alias_p_2 (ao_ref *ref1, ao_ref *ref2, bool tbaa_p)
       || CONSTANT_CLASS_P (base2))
     return false;
 
-  /* We can end up referring to code via function and label decls.
-     As we likely do not properly track code aliases conservatively
-     bail out.  */
-  if (TREE_CODE (base1) == FUNCTION_DECL
-      || TREE_CODE (base1) == LABEL_DECL
-      || TREE_CODE (base2) == FUNCTION_DECL
-      || TREE_CODE (base2) == LABEL_DECL)
-    return true;
-
   /* Two volatile accesses always conflict.  */
   if (ref1->volatile_p
       && ref2->volatile_p)
@@ -2432,6 +2423,15 @@ refs_may_alias_p_2 (ao_ref *ref1, ao_ref *ref2, bool tbaa_p)
 				  ref2ref, base2, offset2, max_size2,
 				  ref2->size);
 
+  /* We can end up referring to code via function and label decls.
+     As we likely do not properly track code aliases conservatively
+     bail out.  */
+  if (TREE_CODE (base1) == FUNCTION_DECL
+      || TREE_CODE (base1) == LABEL_DECL
+      || TREE_CODE (base2) == FUNCTION_DECL
+      || TREE_CODE (base2) == LABEL_DECL)
+    return true;
+
   /* Handle restrict based accesses.
      ???  ao_ref_base strips inner MEM_REF [&decl], recover from that
      here.  */
-- 
2.35.3

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] tree-optimization/105971 - less surprising refs_may_alias_p_2
@ 2022-06-15 11:13 Richard Biener
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Biener @ 2022-06-15 11:13 UTC (permalink / raw)
  To: gcc-patches

When DSE asks whether __real a is using __imag a it gets a surprising
result when a is a FUNCTION_DECL.  The following makes sure this case
is less surprising to callers but keeping the bail-out for the
non-decl case where it is true that PTA doesn't track aliases to code
correctly.

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

2022-06-15  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/105971
	* tree-ssa-alias.cc (refs_may_alias_p_2): Put bail-out for
	FUNCTION_DECL and LABEL_DECL refs after decl-decl disambiguation
	to leak less surprising alias results.

	* gcc.dg/torture/pr106971.c: New testcase.
---
 gcc/testsuite/gcc.dg/torture/pr106971.c | 12 ++++++++++++
 gcc/tree-ssa-alias.cc                   | 18 +++++++++---------
 2 files changed, 21 insertions(+), 9 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr106971.c

diff --git a/gcc/testsuite/gcc.dg/torture/pr106971.c b/gcc/testsuite/gcc.dg/torture/pr106971.c
new file mode 100644
index 00000000000..33f21056e62
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr106971.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+
+void a()
+{
+  int b;
+  int c;
+  int d = (__INTPTR_TYPE__)a;
+  _Complex float *e = (_Complex float *)a;
+  for (;;) {
+    (*e += d) / b ?: 0;
+  }
+}
diff --git a/gcc/tree-ssa-alias.cc b/gcc/tree-ssa-alias.cc
index 063f1893851..b1e7a2d5afc 100644
--- a/gcc/tree-ssa-alias.cc
+++ b/gcc/tree-ssa-alias.cc
@@ -2397,15 +2397,6 @@ refs_may_alias_p_2 (ao_ref *ref1, ao_ref *ref2, bool tbaa_p)
       || CONSTANT_CLASS_P (base2))
     return false;
 
-  /* We can end up referring to code via function and label decls.
-     As we likely do not properly track code aliases conservatively
-     bail out.  */
-  if (TREE_CODE (base1) == FUNCTION_DECL
-      || TREE_CODE (base1) == LABEL_DECL
-      || TREE_CODE (base2) == FUNCTION_DECL
-      || TREE_CODE (base2) == LABEL_DECL)
-    return true;
-
   /* Two volatile accesses always conflict.  */
   if (ref1->volatile_p
       && ref2->volatile_p)
@@ -2432,6 +2423,15 @@ refs_may_alias_p_2 (ao_ref *ref1, ao_ref *ref2, bool tbaa_p)
 				  ref2ref, base2, offset2, max_size2,
 				  ref2->size);
 
+  /* We can end up referring to code via function and label decls.
+     As we likely do not properly track code aliases conservatively
+     bail out.  */
+  if (TREE_CODE (base1) == FUNCTION_DECL
+      || TREE_CODE (base1) == LABEL_DECL
+      || TREE_CODE (base2) == FUNCTION_DECL
+      || TREE_CODE (base2) == LABEL_DECL)
+    return true;
+
   /* Handle restrict based accesses.
      ???  ao_ref_base strips inner MEM_REF [&decl], recover from that
      here.  */
-- 
2.35.3

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] tree-optimization/105971 - less surprising refs_may_alias_p_2
@ 2022-06-15 11:13 Richard Biener
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Biener @ 2022-06-15 11:13 UTC (permalink / raw)
  To: gcc-patches

When DSE asks whether __real a is using __imag a it gets a surprising
result when a is a FUNCTION_DECL.  The following makes sure this case
is less surprising to callers but keeping the bail-out for the
non-decl case where it is true that PTA doesn't track aliases to code
correctly.

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

2022-06-15  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/105971
	* tree-ssa-alias.cc (refs_may_alias_p_2): Put bail-out for
	FUNCTION_DECL and LABEL_DECL refs after decl-decl disambiguation
	to leak less surprising alias results.

	* gcc.dg/torture/pr106971.c: New testcase.
---
 gcc/testsuite/gcc.dg/torture/pr106971.c | 12 ++++++++++++
 gcc/tree-ssa-alias.cc                   | 18 +++++++++---------
 2 files changed, 21 insertions(+), 9 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr106971.c

diff --git a/gcc/testsuite/gcc.dg/torture/pr106971.c b/gcc/testsuite/gcc.dg/torture/pr106971.c
new file mode 100644
index 00000000000..33f21056e62
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr106971.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+
+void a()
+{
+  int b;
+  int c;
+  int d = (__INTPTR_TYPE__)a;
+  _Complex float *e = (_Complex float *)a;
+  for (;;) {
+    (*e += d) / b ?: 0;
+  }
+}
diff --git a/gcc/tree-ssa-alias.cc b/gcc/tree-ssa-alias.cc
index 063f1893851..b1e7a2d5afc 100644
--- a/gcc/tree-ssa-alias.cc
+++ b/gcc/tree-ssa-alias.cc
@@ -2397,15 +2397,6 @@ refs_may_alias_p_2 (ao_ref *ref1, ao_ref *ref2, bool tbaa_p)
       || CONSTANT_CLASS_P (base2))
     return false;
 
-  /* We can end up referring to code via function and label decls.
-     As we likely do not properly track code aliases conservatively
-     bail out.  */
-  if (TREE_CODE (base1) == FUNCTION_DECL
-      || TREE_CODE (base1) == LABEL_DECL
-      || TREE_CODE (base2) == FUNCTION_DECL
-      || TREE_CODE (base2) == LABEL_DECL)
-    return true;
-
   /* Two volatile accesses always conflict.  */
   if (ref1->volatile_p
       && ref2->volatile_p)
@@ -2432,6 +2423,15 @@ refs_may_alias_p_2 (ao_ref *ref1, ao_ref *ref2, bool tbaa_p)
 				  ref2ref, base2, offset2, max_size2,
 				  ref2->size);
 
+  /* We can end up referring to code via function and label decls.
+     As we likely do not properly track code aliases conservatively
+     bail out.  */
+  if (TREE_CODE (base1) == FUNCTION_DECL
+      || TREE_CODE (base1) == LABEL_DECL
+      || TREE_CODE (base2) == FUNCTION_DECL
+      || TREE_CODE (base2) == LABEL_DECL)
+    return true;
+
   /* Handle restrict based accesses.
      ???  ao_ref_base strips inner MEM_REF [&decl], recover from that
      here.  */
-- 
2.35.3

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-06-15 11:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-15 11:13 [PATCH] tree-optimization/105971 - less surprising refs_may_alias_p_2 Richard Biener
  -- strict thread matches above, loose matches on Subject: below --
2022-06-15 11:13 Richard Biener
2022-06-15 11:13 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).