public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] sra: Do not create zero sized accesses  (PR93776)
@ 2020-02-18 15:56 Martin Jambor
  2020-02-18 16:45 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Martin Jambor @ 2020-02-18 15:56 UTC (permalink / raw)
  To: GCC Patches; +Cc: Richard Biener

Hi,

SRA can get a bit confused with zero-sized accesses like the one in
the testcase.  Since there is nothing in the access, nothing is
scalarized, but we can get order of the structures wrong, which the
verifier is not happy about.

Fixed by simply ignoring such accesses.  Bootstrapped and tested on an
x86_64-linux.  OK for trunk?

Thanks,

Martin

2020-02-18  Martin Jambor  <mjambor@suse.cz>

	PR tree-optimization/93776
	* tree-sra.c (create_access): Do not create zero size accesses.
	(get_access_for_expr): Do not search for zero sized accesses.

	testsuite/
	* gcc.dg/tree-ssa/pr93776.c: New test.
---
 gcc/ChangeLog                           |  6 ++++++
 gcc/testsuite/ChangeLog                 |  5 +++++
 gcc/testsuite/gcc.dg/tree-ssa/pr93776.c | 27 +++++++++++++++++++++++++
 gcc/tree-sra.c                          |  5 ++++-
 4 files changed, 42 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr93776.c

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr93776.c b/gcc/testsuite/gcc.dg/tree-ssa/pr93776.c
new file mode 100644
index 00000000000..c407a627718
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr93776.c
@@ -0,0 +1,27 @@
+/* { dg-do compile } */
+/* { dg-options "-O1" } */
+
+struct empty {};
+struct s { int i; };
+struct z
+{
+  int j;
+  struct empty e;
+  struct s s;
+  int k;
+};
+
+void bar (struct z);
+void baz (int);
+
+void foo (void)
+{
+  struct z z, z2;
+
+  z.k = 8;
+  z2.s.i = 1;
+  z = z2;
+  bar (z);
+  z.e = (struct empty) {};
+  baz (z.k);
+}
diff --git a/gcc/tree-sra.c b/gcc/tree-sra.c
index 0cfac0a8192..2c717805b68 100644
--- a/gcc/tree-sra.c
+++ b/gcc/tree-sra.c
@@ -926,6 +926,8 @@ create_access (tree expr, gimple *stmt, bool write)
       size = max_size;
       unscalarizable_region = true;
     }
+  if (size == 0)
+    return NULL;
   if (size < 0)
     {
       disqualify_candidate (base, "Encountered an unconstrained access.");
@@ -3629,7 +3631,8 @@ get_access_for_expr (tree expr)
 	return NULL;
     }
 
-  if (!bitmap_bit_p (candidate_bitmap, DECL_UID (base)))
+  if (max_size == 0
+      || !bitmap_bit_p (candidate_bitmap, DECL_UID (base)))
     return NULL;
 
   return get_var_base_offset_size_access (base, offset, max_size);
-- 
2.25.0

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

* Re: [PATCH] sra: Do not create zero sized accesses  (PR93776)
  2020-02-18 15:56 [PATCH] sra: Do not create zero sized accesses (PR93776) Martin Jambor
@ 2020-02-18 16:45 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2020-02-18 16:45 UTC (permalink / raw)
  To: Martin Jambor, GCC Patches

On February 18, 2020 4:56:35 PM GMT+01:00, Martin Jambor <mjambor@suse.cz> wrote:
>Hi,
>
>SRA can get a bit confused with zero-sized accesses like the one in
>the testcase.  Since there is nothing in the access, nothing is
>scalarized, but we can get order of the structures wrong, which the
>verifier is not happy about.
>
>Fixed by simply ignoring such accesses.  Bootstrapped and tested on an
>x86_64-linux.  OK for trunk?

Ok. 

Richard. 

>Thanks,
>
>Martin
>
>2020-02-18  Martin Jambor  <mjambor@suse.cz>
>
>	PR tree-optimization/93776
>	* tree-sra.c (create_access): Do not create zero size accesses.
>	(get_access_for_expr): Do not search for zero sized accesses.
>
>	testsuite/
>	* gcc.dg/tree-ssa/pr93776.c: New test.
>---
> gcc/ChangeLog                           |  6 ++++++
> gcc/testsuite/ChangeLog                 |  5 +++++
> gcc/testsuite/gcc.dg/tree-ssa/pr93776.c | 27 +++++++++++++++++++++++++
> gcc/tree-sra.c                          |  5 ++++-
> 4 files changed, 42 insertions(+), 1 deletion(-)
> create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr93776.c
>
>diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr93776.c
>b/gcc/testsuite/gcc.dg/tree-ssa/pr93776.c
>new file mode 100644
>index 00000000000..c407a627718
>--- /dev/null
>+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr93776.c
>@@ -0,0 +1,27 @@
>+/* { dg-do compile } */
>+/* { dg-options "-O1" } */
>+
>+struct empty {};
>+struct s { int i; };
>+struct z
>+{
>+  int j;
>+  struct empty e;
>+  struct s s;
>+  int k;
>+};
>+
>+void bar (struct z);
>+void baz (int);
>+
>+void foo (void)
>+{
>+  struct z z, z2;
>+
>+  z.k = 8;
>+  z2.s.i = 1;
>+  z = z2;
>+  bar (z);
>+  z.e = (struct empty) {};
>+  baz (z.k);
>+}
>diff --git a/gcc/tree-sra.c b/gcc/tree-sra.c
>index 0cfac0a8192..2c717805b68 100644
>--- a/gcc/tree-sra.c
>+++ b/gcc/tree-sra.c
>@@ -926,6 +926,8 @@ create_access (tree expr, gimple *stmt, bool write)
>       size = max_size;
>       unscalarizable_region = true;
>     }
>+  if (size == 0)
>+    return NULL;
>   if (size < 0)
>     {
>   disqualify_candidate (base, "Encountered an unconstrained access.");
>@@ -3629,7 +3631,8 @@ get_access_for_expr (tree expr)
> 	return NULL;
>     }
> 
>-  if (!bitmap_bit_p (candidate_bitmap, DECL_UID (base)))
>+  if (max_size == 0
>+      || !bitmap_bit_p (candidate_bitmap, DECL_UID (base)))
>     return NULL;
> 
>   return get_var_base_offset_size_access (base, offset, max_size);

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

end of thread, other threads:[~2020-02-18 16:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-18 15:56 [PATCH] sra: Do not create zero sized accesses (PR93776) Martin Jambor
2020-02-18 16:45 ` 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).