]> git.ipfire.org Git - thirdparty/gcc.git/commit
forwprop: Handle memcpy for copy prop [PR121418, PR121417] master trunk
authorAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Sun, 7 Sep 2025 04:49:18 +0000 (21:49 -0700)
committerAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Mon, 15 Sep 2025 15:59:27 +0000 (08:59 -0700)
commit597b50abb0d2fc1f123a99e1b4beb89ad6259d9e
tree42ee8e5e451155c274c0aa09d9dad32769a42183
parentde0ae1b5103293bc07f35964c2b7da5edbe7eb3c
forwprop: Handle memcpy for copy prop [PR121418, PR121417]

It turns out easy to add support for memcpy copy prop when the memcpy
has changed into `MEM<char[N]>` copy.
Instead of rejecting right out we need to figure out that
`a` and `MEM<char[N]>[&a]` are equivalent in terms of address and size.
And then create a VIEW_CONVER_EXPR from the original src to the new type.

Note this also allows for `a.b` and `a` being considered equivalent if b is the
only field (PR 121751).

Changes since v1:
* v2: Move check for IMAG/REAL and BFR earlier.
      Add a wrapping function around get_inner_reference and use that instead
     of get_addr_base_and_unit_offset.

Bootstrapped and tested on x86_64-linux-gnu.

PR tree-optimization/121751
PR tree-optimization/121418
PR tree-optimization/121417
gcc/ChangeLog:

* tree-ssa-forwprop.cc (split_core_and_offset_size): New function.
(optimize_agr_copyprop_1): Allow for the same
address but different type accesses via a VCE.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/copy-prop-aggregate-1.c: New test.
* gcc.dg/tree-ssa/copy-prop-aggregate-memcpy-1.c: New test.
* gcc.dg/tree-ssa/copy-prop-aggregate-memcpy-2.c: New test.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
gcc/testsuite/gcc.dg/tree-ssa/copy-prop-aggregate-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/copy-prop-aggregate-memcpy-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/copy-prop-aggregate-memcpy-2.c [new file with mode: 0644]
gcc/tree-ssa-forwprop.cc