Bug 36598

Summary: Failed optimisation of return of struct argment in memcpy-1.c
Product: gcc Reporter: Andy Hutchinson <hutchinsonandy>
Component: middle-endAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal CC: danglin, eric.weddington, gcc-bugs, kkojima, pinskia
Priority: P3    
Version: 4.4.0   
Target Milestone: ---   
Host: i686-pc-linux-gnu Target:
Build: i686-pc-linux-gnu Known to work:
Known to fail: Last reconfirmed: 2009-02-20 19:49:15
Bug Depends on: 14295    
Bug Blocks:    

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 jsm-csl@polyomino.org.uk 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:

http://gcc.gnu.org/ml/gcc-patches/2007-12/msg01144.html

Andy
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
Log:
PR target/36598
* gcc.dg/memcpy-1.c: Mark test XFAIL for avr target.

Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.dg/memcpy-1.c

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.

http://gcc.gnu.org/ml/gcc-testresults/2009-02/msg01952.html

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