]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Zero local estimated benefit for cloning extern inline function
authorMartin Jambor <mjambor@suse.cz>
Thu, 14 Mar 2019 16:54:43 +0000 (17:54 +0100)
committerMartin Jambor <jamborm@gcc.gnu.org>
Thu, 14 Mar 2019 16:54:43 +0000 (17:54 +0100)
2019-03-14  Martin Jambor  <mjambor@suse.cz>

Backport from mainline
2019-03-07  Martin Jambor  <mjambor@suse.cz>

PR lto/87525
* ipa-cp.c (perform_estimation_of_a_value): Account zero time benefit
for extern inline functions.

testsuite/
* gcc.dg/ipa/ipcp-5.c: New test.

From-SVN: r269688

gcc/ChangeLog
gcc/ipa-cp.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/ipa/ipcp-5.c [new file with mode: 0644]

index d3f9e5b1fd76169fde85c9ad3457ffeea38f2ab7..288c1ac1fff717b53a12aeb58a1ffb1b59b96a60 100644 (file)
@@ -1,3 +1,12 @@
+2019-03-14  Martin Jambor  <mjambor@suse.cz>
+
+       Backport from mainline
+       2019-03-07  Martin Jambor  <mjambor@suse.cz>
+
+       PR lto/87525
+       * ipa-cp.c (perform_estimation_of_a_value): Account zero time benefit
+       for extern inline functions.
+
 2019-03-14  Richard Biener  <rguenther@suse.de>
 
        Backport from mainline
index b42cfb0f6e0268000966b3f74b88dcddf11896a3..56a95754c7f2540de8daca3d992db217c4160ab8 100644 (file)
@@ -2819,11 +2819,18 @@ perform_estimation_of_a_value (cgraph_node *node, vec<tree> known_csts,
   estimate_ipcp_clone_size_and_time (node, known_csts, known_contexts,
                                     known_aggs_ptrs, &size, &time,
                                     &hints);
-  time_benefit = base_time - time
-    + devirtualization_time_bonus (node, known_csts, known_contexts,
-                                  known_aggs_ptrs)
-    + hint_time_bonus (hints)
-    + removable_params_cost + est_move_cost;
+
+  /* Extern inline functions have no cloning local time benefits because they
+     will be inlined anyway.  The only reason to clone them is if it enables
+     optimization in any of the functions they call.  */
+  if (DECL_EXTERNAL (node->decl) && DECL_DECLARED_INLINE_P (node->decl))
+    time_benefit = 0;
+  else
+    time_benefit = base_time - time
+      + devirtualization_time_bonus (node, known_csts, known_contexts,
+                                    known_aggs_ptrs)
+      + hint_time_bonus (hints)
+      + removable_params_cost + est_move_cost;
 
   gcc_checking_assert (size >=0);
   /* The inliner-heuristics based estimates may think that in certain
index 6061fba0b3650a3f18ac011053c116582f84616b..c4312ffa27100b1736d157736bd9bd17ce143e34 100644 (file)
@@ -1,3 +1,11 @@
+2019-03-14  Martin Jambor  <mjambor@suse.cz>
+
+       Backport from mainline
+       2019-03-07  Martin Jambor  <mjambor@suse.cz>
+
+       PR lto/87525
+       * gcc.dg/ipa/ipcp-5.c: New test.
+
 2019-03-14  Richard Biener  <rguenther@suse.de>
 
        Backport from mainline
diff --git a/gcc/testsuite/gcc.dg/ipa/ipcp-5.c b/gcc/testsuite/gcc.dg/ipa/ipcp-5.c
new file mode 100644 (file)
index 0000000..6786c51
--- /dev/null
@@ -0,0 +1,45 @@
+/* Test that estimated local cloning time benefit of extern inline functions is
+   zero.  */
+
+/* { dg-do compile } */
+/* { dg-options "-O3 -fdump-ipa-cp -fno-early-inlining"  } */
+/* { dg-add-options bind_pic_locally } */
+
+extern int get_int (void);
+extern void use_stuff (int);
+
+int arr[10];
+
+inline void
+f (int a)
+{
+  arr[0] += a + 5;
+  arr[1] += a + 50;
+  arr[2] += a - 3;
+  arr[3] += a;
+  arr[4] += a + 21;
+  arr[5] += a + 900;
+  arr[6] += a + 2;
+  arr[7] += a + 3456;
+  arr[8] += a + 3;
+  arr[9] += a + 32;
+  use_stuff (a);
+}
+
+
+int
+entry (void)
+{
+  int i;
+  for (i = 0; i < 100; i++)
+    f (7);
+  for (i = 0; i < 100; i++)
+    f (get_int ());
+  return 0;
+}
+
+
+/* { dg-final { scan-ipa-dump "loc_time: 0" "cp" } } */
+/* { dg-final { scan-ipa-dump-not "replacing param.*with const" "cp"  } } */
+
+