public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug optimization/14295] New: [tree-ssa] copy propagation for aggregates
@ 2004-02-25 17:37 dann at godzilla dot ics dot uci dot edu
  2004-02-25 17:42 ` [Bug optimization/14295] " dnovillo at gcc dot gnu dot org
                   ` (4 more replies)
  0 siblings, 5 replies; 14+ messages in thread
From: dann at godzilla dot ics dot uci dot edu @ 2004-02-25 17:37 UTC (permalink / raw)
  To: gcc-bugs

This is a (possible?) enhancement request. 
There already is a testcase in the testsuite for this: 20031106-6.c

struct s
{
  char d;
  int a, b;
  double m;
};

struct s foo (struct s r)
{
  struct s temp_struct1;
  struct s temp_struct2;
  struct s temp_struct3;
  temp_struct1 = r;
  temp_struct2 = temp_struct1;
  temp_struct3 = temp_struct2;
  return temp_struct3;
}

The .optimized dump is: 

foo (r)
{
  double r$m;
  int r$b;
  int r$a;
  struct s temp_struct3;

<bb 0>:
  r$a = r.a;
  r$b = r.b;
  r$m = r.m;
  temp_struct3.d = r.d;
  temp_struct3.a = r$a;
  temp_struct3.b = r$b;
  temp_struct3.m = r$m;
  return temp_struct3;
}

It would be nice if it would be just "return r;"

SRA could take care of things like this, but that might be much more work, plus
it precludes from using more optimized memory copy sequences for 
aggregate copying instead of series of loads and store. 

BTW, the above code seems strange too, temporaries are created for r.a, r.b 
and r.m, but not for r.d 

Another compiler produces the following assembly:

        mov     eax, DWORD PTR $T552[esp-4]
        push    esi
        push    edi
        mov     ecx, 6
        lea     esi, DWORD PTR _r$[esp+4]
        mov     edi, eax
        rep movsd
        pop     edi
        pop     esi

-- 
           Summary: [tree-ssa] copy propagation for aggregates
           Product: gcc
           Version: tree-ssa
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dann at godzilla dot ics dot uci dot edu
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14295


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug optimization/14295] [tree-ssa] copy propagation for aggregates
  2004-02-25 17:37 [Bug optimization/14295] New: [tree-ssa] copy propagation for aggregates dann at godzilla dot ics dot uci dot edu
@ 2004-02-25 17:42 ` dnovillo at gcc dot gnu dot org
  2004-02-25 17:58 ` pinskia at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 14+ messages in thread
From: dnovillo at gcc dot gnu dot org @ 2004-02-25 17:42 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |dnovillo at gcc dot gnu dot
                   |dot org                     |org
             Status|UNCONFIRMED                 |ASSIGNED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14295


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug optimization/14295] [tree-ssa] copy propagation for aggregates
  2004-02-25 17:37 [Bug optimization/14295] New: [tree-ssa] copy propagation for aggregates dann at godzilla dot ics dot uci dot edu
  2004-02-25 17:42 ` [Bug optimization/14295] " dnovillo at gcc dot gnu dot org
@ 2004-02-25 17:58 ` pinskia at gcc dot gnu dot org
  2004-05-27  5:28 ` [Bug tree-optimization/14295] " pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-02-25 17:58 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-02-25 17:57 -------
Really you can no longer just look at .optimized anymore.  But this testcase is really fixed.

>From *.t51.nrv:
;; Function foo (foo)

foo (r)
{
  double temp_struct3$m;
  int temp_struct3$b;
  int temp_struct3$a;
  char temp_struct3$d;
  double temp_struct2$m;
  int temp_struct2$b;
  int temp_struct2$a;
  char temp_struct2$d;
  double r$m;
  double temp_struct1$m;
  int r$b;
  int temp_struct1$b;
  int r$a;
  int temp_struct1$a;
  char r$d;
  char temp_struct1$d;
  struct s temp_struct3;
  struct s temp_struct2;
  struct s temp_struct1;

<bb 0>:
  r$a = r.a;
  r$b = r.b;
  r$m = r.m;
  <retval>.d = r.d;
  <retval>.a = r$a;
  <retval>.b = r$b;
  <retval>.m = r$m;
  return <retval>;
}

Note <retval> is a special variable and the expand for return is no longer just returning the struct.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
           Keywords|                            |pessimizes-code
   Target Milestone|---                         |tree-ssa


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14295


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug tree-optimization/14295] [tree-ssa] copy propagation for aggregates
  2004-02-25 17:37 [Bug optimization/14295] New: [tree-ssa] copy propagation for aggregates dann at godzilla dot ics dot uci dot edu
  2004-02-25 17:42 ` [Bug optimization/14295] " dnovillo at gcc dot gnu dot org
  2004-02-25 17:58 ` pinskia at gcc dot gnu dot org
@ 2004-05-27  5:28 ` pinskia at gcc dot gnu dot org
  2004-06-29 17:41 ` pinskia at gcc dot gnu dot org
  2005-09-14 17:35 ` pinskia at gcc dot gnu dot org
  4 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-05-27  5:28 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|3.5.0                       |---


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14295


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug tree-optimization/14295] [tree-ssa] copy propagation for aggregates
  2004-02-25 17:37 [Bug optimization/14295] New: [tree-ssa] copy propagation for aggregates dann at godzilla dot ics dot uci dot edu
                   ` (2 preceding siblings ...)
  2004-05-27  5:28 ` [Bug tree-optimization/14295] " pinskia at gcc dot gnu dot org
