Bug 36598 - Failed optimisation of return of struct argment in memcpy-1.c
Summary: Failed optimisation of return of struct argment in memcpy-1.c
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
: 39245 (view as bug list)
Depends on: 14295
  Show dependency treegraph
Reported: 2008-06-22 13:26 UTC by Andy Hutchinson
Modified: 2012-06-06 10:15 UTC (History)
5 users (show)

See Also:
Host: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2009-02-20 19:49:15


Note You need to log in before you can comment on or make changes to this bug.
Description Andy Hutchinson 2008-06-22 13:26:04 UTC
Testcase gcc.dg/memcpy-1.c fails on AVR target.

Failure occurs because the return value is not simplified to avoid memcpy. This test works on i686 and I can't see why same optimization should not apply to AVR

Test is:

/* { dg-do compile } */
/* { dg-options "-O2 -fdump-tree-optimized" } */
/* { dg-final { scan-tree-dump-times "nasty_local" 0 "optimized" } } */
/* { dg-final { cleanup-tree-dump "optimized" } } */
struct a {int a,b,c;} a;
int test(struct a a)
struct a nasty_local;
__builtin_memcpy (&nasty_local,&a, sizeof(a));
return nasty_local.a;

On i686 we get:

;; Function test (test)

Analyzing Edge Insertions.
test (struct a a)
<bb 2>:
  return a.a;


BUT on AVR we get:

;; Function test (test)

Analyzing Edge Insertions.
test (struct a a)
  struct a nasty_local;

<bb 2>:
  nasty_local = a;
  return nasty_local.a;


I have confirmed the final AVR code is suboptimal.
Comment 1 joseph@codesourcery.com 2008-06-22 13:32:56 UTC
Subject: Re:   New: Failed optimisation of return of struct
 argment in memcpy-1.c

On Sun, 22 Jun 2008, hutchinsonandy at gcc dot gnu dot org wrote:

> Testcase gcc.dg/memcpy-1.c fails on AVR target.

Have you looked at bug 31677 which suggests using the option "--param 
sra-max-structure-size=32"?  If that works for AVR, you could submit a 
patch to add it to the testcase for all targets.

Comment 2 Andy Hutchinson 2008-06-22 14:33:03 UTC
Thanks for information

--param sra-max-structure-size=32 does indeed remove test failure and produces optimal code.

But changing the testcase does not remove the optimization problem - unless sra-max-structure-size was always used. So there is problem somewhere else to fix.

See also:


Comment 3 Richard Biener 2008-06-22 14:50:14 UTC
This is really not a task for SRA but for struct copy propagation (which we
do not do).  See PR14295.

As this testcase was for SRA you can either XFAIL it for avr or see if the
cost metrics need adjustment.
Comment 4 Andy Hutchinson 2008-06-22 16:11:38 UTC
Quite possibly due to cost metrics. They are far from ideal.

Will mark test XFAIL until we can investigate and fix.

Comment 5 Andy Hutchinson 2008-06-30 22:39:22 UTC
Subject: Bug 36598

Author: hutchinsonandy
Date: Mon Jun 30 22:38:34 2008
New Revision: 137298

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=137298
PR target/36598
* gcc.dg/memcpy-1.c: Mark test XFAIL for avr target.


Comment 6 John David Anglin 2009-02-20 18:05:44 UTC
*** Bug 39245 has been marked as a duplicate of this bug. ***
Comment 7 John David Anglin 2009-02-20 18:08:58 UTC
Test also fails on powerpc64 with -m32, arm.
Comment 8 Uroš Bizjak 2009-02-20 19:49:15 UTC
(In reply to comment #7)
> Test also fails on powerpc64 with -m32, arm.

And sh4.


Comment 9 Richard Biener 2012-06-06 10:15:42 UTC
Fixed for avr and ppc at least.