diff options
author | Martin Jambor <mjambor@suse.cz> | 2022-03-10 14:49:23 +0100 |
---|---|---|
committer | Martin Jambor <mjambor@suse.cz> | 2022-03-10 14:50:54 +0100 |
commit | e671e48e352ee278d816d4633146208807a0e403 (patch) | |
tree | d3f8d1b5c97d31ca8a68c953618831280844347b | |
parent | ee34ffa429a399f292ad1421333721a92b998772 (diff) | |
download | gcc-e671e48e352ee278d816d4633146208807a0e403.zip gcc-e671e48e352ee278d816d4633146208807a0e403.tar.gz gcc-e671e48e352ee278d816d4633146208807a0e403.tar.bz2 |
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.
-rw-r--r-- | gcc/ipa-cp.cc | 20 | ||||
-rw-r--r-- | 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 453e9c9..18047c2 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 0000000..34f413e --- /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; +} |