@ 2004-06-29 17:41 ` pinskia at gcc dot gnu dot org
  2005-09-14 17:35 ` pinskia at gcc dot gnu dot org
  4 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-06-29 17:41 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-06-29 17:35 -------
On the mainline now we have:

foo (r)
{
  struct s temp_struct3;
  struct s temp_struct2;
  struct s temp_struct1;

<bb 0>:
  temp_struct1 = r;
  temp_struct2 = temp_struct1;
  temp_struct3 = temp_struct2;
  <retval> = temp_struct3;
  return <retval>;

}

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|0000-00-00 00:00:00         |2004-06-29 17:35:38
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14295


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug tree-optimization/14295] [tree-ssa] copy propagation for aggregates
  2004-02-25 17:37 [Bug optimization/14295] New: [tree-ssa] copy propagation for aggregates dann at godzilla dot ics dot uci dot edu
                   ` (3 preceding siblings ...)
  2004-06-29 17:41 ` pinskia at gcc dot gnu dot org
@ 2005-09-14 17:35 ` pinskia at gcc dot gnu dot org
  4 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-09-14 17:35 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-09-14 17:35 -------
*** Bug 18268 has been marked as a duplicate of this bug. ***

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pinskia at gcc dot gnu dot
                   |                            |org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14295


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug tree-optimization/14295] [tree-ssa] copy propagation for aggregates
       [not found] <bug-14295-4@http.gcc.gnu.org/bugzilla/>
@ 2024-05-24 13:50 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-05-24 13:50 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=14295

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |user202729 at protonmail dot com

--- Comment #10 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 115210 has been marked as a duplicate of this bug. ***

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug tree-optimization/14295] [tree-ssa] copy propagation for aggregates
       [not found] <bug-14295-1008@http.gcc.gnu.org/bugzilla/>
                   ` (5 preceding siblings ...)
  2008-06-22 15:06 ` rguenth at gcc dot gnu dot org
@ 2008-06-22 15:07 ` rguenth at gcc dot gnu dot org
  6 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-06-22 15:07 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from rguenth at gcc dot gnu dot org  2008-06-22 15:07 -------
Created an attachment (id=15801)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=15801&action=view)
aggregate temporary registers

Like this simple, untested patch.  Breaks tree-sra.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14295


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug tree-optimization/14295] [tree-ssa] copy propagation for aggregates
       [not found] <bug-14295-1008@http.gcc.gnu.org/bugzilla/>
                   ` (4 preceding siblings ...)
  2008-01-27 15:36 ` rguenth at gcc dot gnu dot org
@ 2008-06-22 15:06 ` rguenth at gcc dot gnu dot org
  2008-06-22 15:07 ` rguenth at gcc dot gnu dot org
  6 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-06-22 15:06 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from rguenth at gcc dot gnu dot org  2008-06-22 15:05 -------
If we would disallow struct copies in the gimple IL and instead require a
register temporary that we would re-write into SSA form like

  struct s temp_struct3;
  struct s temp_struct2;
  struct s temp_struct1;
  struct s temp_struct3.3;
  struct s temp_struct2.2;
  struct s temp_struct1.1;
  struct s r.0;

