From 42d73fa9d575e3c8c21e88bd7f65922e17b052f1 Mon Sep 17 00:00:00 2001 From: Feng Xue Date: Wed, 8 Jan 2020 02:55:00 +0000 Subject: [PATCH] Find matched aggregate lattice for self-recursive CP (PR ipa/93084) 2020-01-08 Feng Xue PR ipa/93084 * ipa-cp.c (self_recursively_generated_p): Find matched aggregate lattice for a value to check. (propagate_vals_across_arith_jfunc): Add an assertion to ensure finite propagation in self-recursive scc. 2020-01-08 Feng Xue PR ipa/93084 * gcc.dg/ipa/ipa-clone-3.c: New test. From-SVN: r279987 --- gcc/ChangeLog | 8 +++++ gcc/ipa-cp.c | 21 +++++++++++-- gcc/testsuite/ChangeLog | 5 +++ gcc/testsuite/gcc.dg/ipa/ipa-clone-3.c | 42 ++++++++++++++++++++++++++ 4 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/ipa/ipa-clone-3.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 44ae44c8260..6387fcc9aba 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2020-01-08 Feng Xue + + PR ipa/93084 + * ipa-cp.c (self_recursively_generated_p): Find matched aggregate + lattice for a value to check. + (propagate_vals_across_arith_jfunc): Add an assertion to ensure + finite propagation in self-recursive scc. + 2020-01-08 Luo Xiong Hu * ipa-inline.c (caller_growth_limits): Restore the AND. diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c index 4381b35a809..11631986293 100644 --- a/gcc/ipa-cp.c +++ b/gcc/ipa-cp.c @@ -1917,10 +1917,25 @@ self_recursively_generated_p (ipcp_value *val) class ipcp_param_lattices *plats = ipa_get_parm_lattices (info, src->index); - ipcp_lattice *src_lat = src->offset == -1 ? &plats->itself - : plats->aggs; + ipcp_lattice *src_lat; ipcp_value *src_val; + if (src->offset == -1) + src_lat = &plats->itself; + else + { + struct ipcp_agg_lattice *src_aglat; + + for (src_aglat = plats->aggs; src_aglat; src_aglat = src_aglat->next) + if (src_aglat->offset == src->offset) + break; + + if (!src_aglat) + return false; + + src_lat = src_aglat; + } + for (src_val = src_lat->values; src_val; src_val = src_val->next) if (src_val == val) break; @@ -2017,6 +2032,8 @@ propagate_vals_across_arith_jfunc (cgraph_edge *cs, val_seeds.safe_push (src_val); } + gcc_assert ((int) val_seeds.length () <= param_ipa_cp_value_list_size); + /* Recursively generate lattice values with a limited count. */ FOR_EACH_VEC_ELT (val_seeds, i, src_val) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ec35056910b..8ee00cebcfc 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-01-08 Feng Xue + + PR ipa/93084 + * gcc.dg/ipa/ipa-clone-3.c: New test. + 2020-01-07 Paolo Carlini * g++.old-deja/g++.bugs/900208_03.C: Check locations too. diff --git a/gcc/testsuite/gcc.dg/ipa/ipa-clone-3.c b/gcc/testsuite/gcc.dg/ipa/ipa-clone-3.c new file mode 100644 index 00000000000..18d29bdd0b3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/ipa-clone-3.c @@ -0,0 +1,42 @@ +/* { dg-do compile } */ +/* { dg-options "-O3 -fdump-ipa-cp-details -fno-early-inlining --param ipa-cp-max-recursive-depth=8 --param ipa-cp-eval-threshold=1" } */ + +struct V { + int f0; + int f1; +}; + +int data[100]; + +int fn (); + +int recur_fn (struct V * __restrict v) +{ + int i = v->f0; + int j = v->f1; + struct V t; + + if (j > 100) + { + fn (); + return 1; + } + + data[i] = i; + + t.f0 = i - 2; + t.f1 = j + 1; + + recur_fn (&t); + + return i * j; +} + +int main () +{ + struct V v = {1, 3}; + + return recur_fn (&v); +} + +/* { dg-final { scan-ipa-dump-times "Creating a specialized node of recur_fn/\[0-9\]*\\." 8 "cp" } } */