public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-7593] ipa-cp: Avoid adjusting references through self-recursion (PR 104813)
@ 2022-03-10 13:56 Martin Jambor
0 siblings, 0 replies; only message in thread
From: Martin Jambor @ 2022-03-10 13:56 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:e671e48e352ee278d816d4633146208807a0e403
commit r12-7593-ge671e48e352ee278d816d4633146208807a0e403
Author: Martin Jambor <mjambor@suse.cz>
Date: Thu Mar 10 14:49:23 2022 +0100
ipa-cp: Avoid adjusting references through self-recursion (PR 104813)
When writing the patch that downgrades address-taken references to
load references when IPA-CP can prove that all uses of the taken
address ends up in loads, I unfortunately did not take into account
that find_more_scalar_values_for_callers_subset now happily adds
self-recursive edges to the set of callers which should be immediately
redirected (originally recursion was meant to be handled as edge
redirection in a second pass over the SCC).
The code as it is can now decrement the referece counters too many
times. This can remedied by removing self-recursive edges earlier, we
already do it because of thunk expansion issues, and so this patch
does exactly that.
gcc/ChangeLog:
2022-03-07 Martin Jambor <mjambor@suse.cz>
PR ipa/104813
* ipa-cp.cc (create_specialized_node): Move removal of
self-recursive calls from callers vector before refrence
adjustments.
gcc/testsuite/ChangeLog:
2022-03-07 Martin Jambor <mjambor@suse.cz>
PR ipa/104813
* gcc.dg/ipa/pr104813.c: New test.
Diff:
---
gcc/ipa-cp.cc | 20 ++++++++++----------
gcc/testsuite/gcc.dg/ipa/pr104813.c | 32 ++++++++++++++++++++++++++++++++
2 files changed, 42 insertions(+), 10 deletions(-)
diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc
index 453e9c93cc3..18047c209a8 100644
--- a/gcc/ipa-cp.cc
+++ b/gcc/ipa-cp.cc
@@ -5099,6 +5099,16 @@ create_specialized_node (struct cgraph_node *node,
else
new_adjustments = NULL;
+ auto_vec<cgraph_edge *, 2> self_recursive_calls;
+ for (i = callers.length () - 1; i >= 0; i--)
+ {
+ cgraph_edge *cs = callers[i];
+ if (cs->caller == node)
+ {
+ self_recursive_calls.safe_push (cs);
+ callers.unordered_remove (i);
+ }
+ }
replace_trees = cinfo ? vec_safe_copy (cinfo->tree_map) : NULL;
for (i = 0; i < count; i++)
{
@@ -5129,16 +5139,6 @@ create_specialized_node (struct cgraph_node *node,
if (replace_map)
vec_safe_push (replace_trees, replace_map);
}
- auto_vec<cgraph_edge *, 2> self_recursive_calls;
- for (i = callers.length () - 1; i >= 0; i--)
- {
- cgraph_edge *cs = callers[i];
- if (cs->caller == node)
- {
- self_recursive_calls.safe_push (cs);
- callers.unordered_remove (i);
- }
- }
unsigned &suffix_counter = clone_num_suffixes->get_or_insert (
IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (
diff --git a/gcc/testsuite/gcc.dg/ipa/pr104813.c b/gcc/testsuite/gcc.dg/ipa/pr104813.c
new file mode 100644
index 00000000000..34f413e3823
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/ipa/pr104813.c
@@ -0,0 +1,32 @@
+/* { dg-do compile } */
+/* { dg-options "-O3" } */
+
+int a, b, c, d, *e;
+void f(int h) {
+ if (b) {
+ int g;
+ while (g++)
+ d = *e;
+ e++;
+ }
+}
+static void i();
+static void j(int *h, int k, int *l) {
+ if (c) {
+ int *o = h, m;
+ f(*l);
+ i(m);
+ j(o, 1, o);
+ for (;;)
+ ;
+ }
+}
+void i() {
+ int *n = &a;
+ while (1)
+ j(n, 1, n);
+}
+int main() {
+ j(&a, 0, &a);
+ return 0;
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-03-10 13:56 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-10 13:56 [gcc r12-7593] ipa-cp: Avoid adjusting references through self-recursion (PR 104813) Martin Jambor
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).