<bb 2>:
  r.0_1 = r;
  temp_struct1 ={v} r.0_1;
  temp_struct1.1_2 = temp_struct1;
  temp_struct2 ={v} temp_struct1.1_2;
  temp_struct2.2_3 = temp_struct2;
  temp_struct3 ={v} temp_struct2.2_3;
  temp_struct3.3_4 = temp_struct3;
  <retval> ={v} temp_struct3.3_4;
  return <retval>;

then value-numbering can recognize the redundant copies and we end up
with

  struct s temp_struct3.3;
  struct s r.0;

<bb 2>:
  r.0_1 = r;
  <retval> = r.0_1;
  return <retval>;

(and of course with the possibility of out-of-SSA having to deal with
overlapping life-ranges of struct-typed SSA names)


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14295


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug tree-optimization/14295] [tree-ssa] copy propagation for aggregates
       [not found] <bug-14295-1008@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2006-03-10 15:34 ` dnovillo at gcc dot gnu dot org
@ 2008-01-27 15:36 ` rguenth at gcc dot gnu dot org
  2008-06-22 15:06 ` rguenth at gcc dot gnu dot org
  2008-06-22 15:07 ` rguenth at gcc dot gnu dot org
  6 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-01-27 15:36 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from rguenth at gcc dot gnu dot org  2008-01-27 14:14 -------
One important structure copy propagation that SRA is not able to handle is

struct X { int i; int j; };

void foo(struct X);
inline void wrap(struct X w) { foo(w); }
void bar(struct X x) { wrap(x); }

where a copy from the parameter x in bar to the temporary used as parameter
to the call to foo remains (because both cannot be decomposed by SRA as
they need to live in memory):

bar (x)
{
  int x$j;
  int x$i;
  struct X w;

<bb 2>:
  x$i_8 = x.i;
  x$j_9 = x.j;
  w.j = x$j_9;
  w.i = x$i_8;
  foo (w) [tail call];
  return;

}

In this case expansion works anyway because the call to foo is marked as
tail-call before SRA comes along.

SRA heuristics also doesn't work very well here, as it is clearly not
profitable to do element-copy here; in fact it probably makes structure
copy-prop more difficult to implement.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
OtherBugsDependingO|23782                       |
              nThis|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14295


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug tree-optimization/14295] [tree-ssa] copy propagation for aggregates
       [not found] <bug-14295-1008@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2006-02-14 15:53 ` rguenth at gcc dot gnu dot org
@ 2006-03-10 15:34 ` dnovillo at gcc dot gnu dot org
  2008-01-27 15:36 ` rguenth at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 14+ messages in thread
From: dnovillo at gcc dot gnu dot org @ 2006-03-10 15:34 UTC (permalink / raw)
  To: gcc-bugs



-- 

dnovillo at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dnovillo at gcc dot gnu dot
                   |                            |org
         AssignedTo|dnovillo at gcc dot gnu dot |unassigned at gcc dot gnu
                   |org                         |dot org
             Status|ASSIGNED                    |NEW


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14295


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug tree-optimization/14295] [tree-ssa] copy propagation for aggregates
       [not found] <bug-14295-1008@http.gcc.gnu.org/bugzilla/>
  2006-01-07 18:04 ` steven at gcc dot gnu dot org
  2006-01-14 12:16 ` rguenth at gcc dot gnu dot org
@ 2006-02-14 15:53 ` rguenth at gcc dot gnu dot org
  2006-03-10 15:34 ` dnovillo at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2006-02-14 15:53 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from rguenth at gcc dot gnu dot org  2006-02-14 15:52 -------
Created an attachment (id=10849)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=10849&action=view)
simple "cleanup" struct copyprop

Attached simple "cleanup" style struct copyprop that is able to clean up
useless
copys inserted by inlining and gimplification (mostly happens for C++).  It
handles both

  tmp = X;
  Y = tmp;

to

  tmp = X;
  Y = X;

(commented code to remove tmp = X is there, but one needs to somehow check
if the store is to a global var - DCE will happily clean up after us though)

and

  tmp = X;
  X = tmp;

to

  tmp = X;

(happens a few times in gcc itself, same comment as above).  This looks like
a thing we should do after/inside inlining in ssa form.

Note that this patch doesn't require dominator information (which would enable
us to relax the stmt ordering by checking if the final store dominates all
kills of X - i.e. to prevent propagation in the case of

  #   tmpD.1530_3 = V_MUST_DEF <tmpD.1530_2>;
  #   VUSE <aD.1524_1>;
  tmpD.1530 = aD.1524;
  #   aD.1524_5 = V_MUST_DEF <aD.1524_1>;
  #   VUSE <bD.1525_4>;
  aD.1524 = bD.1525;
  #   cD.1526_7 = V_MUST_DEF <cD.1526_6>;
  #   VUSE <tmpD.1530_3>;
  cD.1526 = tmpD.1530;

as aD.1524 is not in SSA form and so the value used in stmt 1 is no longer
available)


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14295


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug tree-optimization/14295] [tree-ssa] copy propagation for aggregates
       [not found] <bug-14295-1008@http.gcc.gnu.org/bugzilla/>
  2006-01-07 18:04 ` steven at gcc dot gnu dot org
