ipa-cp: Do not be too optimistic about self-recursive edges (PR 107661)

PR 107661 shows that function push_agg_values_for_index_from_edge
should not attempt to optimize self-recursive call graph edges when
called from cgraph_edge_brings_all_agg_vals_for_node.  Unlike when
being called from find_aggregate_values_for_callers_subset, we cannot
expect that any cloning for constants would lead to the edge leading
from a new clone to the same new clone, in this case it would only be
redirected to a new callee.

Fixed by adding a parameter to push_agg_values_from_edge whether being
optimistic about self-recursive edges is possible.

gcc/ChangeLog:

2022-11-22  Martin Jambor  <mjambor@suse.cz>

	PR ipa/107661
	* ipa-cp.cc (push_agg_values_from_edge): New parameter
	optimize_self_recursion, use it to decide whether to pass interim to
	the helper function.
	(find_aggregate_values_for_callers_subset): Pass true in the new
	parameter of push_agg_values_from_edge.
	(cgraph_edge_brings_all_agg_vals_for_node): Pass false in the new
	parameter of push_agg_values_from_edge.

gcc/testsuite/ChangeLog:

2022-11-22  Martin Jambor  <mjambor@suse.cz>

	PR ipa/107661
	* g++.dg/ipa/pr107661.C: New test.
2 files changed