From 983398517e18629db71d6a75bc7e50c3df44b3d4 Mon Sep 17 00:00:00 2001
From: Dehao Chen <dehao@google.com>
Date: Tue, 20 May 2014 22:25:06 +0000
Subject: [PATCH] ipa-inline-transform.c (clone_inlined_nodes): Use min of edge
 count and callee count to get clone count.

2014-05-20  Dehao Chen  <dehao@google.com>

	* ipa-inline-transform.c (clone_inlined_nodes): Use min of edge count
	and callee count to get clone count.
	* tree-inline.c (expand_call_inline): Use callee count instead of bb
	count in copy_body.

From-SVN: r210660
---
 gcc/ChangeLog              | 7 +++++++
 gcc/ipa-inline-transform.c | 5 +++--
 gcc/tree-inline.c          | 2 +-
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 1fad15b10109..0b1900e792b2 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+2014-05-20  Dehao Chen  <dehao@google.com>
+
+	* ipa-inline-transform.c (clone_inlined_nodes): Use min of edge count
+	and callee count to get clone count.
+	* tree-inline.c (expand_call_inline): Use callee count instead of bb
+	count in copy_body.
+
 2014-05-20  Richard Sandiford  <rdsandiford@googlemail.com>
 
 	PR rtl-optimization/61243
diff --git a/gcc/ipa-inline-transform.c b/gcc/ipa-inline-transform.c
index a45aab118fdf..7cd3ff740e0e 100644
--- a/gcc/ipa-inline-transform.c
+++ b/gcc/ipa-inline-transform.c
@@ -183,8 +183,9 @@ clone_inlined_nodes (struct cgraph_edge *e, bool duplicate,
 	  if (freq_scale == -1)
 	    freq_scale = e->frequency;
 	  n = cgraph_clone_node (e->callee, e->callee->decl,
-				 e->count, freq_scale, update_original,
-				 vNULL, true, inlining_into, NULL);
+				 MIN (e->count, e->callee->count), freq_scale,
+				 update_original, vNULL, true, inlining_into,
+				 NULL);
 	  cgraph_redirect_edge_callee (e, n);
 	}
     }
diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c
index bc2b2712b05a..3208c7403f4f 100644
--- a/gcc/tree-inline.c
+++ b/gcc/tree-inline.c
@@ -4355,7 +4355,7 @@ expand_call_inline (basic_block bb, gimple stmt, copy_body_data *id)
      function in any way before this point, as this CALL_EXPR may be
      a self-referential call; if we're calling ourselves, we need to
      duplicate our body before altering anything.  */
-  copy_body (id, bb->count,
+  copy_body (id, cg_edge->callee->count,
   	     GCOV_COMPUTE_SCALE (cg_edge->frequency, CGRAPH_FREQ_BASE),
 	     bb, return_block, NULL);