@ 2006-01-14 12:16 ` rguenth at gcc dot gnu dot org
  2006-02-14 15:53 ` rguenth at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2006-01-14 12:16 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from rguenth at gcc dot gnu dot org  2006-01-14 12:16 -------
4.1 branch has
;; Function foo (foo)

Analyzing Edge Insertions.
foo (r)
{
  struct s temp_struct3;
  struct s temp_struct2;
  struct s temp_struct1;

<bb 0>:
  temp_struct1 = r;
  temp_struct2 = temp_struct1;
  temp_struct3 = temp_struct2;
  <retval> = temp_struct3;
  return <retval>;

}

and generates

foo:
        pushl   %ebp
        movl    %esp, %ebp
        pushl   %edi
        pushl   %esi
        subl    $56, %esp
        leal    -28(%ebp), %edi
        leal    12(%ebp), %esi
        cld
        movl    $5, %ecx
        rep
        movsl
        leal    -48(%ebp), %edi
        leal    -28(%ebp), %esi
        movb    $5, %cl
        rep
        movsl
        leal    -48(%ebp), %esi
        movl    8(%ebp), %edi
        movb    $5, %cl
        rep
        movsl
        movl    8(%ebp), %eax
        addl    $56, %esp
        popl    %esi
        popl    %edi
        leave
        ret     $4


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rguenth at gcc dot gnu dot
                   |                            |org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14295


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug tree-optimization/14295] [tree-ssa] copy propagation for aggregates
       [not found] <bug-14295-1008@http.gcc.gnu.org/bugzilla/>
@ 2006-01-07 18:04 ` steven at gcc dot gnu dot org
  2006-01-14 12:16 ` rguenth at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 14+ messages in thread
From: steven at gcc dot gnu dot org @ 2006-01-07 18:04 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from steven at gcc dot gnu dot org  2006-01-07 18:04 -------
On AMD64 with GNU C version 4.2.0 20060107, I get this .optimized dump:

;; Function foo (foo)

foo (r)
{
  int r$b;
  int r$a;
  char r$d;

<bb 2>:
  r$b = r.b;
  r$a = r.a;
  r$d = r.d;
  <retval>.m = r.m;
  <retval>.b = r$b;
  <retval>.a = r$a;
  <retval>.d = r$d;
  return <retval>;

}


-- 

steven at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2005-05-08 18:01:19         |2006-01-07 18:04:40
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14295



^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2024-05-24 13:50 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-02-25 17:37 [Bug optimization/14295] New: [tree-ssa] copy propagation for aggregates dann at godzilla dot ics dot uci dot edu
2004-02-25 17:42 ` [Bug optimization/14295] " dnovillo at gcc dot gnu dot org
2004-02-25 17:58 ` pinskia at gcc dot gnu dot org
2004-05-27  5:28 ` [Bug tree-optimization/14295] " pinskia at gcc dot gnu dot org
2004-06-29 17:41 ` pinskia at gcc dot gnu dot org
2005-09-14 17:35 ` pinskia at gcc dot gnu dot org
     [not found] <bug-14295-1008@http.gcc.gnu.org/bugzilla/>
2006-01-07 18:04 ` steven at gcc dot gnu dot org
2006-01-14 12:16 ` rguenth at gcc dot gnu dot org
2006-02-14 15:53 ` rguenth at gcc dot gnu dot org
2006-03-10 15:34 ` dnovillo at gcc dot gnu dot org
2008-01-27 15:36 ` rguenth at gcc dot gnu dot org
2008-06-22 15:06 ` rguenth at gcc dot gnu dot org
2008-06-22 15:07 ` rguenth at gcc dot gnu dot org
     [not found] <bug-14295-4@http.gcc.gnu.org/bugzilla/>
2024-05-24 13:50 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).