Hi, This patch allows variables whose type transitively contains a union to share stack slots ...
13 years, 8 months ago
(2011-04-20 00:42:13 UTC)
#1
Hi,
This patch allows variables whose type transitively contains a union to share
stack slots if -fno-strict-aliasing is used.
Bootstraps on x86_64 with no test regressions. Also tested by changing
flag_strict_aliasing to 0 by default. Bootstraps and no test regressions when
compared to flag_strict_aliasing=0 without this patch.
OK for trunk?
-Easwaran
2011-04-19 Easwaran Raman <eraman@google.com>
* gcc/testsuite/gcc.dg/stack-layout-1.c: New
* gcc/cfgexpand.c (add_alias_set_conflicts): Add conflicts
with a variable containing union type only with
-fstrict-aliasing.
Index: gcc/testsuite/gcc.dg/stack-layout-1.c
===================================================================
--- gcc/testsuite/gcc.dg/stack-layout-1.c (revision 0)
+++ gcc/testsuite/gcc.dg/stack-layout-1.c (revision 0)
@@ -0,0 +1,25 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-strict-aliasing -fdump-rtl-expand" } */
+union U {
+ int a;
+ float b;
+};
+struct A {
+ union U u1;
+ char a[100];
+};
+void bar (struct A *);
+void foo ()
+ {
+ {
+ struct A a;
+ bar (&a);
+ }
+ {
+ struct A a;
+ bar (&a);
+ }
+ }
+
+/* { dg-final { scan-rtl-dump-times "Partition" 1 "expand" } } */
+/* { dg-final { cleanup-rtl-dump "expand" } } */
Index: gcc/cfgexpand.c
===================================================================
--- gcc/cfgexpand.c (revision 172657)
+++ gcc/cfgexpand.c (working copy)
@@ -373,8 +373,9 @@ add_alias_set_conflicts (void)
to elements will conflict. In case of unions we have
to be careful as type based aliasing rules may say
access to the same memory does not conflict. So play
- safe and add a conflict in this case. */
- || contains_union)
+ safe and add a conflict in this case when
+ -fstrict-aliasing is used. */
+ || (contains_union && flag_strict_aliasing))
add_stack_var_conflict (i, j);
}
}
--
This patch is available for review at http://codereview.appspot.com/4444051
On Wed, Apr 20, 2011 at 2:42 AM, Easwaran Raman <eraman@google.com> wrote: > Hi, > ...
13 years, 8 months ago
(2011-04-20 09:07:04 UTC)
#2
On Wed, Apr 20, 2011 at 2:42 AM, Easwaran Raman <eraman@google.com> wrote:
> Hi,
> This patch allows variables whose type transitively contains a union to
share stack slots if -fno-strict-aliasing is used.
>
> Bootstraps on x86_64 with no test regressions. Also tested by changing
flag_strict_aliasing to 0 by default. Bootstraps and no test regressions when
compared to flag_strict_aliasing=0 without this patch.
>
> OK for trunk?
Ok.
Thanks,
Richard.
> -Easwaran
>
> 2011-04-19 Easwaran Raman <eraman@google.com>
>
> * gcc/testsuite/gcc.dg/stack-layout-1.c: New
> * gcc/cfgexpand.c (add_alias_set_conflicts): Add conflicts
> with a variable containing union type only with
> -fstrict-aliasing.
>
> Index: gcc/testsuite/gcc.dg/stack-layout-1.c
> ===================================================================
> --- gcc/testsuite/gcc.dg/stack-layout-1.c (revision 0)
> +++ gcc/testsuite/gcc.dg/stack-layout-1.c (revision 0)
> @@ -0,0 +1,25 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -fno-strict-aliasing -fdump-rtl-expand" } */
> +union U {
> + int a;
> + float b;
> +};
> +struct A {
> + union U u1;
> + char a[100];
> +};
> +void bar (struct A *);
> +void foo ()
> + {
> + {
> + struct A a;
> + bar (&a);
> + }
> + {
> + struct A a;
> + bar (&a);
> + }
> + }
> +
> +/* { dg-final { scan-rtl-dump-times "Partition" 1 "expand" } } */
> +/* { dg-final { cleanup-rtl-dump "expand" } } */
> Index: gcc/cfgexpand.c
> ===================================================================
> --- gcc/cfgexpand.c (revision 172657)
> +++ gcc/cfgexpand.c (working copy)
> @@ -373,8 +373,9 @@ add_alias_set_conflicts (void)
> to elements will conflict. In case of unions we have
> to be careful as type based aliasing rules may say
> access to the same memory does not conflict. So play
> - safe and add a conflict in this case. */
> - || contains_union)
> + safe and add a conflict in this case when
> + -fstrict-aliasing is used. */
> + || (contains_union && flag_strict_aliasing))
> add_stack_var_conflict (i, j);
> }
> }
>
> --
> This patch is available for review at http://codereview.appspot.com/4444051
>
13 years, 8 months ago
(2011-04-20 09:18:40 UTC)
#3
> 2011-04-19 Easwaran Raman <eraman@google.com>
>
> * gcc/testsuite/gcc.dg/stack-layout-1.c: New
> * gcc/cfgexpand.c (add_alias_set_conflicts): Add conflicts
> with a variable containing union type only with
> -fstrict-aliasing.
You need an entry for each relevant ChangeLog, without prefixes:
2011-04-20 Easwaran Raman <eraman@google.com>
* cfgexpand.c (add_alias_set_conflicts): Add conflicts with a variable
containing union type only with -fstrict-aliasing.
2011-04-20 Easwaran Raman <eraman@google.com>
* gcc.dg/stack-layout-1.c: New test.
--
Eric Botcazou
On Wed, Apr 20, 2011 at 2:12 AM, Eric Botcazou <ebotcazou@adacore.com> wrote: >> 2011-04-19 Easwaran ...
13 years, 8 months ago
(2011-04-20 18:36:19 UTC)
#4
On Wed, Apr 20, 2011 at 2:12 AM, Eric Botcazou <ebotcazou@adacore.com> wrote:
>> 2011-04-19 Easwaran Raman <eraman@google.com>
>>
>> * gcc/testsuite/gcc.dg/stack-layout-1.c: New
>> * gcc/cfgexpand.c (add_alias_set_conflicts): Add conflicts
>> with a variable containing union type only with
>> -fstrict-aliasing.
>
> You need an entry for each relevant ChangeLog, without prefixes:
>
>
> 2011-04-20 Easwaran Raman <eraman@google.com>
>
> * cfgexpand.c (add_alias_set_conflicts): Add conflicts with a variable
> containing union type only with -fstrict-aliasing.
>
>
> 2011-04-20 Easwaran Raman <eraman@google.com>
>
> * gcc.dg/stack-layout-1.c: New test.
>
>
> --
> Eric Botcazou
>
Thanks. I've added them to the respective Changelog files and
committed the patch.
-Easwaran
Issue 4444051: Allow union variables to share stack slots wwith -fno-strict-aliasing
Created 13 years, 8 months ago by eraman
Modified 13 years, 8 months ago
Reviewers: richard.guenther_gmail.com, ebotcazou_adacore.com
Base URL: svn://gcc.gnu.org/svn/gcc/trunk/
Comments: 0