]> git.ipfire.org Git - thirdparty/gcc.git/commit
gimple-fold: Implement simple copy propagation for aggregates [PR14295]
authorAndrew Pinski <quic_apinski@quicinc.com>
Fri, 21 Feb 2025 06:05:38 +0000 (22:05 -0800)
committerAndrew Pinski <quic_apinski@quicinc.com>
Wed, 4 Jun 2025 16:04:04 +0000 (09:04 -0700)
commit069caa5cea91fab3f1579ee1fdf50b923b75a6de
tree61984cad54857720357f20c3b3930dceb04e7391
parent7bb1933c1fcca8cb99132ff5d08b3f3efca4ff07
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 <quic_apinski@quicinc.com>
gcc/testsuite/g++.dg/opt/pr66119.C
gcc/testsuite/gcc.c-torture/execute/builtins/pr22237-1-lib.c [new file with mode: 0644]
gcc/testsuite/gcc.c-torture/execute/builtins/pr22237-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/20031106-6.c
gcc/testsuite/gcc.dg/tree-ssa/pr108358-a.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/pr114169-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/pr57361-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/pr57361.c
gcc/tree-ssa-forwprop.cc