[gcc(refs/vendors/redhat/heads/gcc-10-branch)] ipa: Fix removal of multi-target speculation.

Jakub Jelinek jakub@gcc.gnu.org
Thu Jan 30 20:54:00 GMT 2020


https://gcc.gnu.org/g:7c7107778f16c2db6e97e73fdec6d6606b619864

commit 7c7107778f16c2db6e97e73fdec6d6606b619864
Author: Jan Hubicka <jh@suse.cz>
Date:   Wed Jan 29 12:43:10 2020 +0100

    ipa: Fix removal of multi-target speculation.
    
    	* cgraph.c (cgraph_edge::resolve_speculation): Only lookup direct edge
    	if called on indirect edge.
    	(cgraph_edge::redirect_call_stmt_to_callee): Lookup indirect edge of
    	speculative call if needed.
    
    	* gcc.dg/tree-prof/indir-call-prof-2.c: New testcase.

Diff:
---
 gcc/ChangeLog                                      |  7 +++++
 gcc/cgraph.c                                       |  8 +++--
 gcc/testsuite/ChangeLog                            |  4 +++
 gcc/testsuite/gcc.dg/tree-prof/indir-call-prof-2.c | 35 ++++++++++++++++++++++
 4 files changed, 52 insertions(+), 2 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index f6959ef..504486c 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+2020-01-28  Jan Hubicka  <hubicka@ucw.cz>
+
+	* cgraph.c (cgraph_edge::resolve_speculation): Only lookup direct edge
+	if called on indirect edge.
+	(cgraph_edge::redirect_call_stmt_to_callee): Lookup indirect edge of
+	speculative call if needed.
+
 2020-01-29  Richard Biener  <rguenther@suse.de>
 
 	PR tree-optimization/93428
diff --git a/gcc/cgraph.c b/gcc/cgraph.c
index 3e50b0b..294b2d3 100644
--- a/gcc/cgraph.c
+++ b/gcc/cgraph.c
@@ -1189,7 +1189,10 @@ cgraph_edge::resolve_speculation (cgraph_edge *edge, tree callee_decl)
   ipa_ref *ref;
 
   gcc_assert (edge->speculative && (!callee_decl || edge->callee));
-  e2 = edge->first_speculative_call_target ();
+  if (!edge->callee)
+    e2 = edge->first_speculative_call_target ();
+  else
+    e2 = edge;
   ref = e2->speculative_call_target_ref ();
   edge = edge->speculative_call_indirect_edge ();
   if (!callee_decl
@@ -1364,7 +1367,8 @@ cgraph_edge::redirect_call_stmt_to_callee (cgraph_edge *e)
       /* If there already is an direct call (i.e. as a result of inliner's
 	 substitution), forget about speculating.  */
       if (decl)
-	e = make_direct (e, cgraph_node::get (decl));
+	e = make_direct (e->speculative_call_indirect_edge (),
+			 cgraph_node::get (decl));
       else
 	{
 	  /* Be sure we redirect all speculative targets before poking
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 01769a8..0551884 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2020-01-28  Jan Hubicka  <hubicka@ucw.cz>
+
+	* gcc.dg/tree-prof/indir-call-prof-2.c: New testcase.
+
 2020-01-29  Richard Sandiford  <richard.sandiford@arm.com>
 
 	PR testsuite/93393
diff --git a/gcc/testsuite/gcc.dg/tree-prof/indir-call-prof-2.c b/gcc/testsuite/gcc.dg/tree-prof/indir-call-prof-2.c
new file mode 100644
index 0000000..bbba052
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-prof/indir-call-prof-2.c
@@ -0,0 +1,35 @@
+/* { dg-options "-O2 -fno-early-inlining -fdump-ipa-profile-optimized -fdump-ipa-afdo" } */
+volatile int one;
+static int
+add1 (int val)
+{
+  return val += one;
+}
+
+static int
+sub1 (int val)
+{
+  return val -= one;
+}
+
+static int
+do_op (int val, int (*fnptr) (int))
+{
+  return fnptr (val);
+}
+
+int
+main (void)
+{
+  int i, val = 0;
+  for (i = 0; i < 100000; i++)
+    {
+      val = do_op (val, add1);
+      val = do_op (val, sub1);
+    }
+  return val;
+}
+/* { dg-final-use-not-autofdo { scan-ipa-dump "Indirect call -> direct call.* add1 .will resolve by ipa-profile" "profile"} } */
+/* { dg-final-use-not-autofdo { scan-ipa-dump "Indirect call -> direct call.* sub1 .will resolve by ipa-profile" "profile"} } */
+/* { dg-final-use-autofdo { scan-ipa-dump "Indirect call -> direct call.* add1 .will resolve by ipa-profile" "afdo"} } */
+/* { dg-final-use-autofdo { scan-ipa-dump "Indirect call -> direct call.* sub1 .will resolve by ipa-profile" "afdo"} } */



More information about the Gcc-cvs mailing list