Fix missed IPA-CP on by-ref argument directly passed through (PR 93429)
authorFeng Xue <fxue@os.amperecomputing.com>
Fri, 24 Jan 2020 15:09:28 +0000 (23:09 +0800)
committerFeng Xue <fxue@os.amperecomputing.com>
Mon, 1 Jun 2020 06:10:04 +0000 (14:10 +0800)
2020-06-01  Feng Xue  <fxue@os.amperecomputing.com>

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
gcc/testsuite/gcc.dg/ipa/ipcp-agg-13.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/ipa/ipcp-agg-8.c

index c64e9104a94411891a82367dc79cec2d9313fcd3..b0c8f40526002a7efebfa813ec181f144bb532e4 100644 (file)
@@ -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 (file)
index 0000000..47e9e53
--- /dev/null
@@ -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" } } */ 
index a2a870d2e1a0c1d48010e72ac3526ecfa09c2e11..2d9c82f7310b0fd398d9c350690f7c7f8a3b7799 100644 (file)
@@ -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" } } */