public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] tree-optimization/100051 - disambiguate access size vs decl
@ 2021-04-13 12:33 Richard Biener
  2021-04-27 10:41 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Richard Biener @ 2021-04-13 12:33 UTC (permalink / raw)
  To: gcc-patches

This adds disambiguation of the access size vs. the decl size
in the pointer based vs. decl based disambiguator.  We have
a TBAA based check like this already but that's fend off when
seeing alias-sets of zero or when -fno-strict-aliasing is in
effect.  Also the perceived dynamic type could be smaller than
the actual access.

Bootstrapped and tested on x86_64-unknown-linux-gnu, queued for stage1.

2021-04-13  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/100051
	* tree-ssa-alias.c (indirect_ref_may_alias_decl_p): Add
	disambiguator based on access size vs. decl size.

	* gcc.dg/tree-ssa/ssa-fre-92.c: New testcase.
---
 gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-92.c | 21 +++++++++++++++++++++
 gcc/tree-ssa-alias.c                       | 11 +++++++++++
 2 files changed, 32 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-92.c

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-92.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-92.c
new file mode 100644
index 00000000000..c67fcea5e93
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-92.c
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-fre1" } */
+
+extern void foo(void);
+int a, c, *f, **d = &f;
+char b;
+int main()
+{
+  if (a) {
+    b = 0;
+    int *g = &c;
+    *g = 0;
+    f = *d;
+    *d = f;
+    if ((2 ^ b) == 0)
+      foo();
+  }
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump-not "foo" "fre1" } } */
diff --git a/gcc/tree-ssa-alias.c b/gcc/tree-ssa-alias.c
index ebb3f49c86c..6c7d2f1b7e0 100644
--- a/gcc/tree-ssa-alias.c
+++ b/gcc/tree-ssa-alias.c
@@ -2034,6 +2034,17 @@ indirect_ref_may_alias_decl_p (tree ref1 ATTRIBUTE_UNUSED, tree base1,
   if (TREE_CODE (base1) != TARGET_MEM_REF
       && !ranges_maybe_overlap_p (offset1 + moff, -1, offset2, max_size2))
     return false;
+
+  /* If the pointer based access is bigger than the variable they cannot
+     alias.  This is similar to the check below where we use TBAA to
+     increase the size of the pointer based access based on the dynamic
+     type of a containing object we can infer from it.  */
+  poly_int64 dsize2;
+  if (known_size_p (size1)
+      && poly_int_tree_p (DECL_SIZE (base2), &dsize2)
+      && known_lt (dsize2, size1))
+    return false;
+
   /* They also cannot alias if the pointer may not point to the decl.  */
   if (!ptr_deref_may_alias_decl_p (ptr1, base2))
     return false;
-- 
2.26.2

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

* Re: [PATCH] tree-optimization/100051 - disambiguate access size vs decl
  2021-04-13 12:33 [PATCH] tree-optimization/100051 - disambiguate access size vs decl Richard Biener
@ 2021-04-27 10:41 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2021-04-27 10:41 UTC (permalink / raw)
  To: Richard Biener; +Cc: GCC Patches

On Tue, Apr 13, 2021 at 3:50 PM Richard Biener <rguenther@suse.de> wrote:
>
> This adds disambiguation of the access size vs. the decl size
> in the pointer based vs. decl based disambiguator.  We have
> a TBAA based check like this already but that's fend off when
> seeing alias-sets of zero or when -fno-strict-aliasing is in
> effect.  Also the perceived dynamic type could be smaller than
> the actual access.
>
> Bootstrapped and tested on x86_64-unknown-linux-gnu, queued for stage1.

g:d1d01a66012a93cc8cb7dafbe1b5ec453ec96b59

> 2021-04-13  Richard Biener  <rguenther@suse.de>
>
>         PR tree-optimization/100051
>         * tree-ssa-alias.c (indirect_ref_may_alias_decl_p): Add
>         disambiguator based on access size vs. decl size.
>
>         * gcc.dg/tree-ssa/ssa-fre-92.c: New testcase.
> ---
>  gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-92.c | 21 +++++++++++++++++++++
>  gcc/tree-ssa-alias.c                       | 11 +++++++++++
>  2 files changed, 32 insertions(+)
>  create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-92.c
>
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-92.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-92.c
> new file mode 100644
> index 00000000000..c67fcea5e93
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-92.c
> @@ -0,0 +1,21 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -fdump-tree-fre1" } */
> +
> +extern void foo(void);
> +int a, c, *f, **d = &f;
> +char b;
> +int main()
> +{
> +  if (a) {
> +    b = 0;
> +    int *g = &c;
> +    *g = 0;
> +    f = *d;
> +    *d = f;
> +    if ((2 ^ b) == 0)
> +      foo();
> +  }
> +  return 0;
> +}
> +
> +/* { dg-final { scan-tree-dump-not "foo" "fre1" } } */
> diff --git a/gcc/tree-ssa-alias.c b/gcc/tree-ssa-alias.c
> index ebb3f49c86c..6c7d2f1b7e0 100644
> --- a/gcc/tree-ssa-alias.c
> +++ b/gcc/tree-ssa-alias.c
> @@ -2034,6 +2034,17 @@ indirect_ref_may_alias_decl_p (tree ref1 ATTRIBUTE_UNUSED, tree base1,
>    if (TREE_CODE (base1) != TARGET_MEM_REF
>        && !ranges_maybe_overlap_p (offset1 + moff, -1, offset2, max_size2))
>      return false;
> +
> +  /* If the pointer based access is bigger than the variable they cannot
> +     alias.  This is similar to the check below where we use TBAA to
> +     increase the size of the pointer based access based on the dynamic
> +     type of a containing object we can infer from it.  */
> +  poly_int64 dsize2;
> +  if (known_size_p (size1)
> +      && poly_int_tree_p (DECL_SIZE (base2), &dsize2)
> +      && known_lt (dsize2, size1))
> +    return false;
> +
>    /* They also cannot alias if the pointer may not point to the decl.  */
>    if (!ptr_deref_may_alias_decl_p (ptr1, base2))
>      return false;
> --
> 2.26.2

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

end of thread, other threads:[~2021-04-27 10:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-13 12:33 [PATCH] tree-optimization/100051 - disambiguate access size vs decl Richard Biener
2021-04-27 10:41 ` 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).