From 63d7ceaaba06f2b35d82e1e62fc9b8f2fe474857 Mon Sep 17 00:00:00 2001 From: Richard Guenther Date: Tue, 31 Jan 2012 09:46:29 +0000 Subject: [PATCH] re PR tree-optimization/51528 (SRA should not create BOOLEAN_TYPE replacements) 2012-01-31 Richard Guenther PR tree-optimization/51528 * tree-sra.c (sra_modify_assign): Avoid copy-in/out for aggregate assigns. * gcc.dg/torture/pr51528.c: New testcase. From-SVN: r183752 --- gcc/ChangeLog | 6 ++++ gcc/testsuite/ChangeLog | 5 +++ gcc/testsuite/gcc.dg/torture/pr51528.c | 46 ++++++++++++++++++++++++++ gcc/tree-sra.c | 9 +++-- 4 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr51528.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d451dcc193f..ce93b26a768 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2012-01-31 Richard Guenther + + PR tree-optimization/51528 + * tree-sra.c (sra_modify_assign): Avoid copy-in/out for aggregate + assigns. + 2012-01-31 Jakub Jelinek PR bootstrap/52041 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index da42f22950c..77c86391983 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2012-01-31 Richard Guenther + + PR tree-optimization/51528 + * gcc.dg/torture/pr51528.c: New testcase. + 2012-01-30 Uros Bizjak PR go/48501 diff --git a/gcc/testsuite/gcc.dg/torture/pr51528.c b/gcc/testsuite/gcc.dg/torture/pr51528.c new file mode 100644 index 00000000000..db5f3e0cadd --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr51528.c @@ -0,0 +1,46 @@ +/* { dg-do run } */ +/* { dg-options "-fno-early-inlining" } */ + +extern void abort (void); + +union U +{ + int i; + _Bool b; +}; + +_Bool gb; + +void __attribute__ ((noinline)) +use_bool (union U u) +{ + gb = u.b; +} + +union U +bar (void) +{ + union U u; + u.i = 0xFFFE; + return u; +} + +union U __attribute__ ((noinline)) +foo (void) +{ + union U u,v; + + u.b = 1; + use_bool (u); + u = bar (); + + return u; +} + +int main (int argc, char **argv) +{ + union U u = foo (); + if (u.i != 0xFFFE) + abort (); + return 0; +} diff --git a/gcc/tree-sra.c b/gcc/tree-sra.c index ef268943434..e3bf38230dc 100644 --- a/gcc/tree-sra.c +++ b/gcc/tree-sra.c @@ -3135,9 +3135,14 @@ sra_modify_assign (gimple *stmt, gimple_stmt_iterator *gsi) sra_stats.deleted++; return SRA_AM_REMOVED; } + /* Restore the aggregate RHS from its components so the + prevailing aggregate copy does the right thing. */ if (access_has_children_p (racc)) - generate_subtree_copies (racc->first_child, lhs, racc->offset, - 0, 0, gsi, false, true, loc); + generate_subtree_copies (racc->first_child, racc->base, 0, 0, 0, + gsi, false, false, loc); + /* Re-load the components of the aggregate copy destination. + But use the RHS aggregate to load from to expose more + optimization opportunities. */ if (access_has_children_p (lacc)) generate_subtree_copies (lacc->first_child, rhs, lacc->offset, 0, 0, gsi, true, true, loc);