]> git.ipfire.org Git - thirdparty/gcc.git/commit
forwprop: Change proping memset into memcpy into a forwprop rather than a backwalk
authorAndrew Pinski <quic_apinski@quicinc.com>
Mon, 9 Jun 2025 06:13:23 +0000 (23:13 -0700)
committerAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Fri, 8 Aug 2025 21:30:28 +0000 (14:30 -0700)
commit899e7284bfa0b736165c3d9d5c18d5d883c5cbfb
tree6ff5464b75daaac60be1bb1c32d86f322bb3a018
parentc7de7ddbfae1656ad8309f8821d17ae43383e5d5
forwprop: Change proping memset into memcpy into a forwprop rather than a backwalk

One thing I noticed while working on copy prop for aggregates is that we start with
a memcpy like statement and then walk backwards. This means we could have a few walks
backwards to see there was no statement for zeroing. Instead this changes the walk
backwards into a true forwprop. In the future we can expand to forwprop the zeroing
into say an function argument or something more than memcpy like statement.

This should speed up slightly the compile time performance since there will be less
memsets like statements than memcpy and there is only one walk forwards for memset like
staments instead of multiple walk backwards to find the memset.

Note this does add one extra improvement, the memcpy now does not need to have an address
as its dest argument; this could have been done before too but it was even more noticable
now because of the variable became only set so it was removed and the check was removed
as well.

There is also a fix on how ao_ref for the memset/memcpy is done, before it was just using
ao_ref_init which is wrong since it should instead of used ao_ref_init_from_ptr_and_size.
This part fixes PR 121422.

Changes since v1:
* v2: Add back limit on the walk which was missed in v1.
      Move the call to get_addr_base_and_unit_offset outside
of the vuse loop.
* v3: Remove extra check before the call to optimize_aggr_zeroprop_1.
      Fix setting up of ao_ref for memset (PR121422).

PR tree-optimization/118946
PR tree-optimization/121422

gcc/ChangeLog:

* tree-ssa-forwprop.cc (optimize_memcpy_to_memset): Remove.
(optimize_aggr_zeroprop_1): New function.
(optimize_aggr_zeroprop): New function.
(simplify_builtin_call): Don't call optimize_memcpy_to_memset
for memcpy but call optimize_aggr_zeroprop for memset.
(pass_forwprop::execute): Don't call optimize_memcpy_to_memset
for aggregate copies but rather call optimize_aggr_zeroprop
for aggregate stores.

gcc/testsuite/ChangeLog:

* gcc.dg/pr118946-1.c: New test.
* gcc.dg/torture/pr121422-1.c: New test.
* gcc.dg/torture/pr121422-2.c: New test.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
gcc/testsuite/gcc.dg/pr118946-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/pr121422-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/pr121422-2.c [new file with mode: 0644]
gcc/tree-ssa-forwprop.cc