]> git.ipfire.org Git - thirdparty/gcc.git/commit
forwprop: Fix up "nop" copies after recent changes [PR121962]
authorAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Tue, 16 Sep 2025 17:55:03 +0000 (10:55 -0700)
committerAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Wed, 17 Sep 2025 18:36:42 +0000 (11:36 -0700)
commita7a9f0de4fe01ee96350892066afbe5aca4bc0a6
tree1e804e3beaeb0dca7d52b8d50648d55ae117dce3
parent4b83df548f3f16c8c5bd83d82801f8219984e089
forwprop: Fix up "nop" copies after recent changes [PR121962]

After r16-3887-g597b50abb0d2fc, the check to see if the copy is
a nop copy becomes inefficient. The code going into an infinite
loop as the copy keeps on being propagated over and over again.

That is if we have:
```
  struct s1 *b = &a.t;
  a.t = *b;
  p = *b;
```

This goes into an infinite loop propagating over and over again the
`MEM[&a]`.
To solve this a new function is needed for the comparison that is
similar to new_src_based_on_copy.

PR tree-optimization/121962

gcc/ChangeLog:

* tree-ssa-forwprop.cc (same_for_assignment): New function.
(optimize_agr_copyprop_1): Use same_for_assignment to check for
nop copies.
(optimize_agr_copyprop): Likewise.

gcc/testsuite/ChangeLog:

* gcc.dg/torture/pr121962-1.c: New test.

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