* [PR 69355] Correct hole detection when total_scalarization fails
@ 2016-01-26 17:21 Martin Jambor
2016-01-27 8:37 ` Richard Biener
0 siblings, 1 reply; 2+ messages in thread
From: Martin Jambor @ 2016-01-26 17:21 UTC (permalink / raw)
To: GCC Patches; +Cc: Richard Biener
Hi,
PR 69355 has revealed that when SRA attempts total scalarization of an
aggregate but this fails because the user type-casts a scalar field
and stores into a it a smaller aggregate (and the scalar field is not
written to, whether directly or as a part of an aggregate store), the
pass can loose track of unscalarized data there.
I think that this can happen only when violating strict aliasing rules
but with -fno-strict-aliasing it should work.
Fixed thusly with the patch below (the condition is there to avoid
detecting padding after aggregate-fields in totally-scalarized
aggregates as unscalarized data). Bootstrapped and tested on
x86_64-linux. OK for trunk? And the gcc-5 branch?
Thanks,
Martin
2016-01-26 Martin Jambor <mjambor@suse.cz>
PR tree-optimization/69355
* tree-sra.c (analyze_access_subtree): Correct hole detection when
total_scalarization fails.
testsuite/
* gcc.dg/tree-ssa/pr69355.c: New test.
---
gcc/testsuite/gcc.dg/tree-ssa/pr69355.c | 44 +++++++++++++++++++++++++++++++++
gcc/tree-sra.c | 2 +-
2 files changed, 45 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr69355.c
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr69355.c b/gcc/testsuite/gcc.dg/tree-ssa/pr69355.c
new file mode 100644
index 0000000..f515c21
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr69355.c
@@ -0,0 +1,44 @@
+/* { dg-do run } */
+/* { dg-options "-O -fno-strict-aliasing" } */
+
+struct S
+{
+ void *a;
+ long double b;
+};
+
+struct Z
+{
+ long long l;
+ short s;
+} __attribute__((packed));
+
+struct S __attribute__((noclone, noinline))
+foo (void *v, struct Z *z)
+{
+ struct S t;
+ t.a = v;
+ *(struct Z *) &t.b = *z;
+ return t;
+}
+
+struct Z gz;
+
+int
+main (int argc, char **argv)
+{
+ struct S s;
+
+ if (sizeof (long double) < sizeof (struct Z))
+ return 0;
+
+ gz.l = 0xbeef;
+ gz.s = 0xab;
+
+ s = foo ((void *) 0, &gz);
+
+ if ((((struct Z *) &s.b)->l != gz.l)
+ || (((struct Z *) &s.b)->s != gz.s))
+ __builtin_abort ();
+ return 0;
+}
diff --git a/gcc/tree-sra.c b/gcc/tree-sra.c
index 740542f..b0e737a 100644
--- a/gcc/tree-sra.c
+++ b/gcc/tree-sra.c
@@ -2421,7 +2421,7 @@ analyze_access_subtree (struct access *root, struct access *parent,
if (covered_to < limit)
hole = true;
- if (scalar)
+ if (scalar || !allow_replacements)
root->grp_total_scalarization = 0;
}
--
2.7.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PR 69355] Correct hole detection when total_scalarization fails
2016-01-26 17:21 [PR 69355] Correct hole detection when total_scalarization fails Martin Jambor
@ 2016-01-27 8:37 ` Richard Biener
0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2016-01-27 8:37 UTC (permalink / raw)
To: Martin Jambor; +Cc: GCC Patches
On Tue, 26 Jan 2016, Martin Jambor wrote:
> Hi,
>
> PR 69355 has revealed that when SRA attempts total scalarization of an
> aggregate but this fails because the user type-casts a scalar field
> and stores into a it a smaller aggregate (and the scalar field is not
> written to, whether directly or as a part of an aggregate store), the
> pass can loose track of unscalarized data there.
>
> I think that this can happen only when violating strict aliasing rules
> but with -fno-strict-aliasing it should work.
>
> Fixed thusly with the patch below (the condition is there to avoid
> detecting padding after aggregate-fields in totally-scalarized
> aggregates as unscalarized data). Bootstrapped and tested on
> x86_64-linux. OK for trunk? And the gcc-5 branch?
Ok.
Thanks,
Richard.
> Thanks,
>
> Martin
>
>
> 2016-01-26 Martin Jambor <mjambor@suse.cz>
>
> PR tree-optimization/69355
> * tree-sra.c (analyze_access_subtree): Correct hole detection when
> total_scalarization fails.
>
> testsuite/
> * gcc.dg/tree-ssa/pr69355.c: New test.
>
> ---
> gcc/testsuite/gcc.dg/tree-ssa/pr69355.c | 44 +++++++++++++++++++++++++++++++++
> gcc/tree-sra.c | 2 +-
> 2 files changed, 45 insertions(+), 1 deletion(-)
> create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr69355.c
>
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr69355.c b/gcc/testsuite/gcc.dg/tree-ssa/pr69355.c
> new file mode 100644
> index 0000000..f515c21
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr69355.c
> @@ -0,0 +1,44 @@
> +/* { dg-do run } */
> +/* { dg-options "-O -fno-strict-aliasing" } */
> +
> +struct S
> +{
> + void *a;
> + long double b;
> +};
> +
> +struct Z
> +{
> + long long l;
> + short s;
> +} __attribute__((packed));
> +
> +struct S __attribute__((noclone, noinline))
> +foo (void *v, struct Z *z)
> +{
> + struct S t;
> + t.a = v;
> + *(struct Z *) &t.b = *z;
> + return t;
> +}
> +
> +struct Z gz;
> +
> +int
> +main (int argc, char **argv)
> +{
> + struct S s;
> +
> + if (sizeof (long double) < sizeof (struct Z))
> + return 0;
> +
> + gz.l = 0xbeef;
> + gz.s = 0xab;
> +
> + s = foo ((void *) 0, &gz);
> +
> + if ((((struct Z *) &s.b)->l != gz.l)
> + || (((struct Z *) &s.b)->s != gz.s))
> + __builtin_abort ();
> + return 0;
> +}
> diff --git a/gcc/tree-sra.c b/gcc/tree-sra.c
> index 740542f..b0e737a 100644
> --- a/gcc/tree-sra.c
> +++ b/gcc/tree-sra.c
> @@ -2421,7 +2421,7 @@ analyze_access_subtree (struct access *root, struct access *parent,
>
> if (covered_to < limit)
> hole = true;
> - if (scalar)
> + if (scalar || !allow_replacements)
> root->grp_total_scalarization = 0;
> }
>
>
--
Richard Biener <rguenther@suse.de>
SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nuernberg)
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-01-27 8:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-26 17:21 [PR 69355] Correct hole detection when total_scalarization fails Martin Jambor
2016-01-27 8:37 ` 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).