From 32633ec815b4d741a9a4b1b75de235844f6d691c Mon Sep 17 00:00:00 2001 From: Feng Xue Date: Fri, 24 Jan 2020 23:09:28 +0800 Subject: [PATCH] Fix missed IPA-CP on by-ref argument directly passed through (PR 93429) 2020-06-01 Feng Xue gcc/ PR ipa/93429 * ipa-cp.c (propagate_aggs_across_jump_function): Check aggregate lattice for simple pass-through by-ref argument. gcc/testsuite/ PR ipa/93429 * gcc.dg/ipa/ipcp-agg-8.c: Change dump string. * gcc.dg/ipa/ipcp-agg-13.c: New test. --- gcc/ipa-cp.c | 23 ++++++------- gcc/testsuite/gcc.dg/ipa/ipcp-agg-13.c | 45 ++++++++++++++++++++++++++ gcc/testsuite/gcc.dg/ipa/ipcp-agg-8.c | 5 +-- 3 files changed, 57 insertions(+), 16 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/ipa/ipcp-agg-13.c diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c index c64e9104a94..b0c8f405260 100644 --- a/gcc/ipa-cp.c +++ b/gcc/ipa-cp.c @@ -2735,9 +2735,8 @@ propagate_aggs_across_jump_function (struct cgraph_edge *cs, gcc_assert (!jfunc->agg.items); ret |= merge_aggregate_lattices (cs, dest_plats, src_plats, src_idx, 0); + return ret; } - else - ret |= set_agg_lats_contain_variable (dest_plats); } else if (jfunc->type == IPA_JF_ANCESTOR && ipa_get_jf_ancestor_agg_preserved (jfunc)) @@ -2759,8 +2758,10 @@ propagate_aggs_across_jump_function (struct cgraph_edge *cs, ret |= set_agg_lats_to_bottom (dest_plats); else ret |= set_agg_lats_contain_variable (dest_plats); + return ret; } - else if (jfunc->agg.items) + + if (jfunc->agg.items) { bool pre_existing = dest_plats->aggs != NULL; struct ipcp_agg_lattice **aglat = &dest_plats->aggs; @@ -4988,11 +4989,7 @@ intersect_aggregates_with_edge (struct cgraph_edge *cs, int index, else intersect_with_agg_replacements (cs->caller, src_idx, &inter, 0); - } - else - { - inter.release (); - return vNULL; + return inter; } } else @@ -5008,11 +5005,7 @@ intersect_aggregates_with_edge (struct cgraph_edge *cs, int index, inter = copy_plats_to_inter (src_plats, 0); else intersect_with_plats (src_plats, &inter, 0); - } - else - { - inter.release (); - return vNULL; + return inter; } } } @@ -5043,8 +5036,10 @@ intersect_aggregates_with_edge (struct cgraph_edge *cs, int index, else intersect_with_plats (src_plats, &inter, delta); } + return inter; } - else if (jfunc->agg.items) + + if (jfunc->agg.items) { class ipa_node_params *caller_info = IPA_NODE_REF (cs->caller); struct ipa_agg_value *item; diff --git a/gcc/testsuite/gcc.dg/ipa/ipcp-agg-13.c b/gcc/testsuite/gcc.dg/ipa/ipcp-agg-13.c new file mode 100644 index 00000000000..47e9e530aa9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/ipcp-agg-13.c @@ -0,0 +1,45 @@ +/* { dg-do compile } */ +/* { dg-options "-O3 -fno-ipa-sra -fdump-ipa-cp --param ipa-cp-eval-threshold=1" } */ + +int data; +int fn(); + +int __attribute__((noinline)) f1 (int *p) +{ + data = *p; + fn (); + return 0; +} + +int __attribute__((noinline)) f2 (int *p) +{ + *p = *p + 1; + f1 (p); + return 1; +} + +int __attribute__((noinline)) f3 (int a, int *p) +{ + *p = a - 2; + f1 (p); + return 1; +} + +int f4 () +{ + int i; + + for (i = 0; i < 100; i++) + { + int v = 2; + + f2 (&v); + f3 (6, &v); + } + + return 0; +} + +/* { dg-final { scan-ipa-dump "Aggregate replacements: 0\\\[0]=2" "cp" } } */ +/* { dg-final { scan-ipa-dump "Aggregate replacements: 0\\\[0]=3" "cp" } } */ +/* { dg-final { scan-ipa-dump "Aggregate replacements: 0\\\[0]=4" "cp" } } */ diff --git a/gcc/testsuite/gcc.dg/ipa/ipcp-agg-8.c b/gcc/testsuite/gcc.dg/ipa/ipcp-agg-8.c index a2a870d2e1a..2d9c82f7310 100644 --- a/gcc/testsuite/gcc.dg/ipa/ipcp-agg-8.c +++ b/gcc/testsuite/gcc.dg/ipa/ipcp-agg-8.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-O3 -fno-ipa-sra -fdump-tree-optimized-slim" } */ +/* { dg-options "-O3 -fno-ipa-sra -fdump-ipa-cp" } */ /* { dg-add-options bind_pic_locally } */ struct S @@ -48,4 +48,5 @@ entry (int c) foo (4, i, &s); } } -/* { dg-final { scan-tree-dump "->b;" "optimized" } } */ +/* { dg-final { scan-ipa-dump "Aggregate replacements: 1\\\[32]=64, 1\\\[64]=32" "cp" } } */ +/* { dg-final { scan-ipa-dump "Aggregate replacements: 1\\\[32]=0" "cp" } } */ -- 2.30.2