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 <era...@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