[Bug tree-optimization/14295] [tree-ssa] copy propagation for aggregates

2025-06-04 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=14295

Andrew Pinski  changed:

   What|Removed |Added

 Resolution|--- |FIXED
   Target Milestone|--- |16.0
 Status|ASSIGNED|RESOLVED

--- Comment #17 from Andrew Pinski  ---
The first patch has been committed which fixes this testcase; I have a few more
patches after this to finish this up but there are other bug reports for those.

[Bug tree-optimization/14295] [tree-ssa] copy propagation for aggregates

2025-06-04 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=14295

--- Comment #16 from GCC Commits  ---
The trunk branch has been updated by Andrew Pinski :

https://gcc.gnu.org/g:069caa5cea91fab3f1579ee1fdf50b923b75a6de

commit r16-1113-g069caa5cea91fab3f1579ee1fdf50b923b75a6de
Author: Andrew Pinski 
Date:   Thu Feb 20 22:05:38 2025 -0800

gimple-fold: Implement simple copy propagation for aggregates [PR14295]

This implements a simple copy propagation for aggregates in the similar
fashion as we already do for copy prop of zeroing.

Right now this only looks at the previous vdef statement but this allows us
to catch a lot of cases that show up in C++ code.

This used to deleted aggregate copies that are to the same location
(PR57361)
But that was found to delete statements that are needed for aliasing
markers reason.
So we need to keep them around until that is solved. Note DSE will delete
the statements
anyways so there is no testcase added since we expose the latent bug in the
same way.
See https://gcc.gnu.org/pipermail/gcc-patches/2025-May/685003.html for the
testcase and
explaintation there.

Also adds a variant of pr22237.c which was found while working on this
patch.

Changes since v1:
* v2: change check for vuse to use default definition.
  Remove dest/src arguments for optimize_agr_copyprop
  Changed dump messages slightly.
  Added stats
  Don't delete `a = a` until aliasing markers are added.

PR tree-optimization/14295
PR tree-optimization/108358
PR tree-optimization/114169

gcc/ChangeLog:

* tree-ssa-forwprop.cc (optimize_agr_copyprop): New function.
(pass_forwprop::execute): Call optimize_agr_copyprop for load/store
statements.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/20031106-6.c: Un-xfail. Add scan for forwprop1.
* g++.dg/opt/pr66119.C: Disable forwprop since that does
the copy prop now.
* gcc.dg/tree-ssa/pr108358-a.c: New test.
* gcc.dg/tree-ssa/pr114169-1.c: New test.
* gcc.c-torture/execute/builtins/pr22237-1-lib.c: New test.
* gcc.c-torture/execute/builtins/pr22237-1.c: New test.
* gcc.dg/tree-ssa/pr57361.c: Disable forwprop1.
* gcc.dg/tree-ssa/pr57361-1.c: New test.

Signed-off-by: Andrew Pinski 

[Bug tree-optimization/14295] [tree-ssa] copy propagation for aggregates

2025-05-19 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=14295

--- Comment #15 from Andrew Pinski  ---
Patch posted:
https://gcc.gnu.org/pipermail/gcc-patches/2025-May/684017.html

[Bug tree-optimization/14295] [tree-ssa] copy propagation for aggregates

2025-02-21 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=14295

--- Comment #14 from Andrew Pinski  ---
Note looking into how LLVM implements this is almost exactly the same as I have
implemented. The memset/memcpy -> memset/memset is exactly the same (though it
does work with other things inbetween).

[Bug tree-optimization/14295] [tree-ssa] copy propagation for aggregates

2025-02-21 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=14295

--- Comment #13 from Andrew Pinski  ---
Created attachment 60556
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=60556&action=edit
Patch which adds the simplified copy prop for agg

This fixes the testcase and has been bootstrapped and tested on x86_64 (other
targets might have some testcase failures due to SRA no longer needed to do the
copy prop). 

