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>