* [PATCH] ipa-cp: Avoid adjusting references through self-recursion (PR 104813)
@ 2022-03-08 21:51 Martin Jambor
2022-03-10 7:43 ` Martin Liška
0 siblings, 1 reply; 2+ messages in thread
From: Martin Jambor @ 2022-03-08 21:51 UTC (permalink / raw)
To: GCC Patches; +Cc: Jan Hubicka
Hi,
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.
Bootstrapped and LTO-bootstrapped and tested on x86_64-linux. OK for
master?
Thanks,
Martin
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.
---
gcc/ipa-cp.cc | 20 +++++++++---------
gcc/testsuite/gcc.dg/ipa/pr104813.c | 32 +++++++++++++++++++++++++++++
2 files changed, 42 insertions(+), 10 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/ipa/pr104813.c
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;
+}
--
2.35.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] ipa-cp: Avoid adjusting references through self-recursion (PR 104813)
2022-03-08 21:51 [PATCH] ipa-cp: Avoid adjusting references through self-recursion (PR 104813) Martin Jambor
@ 2022-03-10 7:43 ` Martin Liška
0 siblings, 0 replies; 2+ messages in thread
From: Martin Liška @ 2022-03-10 7:43 UTC (permalink / raw)
To: Martin Jambor, GCC Patches; +Cc: Jan Hubicka
On 3/8/22 22:51, Martin Jambor wrote:
> Hi,
>
> 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.
>
> Bootstrapped and LTO-bootstrapped and tested on x86_64-linux. OK for
> master?
Yes, thanks.
Martin
>
> Thanks,
>
> Martin
>
>
> 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.
> ---
> gcc/ipa-cp.cc | 20 +++++++++---------
> gcc/testsuite/gcc.dg/ipa/pr104813.c | 32 +++++++++++++++++++++++++++++
> 2 files changed, 42 insertions(+), 10 deletions(-)
> create mode 100644 gcc/testsuite/gcc.dg/ipa/pr104813.c
>
> 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] 2+ messages in thread
end of thread, other threads:[~2022-03-10 7:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-08 21:51 [PATCH] ipa-cp: Avoid adjusting references through self-recursion (PR 104813) Martin Jambor
2022-03-10 7:43 ` Martin Liška
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).