]> git.ipfire.org Git - thirdparty/gcc.git/commit
forwprop: Improve the reject case for copy prop [PR107051]
authorAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Wed, 27 Aug 2025 05:04:06 +0000 (22:04 -0700)
committerAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Thu, 4 Sep 2025 10:12:43 +0000 (03:12 -0700)
commitadfe96eb612feeb6abb2ecac267325243039a0f8
treefd42566b6788d38a19eb0916796000582a49931b
parent43a8c0f8e67f282823a3af1df4cd77dd86981b9c
forwprop: Improve the reject case for copy prop [PR107051]

Currently the code rejects:
```
tmp = *a;
*b = tmp;
```
(unless *a == *b). This can be improved such that if a and b are known to
share the same base, then only reject it if they overlap; that is the
difference of the offsets (from the base) is maybe less than the size.

This fixes the testcase in comment #0 of PR 107051.

Changes since v1:
* v2: Use ranges_maybe_overlap_p instead of manually checking the overlap.
      Allow for the case where the alignment is known to be greater than
      the size.

PR tree-optimization/107051

gcc/ChangeLog:

* tree-ssa-forwprop.cc (optimize_agr_copyprop_1): Allow for
memory sharing the same base if they known not to overlap over
the size.

gcc/testsuite/ChangeLog:

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

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