Just like the copy prop for zeroing, this only handles the previous memory
setting statement. 

I have an idea of how to improve this not just for the final copy. I had a
patch which handled call arguments but I want to make it more generic.

[Bug tree-optimization/14295] [tree-ssa] copy propagation for aggregates

2025-02-20 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=14295

--- Comment #12 from Andrew Pinski  ---
optimize_memcpy_to_memset does some simple copy prop but with zeroing. A
similar method could be done for non zeroing and i am going to try that.

[Bug tree-optimization/14295] [tree-ssa] copy propagation for aggregates

2025-02-20 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=14295

Andrew Pinski  changed:

   What|Removed |Added

   Assignee|unassigned at gcc dot gnu.org  |pinskia at gcc dot 
gnu.org
 Status|NEW |ASSIGNED

--- Comment #11 from Andrew Pinski  ---
.

[Bug tree-optimization/14295] [tree-ssa] copy propagation for aggregates

2024-05-24 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=14295

Andrew Pinski  changed:

   What|Removed |Added

 CC||user202729 at protonmail dot 
com

--- Comment #10 from Andrew Pinski  ---
*** Bug 115210 has been marked as a duplicate of this bug. ***

[Bug tree-optimization/14295] [tree-ssa] copy propagation for aggregates

2016-12-15 Thread etienne_lorrain at yahoo dot fr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=14295
Bug 14295 depends on bug 24177, which changed state.

Bug 24177 Summary: function returning structure produce very long/slow assembly
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=24177

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |FIXED

[Bug tree-optimization/14295] [tree-ssa] copy propagation for aggregates

2008-06-22 Thread rguenth at gcc dot gnu dot org


--- 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



[Bug tree-optimization/14295] [tree-ssa] copy propagation for aggregates

2008-06-22 Thread rguenth at gcc dot gnu dot org


--- 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;

:
  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;
   ={v} temp_struct3.3_4;
  return ;

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

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

:
  r.0_1 = r;
   = r.0_1;
  return ;

(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



[Bug tree-optimization/14295] [tree-ssa] copy propagation for aggregates

2008-01-27 Thread rguenth at gcc dot gnu dot org


--- 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;

:
  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



[Bug tree-optimization/14295] [tree-ssa] copy propagation for aggregates

2006-03-10 Thread dnovillo at gcc dot gnu dot org


-- 

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



[Bug tree-optimization/14295] [tree-ssa] copy propagation for aggregates

2006-02-14 Thread rguenth at gcc dot gnu dot org


--- 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 ;
  #   VUSE ;
  tmpD.1530 = aD.1524;
  #   aD.1524_5 = V_MUST_DEF ;
  #   VUSE ;
  aD.1524 = bD.1525;
  #   cD.1526_7 = V_MUST_DEF ;
  #   VUSE ;
  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



[Bug tree-optimization/14295] [tree-ssa] copy propagation for aggregates

2006-01-14 Thread rguenth at gcc dot gnu dot org


--- 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;

:
  temp_struct1 = r;
  temp_struct2 = temp_struct1;
  temp_struct3 = temp_struct2;
   = temp_struct3;
  return ;

}

and generates

foo:
pushl   %ebp
movl%esp, %ebp
pushl   %edi
pushl   %esi
subl$56, %esp
leal-28(%ebp), %edi
leal12(%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
movl8(%ebp), %edi
movb$5, %cl
rep
movsl
movl8(%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



[Bug tree-optimization/14295] [tree-ssa] copy propagation for aggregates

2006-01-07 Thread steven at gcc dot gnu dot org


--- 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;

:
  r$b = r.b;
  r$a = r.a;
  r$d = r.d;
  .m = r.m;
  .b = r$b;
  .a = r$a;
  .d = r$d;
  return ;

}


-- 

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




[Bug tree-optimization/14295] [tree-ssa] copy propagation for aggregates

2005-09-14 Thread pinskia at gcc dot gnu dot org

--- 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