[{"id":1798105,"web_url":"http://patchwork.ozlabs.org/comment/1798105/","msgid":"<da7c915d-aa07-76d3-d79d-9e90419bbd79@suse.cz>","list_archive_url":null,"date":"2017-11-02T17:17:59","subject":"Re: Drop frequencies from basic blocks","submitter":{"id":62010,"url":"http://patchwork.ozlabs.org/api/people/62010/","name":"Martin Liška","email":"mliska@suse.cz"},"content":"Hi Honza.\n\nThanks for the huge patch. I'm willing to help you with testing, but I can't\napply the patch on top of r254348:\n\n../../gcc/profile.c: In function ‘void compute_branch_probabilities(unsigned int, unsigned int)’:\n../../gcc/profile.c:794:11: error: ‘flag_guess_branch_probability’ was not declared in this scope\n        || !flag_guess_branch_probability)\n            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n../../gcc/profile.c:794:11: note: suggested alternative: ‘OPT_fguess_branch_probability’\n        || !flag_guess_branch_probability)\n            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n            OPT_fguess_branch_probability\n../../gcc/profile.c:801:21: error: no match for ‘operator!=’ (operand types are ‘profile_count’ and ‘profile_count’)\n        if (bb->count != profile_count::zero ())\n            ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~\nIn file included from ../../gcc/coretypes.h:397:0,\n                  from ../../gcc/profile.c:52:\n../../gcc/wide-int.h:3158:19: note: candidate: template<class T1, class T2> typename wi::binary_traits<T1, T2>::predicate_result operator!=(const T1&, const T2&)\n  BINARY_PREDICATE (operator !=, ne_p)\n                    ^\n../../gcc/wide-int.h:3142:3: note: in definition of macro ‘BINARY_PREDICATE’\n    OP (const T1 &x, const T2 &y) \\\n    ^~\n../../gcc/wide-int.h:3158:19: note:   template argument deduction/substitution failed:\n  BINARY_PREDICATE (operator !=, ne_p)\n                    ^\n../../gcc/wide-int.h:3142:3: note: in definition of macro ‘BINARY_PREDICATE’\n    OP (const T1 &x, const T2 &y) \\\n    ^~\n../../gcc/wide-int.h: In substitution of ‘template<class T1, class T2> typename wi::binary_traits<T1, T2>::predicate_result operator!=(const T1&, const T2&) [with T1 = profile_count; T2 = profile_count]’:\n../../gcc/profile.c:801:45:   required from here\n../../gcc/wide-int.h:3158:19: error: incomplete type ‘wi::int_traits<profile_count>’ used in nested name specifier\n  BINARY_PREDICATE (operator !=, ne_p)\n                    ^\n../../gcc/wide-int.h:3142:3: note: in definition of macro ‘BINARY_PREDICATE’\n    OP (const T1 &x, const T2 &y) \\\n    ^~\n\nCan you please check that?\n\nThanks,\nMartin","headers":{"Return-Path":"<gcc-patches-return-465772-incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list gcc-patches@gcc.gnu.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=gcc-patches-return-465772-incoming=patchwork.ozlabs.org@gcc.gnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tunprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org\n\theader.b=\"f8NkXeCo\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3ySWxz0N0bz9s81\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri,  3 Nov 2017 04:18:13 +1100 (AEDT)","(qmail 21251 invoked by alias); 2 Nov 2017 17:18:05 -0000","(qmail 21234 invoked by uid 89); 2 Nov 2017 17:18:04 -0000","from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by\n\tsourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP;\n\tThu, 02 Nov 2017 17:18:02 +0000","from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254])\tby\n\tmx2.suse.de (Postfix) with ESMTP id 65B87ADDF;\n\tThu,  2 Nov 2017 17:18:00 +0000 (UTC)"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender\n\t:subject:to:references:from:message-id:date:mime-version\n\t:in-reply-to:content-type:content-transfer-encoding; q=dns; s=\n\tdefault; b=eN4rDDkq/GIE9pecEjWiFbpzogMxCzNv+49Qold0ndbkg9HfzeaUn\n\tWq0RUqUZZL+xM5DtNRZC0VSS6OjvTE3gD9mq1Li6BG2pzc38AePCCPxznYn1Ntjr\n\tTVnM1YZXm2O3Al3p2Xyim/lYvc0Vap9n4hJyxGY8SfZaUr+xMD4+OI=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender\n\t:subject:to:references:from:message-id:date:mime-version\n\t:in-reply-to:content-type:content-transfer-encoding; s=default;\n\tbh=RD4s6HdKcqciKlqajxzL7/YmAko=; b=f8NkXeCoz/JIy0xN7TrHP1kH4/mr\n\tXRqJrPTDae4vylaM+UnNW9GFS/sd5ZV2Zks5D74p3RRqHCLzsd/OsALZLGgSC0Sy\n\tL9XY8I3DopgwbUYYXfrRAmWkhgy7QAzZinJmEgoOU5+fnt5tvt8WdJf6i7L0zO3G\n\tK0NvEkwcmaO2khU=","Mailing-List":"contact gcc-patches-help@gcc.gnu.org; run by ezmlm","Precedence":"bulk","List-Id":"<gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<mailto:gcc-patches-unsubscribe-incoming=patchwork.ozlabs.org@gcc.gnu.org>","List-Archive":"<http://gcc.gnu.org/ml/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-help@gcc.gnu.org>","Sender":"gcc-patches-owner@gcc.gnu.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-1.9 required=5.0 tests=BAYES_00,\n\tSPF_PASS autolearn=ham version=3.3.2\n\tspammy=HContent-Transfer-Encoding:8bit","X-HELO":"mx2.suse.de","Subject":"Re: Drop frequencies from basic blocks","To":"Jan Hubicka <hubicka@ucw.cz>, gcc-patches@gcc.gnu.org","References":"<20171102153225.GA53964@kam.mff.cuni.cz>","From":"=?utf-8?q?Martin_Li=C5=A1ka?= <mliska@suse.cz>","Message-ID":"<da7c915d-aa07-76d3-d79d-9e90419bbd79@suse.cz>","Date":"Thu, 2 Nov 2017 18:17:59 +0100","User-Agent":"Mozilla/5.0 (X11; Linux x86_64;\n\trv:52.0) Gecko/20100101 Thunderbird/52.4.0","MIME-Version":"1.0","In-Reply-To":"<20171102153225.GA53964@kam.mff.cuni.cz>","Content-Type":"text/plain; charset=utf-8; format=flowed","Content-Transfer-Encoding":"8bit","X-IsSubscribed":"yes"}},{"id":1798200,"web_url":"http://patchwork.ozlabs.org/comment/1798200/","msgid":"<20171102190652.GB31407@kam.mff.cuni.cz>","list_archive_url":null,"date":"2017-11-02T19:06:52","subject":"Re: Drop frequencies from basic blocks","submitter":{"id":4327,"url":"http://patchwork.ozlabs.org/api/people/4327/","name":"Jan Hubicka","email":"hubicka@ucw.cz"},"content":"> Hi Honza.\n> \n> Thanks for the huge patch. I'm willing to help you with testing, but I can't\n> apply the patch on top of r254348:\n\nSorry, I must have used older diff file, because it is one of unfinished chnages I made today.\nI am attaching correct diff.\n\nIndex: asan.c\n===================================================================\n--- asan.c\t(revision 254348)\n+++ asan.c\t(working copy)\n@@ -1801,6 +1801,7 @@ create_cond_insert_point (gimple_stmt_it\n     ? profile_probability::very_unlikely ()\n     : profile_probability::very_likely ();\n   e->probability = fallthrough_probability.invert ();\n+  then_bb->count = e->count ();\n   if (create_then_fallthru_edge)\n     make_single_succ_edge (then_bb, fallthru_bb, EDGE_FALLTHRU);\n \nIndex: basic-block.h\n===================================================================\n--- basic-block.h\t(revision 254348)\n+++ basic-block.h\t(working copy)\n@@ -148,9 +148,6 @@ struct GTY((chain_next (\"%h.next_bb\"), c\n   /* Expected number of executions: calculated in profile.c.  */\n   profile_count count;\n \n-  /* Expected frequency.  Normalized to be in range 0 to BB_FREQ_MAX.  */\n-  int frequency;\n-\n   /* The discriminator for this block.  The discriminator distinguishes\n      among several basic blocks that share a common locus, allowing for\n      more accurate sample-based profiling.  */\n@@ -301,7 +298,7 @@ enum cfg_bb_flags\n \t\t\t\t\t ? EDGE_SUCC ((bb), 1) : EDGE_SUCC ((bb), 0))\n \n /* Return expected execution frequency of the edge E.  */\n-#define EDGE_FREQUENCY(e)\t\te->probability.apply (e->src->frequency)\n+#define EDGE_FREQUENCY(e)\t\te->count ().to_frequency (cfun)\n \n /* Compute a scale factor (or probability) suitable for scaling of\n    gcov_type values via apply_probability() and apply_scale().  */\nIndex: bb-reorder.c\n===================================================================\n--- bb-reorder.c\t(revision 254348)\n+++ bb-reorder.c\t(working copy)\n@@ -256,8 +256,8 @@ push_to_next_round_p (const_basic_block\n \n   there_exists_another_round = round < number_of_rounds - 1;\n \n-  block_not_hot_enough = (bb->frequency < exec_th\n-\t\t\t  || bb->count < count_th\n+  block_not_hot_enough = (bb->count.to_frequency (cfun) < exec_th\n+\t\t\t  || bb->count.ipa () < count_th\n \t\t\t  || probably_never_executed_bb_p (cfun, bb));\n \n   if (there_exists_another_round\n@@ -293,9 +293,9 @@ find_traces (int *n_traces, struct trace\n     {\n       bbd[e->dest->index].heap = heap;\n       bbd[e->dest->index].node = heap->insert (bb_to_key (e->dest), e->dest);\n-      if (e->dest->frequency > max_entry_frequency)\n-\tmax_entry_frequency = e->dest->frequency;\n-      if (e->dest->count.initialized_p () && e->dest->count > max_entry_count)\n+      if (e->dest->count.to_frequency (cfun) > max_entry_frequency)\n+\tmax_entry_frequency = e->dest->count.to_frequency (cfun);\n+      if (e->dest->count.ipa_p () && e->dest->count > max_entry_count)\n \tmax_entry_count = e->dest->count;\n     }\n \n@@ -329,8 +329,10 @@ find_traces (int *n_traces, struct trace\n \t  for (bb = traces[i].first;\n \t       bb != traces[i].last;\n \t       bb = (basic_block) bb->aux)\n-\t    fprintf (dump_file, \"%d [%d] \", bb->index, bb->frequency);\n-\t  fprintf (dump_file, \"%d [%d]\\n\", bb->index, bb->frequency);\n+\t    fprintf (dump_file, \"%d [%d] \", bb->index,\n+\t\t     bb->count.to_frequency (cfun));\n+\t  fprintf (dump_file, \"%d [%d]\\n\", bb->index,\n+\t\t   bb->count.to_frequency (cfun));\n \t}\n       fflush (dump_file);\n     }\n@@ -551,7 +553,7 @@ find_traces_1_round (int branch_th, int\n \t\tcontinue;\n \n \t      prob = e->probability;\n-\t      freq = e->dest->frequency;\n+\t      freq = e->dest->count.to_frequency (cfun);\n \n \t      /* The only sensible preference for a call instruction is the\n \t\t fallthru edge.  Don't bother selecting anything else.  */\n@@ -573,7 +575,7 @@ find_traces_1_round (int branch_th, int\n \t\t  || !prob.initialized_p ()\n \t\t  || ((prob.to_reg_br_prob_base () < branch_th\n \t\t       || EDGE_FREQUENCY (e) < exec_th\n-\t\t      || e->count () < count_th) && (!for_size)))\n+\t\t      || e->count ().ipa () < count_th) && (!for_size)))\n \t\tcontinue;\n \n \t      if (better_edge_p (bb, e, prob, freq, best_prob, best_freq,\n@@ -671,7 +673,7 @@ find_traces_1_round (int branch_th, int\n \t\t      || !prob.initialized_p ()\n \t\t      || prob.to_reg_br_prob_base () < branch_th\n \t\t      || freq < exec_th\n-\t\t      || e->count () < count_th)\n+\t\t      || e->count ().ipa () < count_th)\n \t\t    {\n \t\t      /* When partitioning hot/cold basic blocks, make sure\n \t\t\t the cold blocks (and only the cold blocks) all get\n@@ -706,7 +708,7 @@ find_traces_1_round (int branch_th, int\n \t\t  if (best_edge->dest != bb)\n \t\t    {\n \t\t      if (EDGE_FREQUENCY (best_edge)\n-\t\t\t  > 4 * best_edge->dest->frequency / 5)\n+\t\t\t  > 4 * best_edge->dest->count.to_frequency (cfun) / 5)\n \t\t\t{\n \t\t\t  /* The loop has at least 4 iterations.  If the loop\n \t\t\t     header is not the first block of the function\n@@ -783,8 +785,8 @@ find_traces_1_round (int branch_th, int\n \t\t\t    & EDGE_CAN_FALLTHRU)\n \t\t\t&& !(single_succ_edge (e->dest)->flags & EDGE_COMPLEX)\n \t\t\t&& single_succ (e->dest) == best_edge->dest\n-\t\t\t&& (2 * e->dest->frequency >= EDGE_FREQUENCY (best_edge)\n-\t\t\t    || for_size))\n+\t\t\t&& (2 * e->dest->count.to_frequency (cfun)\n+\t\t\t    >= EDGE_FREQUENCY (best_edge) || for_size))\n \t\t      {\n \t\t\tbest_edge = e;\n \t\t\tif (dump_file)\n@@ -945,9 +947,9 @@ bb_to_key (basic_block bb)\n \n   if (priority)\n     /* The block with priority should have significantly lower key.  */\n-    return -(100 * BB_FREQ_MAX + 100 * priority + bb->frequency);\n+    return -(100 * BB_FREQ_MAX + 100 * priority + bb->count.to_frequency (cfun));\n \n-  return -bb->frequency;\n+  return -bb->count.to_frequency (cfun);\n }\n \n /* Return true when the edge E from basic block BB is better than the temporary\n@@ -1290,7 +1292,7 @@ connect_traces (int n_traces, struct tra\n \t\t\t\t&& !connected[bbd[di].start_of_trace]\n \t\t\t\t&& BB_PARTITION (e2->dest) == current_partition\n \t\t\t\t&& EDGE_FREQUENCY (e2) >= freq_threshold\n-\t\t\t\t&& e2->count () >= count_threshold\n+\t\t\t\t&& e2->count ().ipa () >= count_threshold\n \t\t\t\t&& (!best2\n \t\t\t\t    || e2->probability > best2->probability\n \t\t\t\t    || (e2->probability == best2->probability\n@@ -1317,7 +1319,7 @@ connect_traces (int n_traces, struct tra\n \t\t\t\toptimize_edge_for_speed_p (best)\n \t\t\t\t&& EDGE_FREQUENCY (best) >= freq_threshold\n \t\t\t\t&& (!best->count ().initialized_p ()\n-\t\t\t\t    || best->count () >= count_threshold)))\n+\t\t\t\t    || best->count ().ipa () >= count_threshold)))\n \t\t{\n \t\t  basic_block new_bb;\n \n@@ -1375,7 +1377,7 @@ copy_bb_p (const_basic_block bb, int cod\n   int max_size = uncond_jump_length;\n   rtx_insn *insn;\n \n-  if (!bb->frequency)\n+  if (!bb->count.to_frequency (cfun))\n     return false;\n   if (EDGE_COUNT (bb->preds) < 2)\n     return false;\n@@ -1459,7 +1461,6 @@ fix_up_crossing_landing_pad (eh_landing_\n   last_bb = EXIT_BLOCK_PTR_FOR_FN (cfun)->prev_bb;\n   new_bb = create_basic_block (new_label, jump, last_bb);\n   new_bb->aux = last_bb->aux;\n-  new_bb->frequency = post_bb->frequency;\n   new_bb->count = post_bb->count;\n   last_bb->aux = new_bb;\n \n@@ -1517,7 +1518,6 @@ sanitize_hot_paths (bool walk_up, unsign\n       edge_iterator ei;\n       profile_probability highest_probability\n \t\t\t\t = profile_probability::uninitialized ();\n-      int highest_freq = 0;\n       profile_count highest_count = profile_count::uninitialized ();\n       bool found = false;\n \n@@ -1544,11 +1544,8 @@ sanitize_hot_paths (bool walk_up, unsign\n           /* The following loop will look for the hottest edge via\n              the edge count, if it is non-zero, then fallback to the edge\n              frequency and finally the edge probability.  */\n-          if (!highest_count.initialized_p () || e->count () > highest_count)\n+          if (!(e->count () > highest_count))\n             highest_count = e->count ();\n-          int edge_freq = EDGE_FREQUENCY (e);\n-          if (edge_freq > highest_freq)\n-            highest_freq = edge_freq;\n           if (!highest_probability.initialized_p ()\n \t      || e->probability > highest_probability)\n             highest_probability = e->probability;\n@@ -1573,17 +1570,12 @@ sanitize_hot_paths (bool walk_up, unsign\n           /* Select the hottest edge using the edge count, if it is non-zero,\n              then fallback to the edge frequency and finally the edge\n              probability.  */\n-          if (highest_count > 0)\n+          if (highest_count.initialized_p ())\n             {\n-              if (e->count () < highest_count)\n+              if (!(e->count () >= highest_count))\n                 continue;\n             }\n-          else if (highest_freq)\n-            {\n-              if (EDGE_FREQUENCY (e) < highest_freq)\n-                continue;\n-            }\n-          else if (e->probability < highest_probability)\n+          else if (!(e->probability >= highest_probability))\n             continue;\n \n           basic_block reach_bb = walk_up ? e->src : e->dest;\nIndex: bt-load.c\n===================================================================\n--- bt-load.c\t(revision 254348)\n+++ bt-load.c\t(working copy)\n@@ -185,7 +185,7 @@ static int first_btr, last_btr;\n static int\n basic_block_freq (const_basic_block bb)\n {\n-  return bb->frequency;\n+  return bb->count.to_frequency (cfun);\n }\n \n /* If the rtx at *XP references (sets or reads) any branch target\nIndex: cfg.c\n===================================================================\n--- cfg.c\t(revision 254348)\n+++ cfg.c\t(working copy)\n@@ -68,6 +68,7 @@ init_flow (struct function *the_fun)\n   if (!the_fun->cfg)\n     the_fun->cfg = ggc_cleared_alloc<control_flow_graph> ();\n   n_edges_for_fn (the_fun) = 0;\n+  the_fun->cfg->count_max = profile_count::uninitialized ();\n   ENTRY_BLOCK_PTR_FOR_FN (the_fun)\n     = alloc_block ();\n   ENTRY_BLOCK_PTR_FOR_FN (the_fun)->index = ENTRY_BLOCK;\n@@ -447,13 +448,18 @@ check_bb_profile (basic_block bb, FILE *\n     }\n   if (bb != ENTRY_BLOCK_PTR_FOR_FN (fun))\n     {\n-      int sum = 0;\n+      profile_count sum = profile_count::zero ();\n       FOR_EACH_EDGE (e, ei, bb->preds)\n-\tsum += EDGE_FREQUENCY (e);\n-      if (abs (sum - bb->frequency) > 100)\n-\tfprintf (file,\n-\t\t \";; %sInvalid sum of incoming frequencies %i, should be %i\\n\",\n-\t\t s_indent, sum, bb->frequency);\n+\tsum += e->count ();\n+      if (sum.differs_from_p (bb->count))\n+\t{\n+\t  fprintf (file, \";; %sInvalid sum of incoming counts \",\n+\t\t   s_indent);\n+\t  sum.dump (file);\n+\t  fprintf (file, \", should be \");\n+\t  bb->count.dump (file);\n+\t  fprintf (file, \"\\n\");\n+\t}\n     }\n   if (BB_PARTITION (bb) == BB_COLD_PARTITION)\n     {\n@@ -751,7 +757,6 @@ dump_bb_info (FILE *outf, basic_block bb\n \t      fputs (\", count \", outf);\n \t      bb->count.dump (outf);\n \t    }\n-\t  fprintf (outf, \", freq %i\", bb->frequency);\n \t  if (maybe_hot_bb_p (fun, bb))\n \t    fputs (\", maybe hot\", outf);\n \t  if (probably_never_executed_bb_p (fun, bb))\n@@ -843,15 +848,15 @@ brief_dump_cfg (FILE *file, dump_flags_t\n     }\n }\n \n-/* An edge originally destinating BB of FREQUENCY and COUNT has been proved to\n+/* An edge originally destinating BB of COUNT has been proved to\n    leave the block by TAKEN_EDGE.  Update profile of BB such that edge E can be\n    redirected to destination of TAKEN_EDGE.\n \n    This function may leave the profile inconsistent in the case TAKEN_EDGE\n-   frequency or count is believed to be lower than FREQUENCY or COUNT\n+   frequency or count is believed to be lower than COUNT\n    respectively.  */\n void\n-update_bb_profile_for_threading (basic_block bb, int edge_frequency,\n+update_bb_profile_for_threading (basic_block bb, \n \t\t\t\t profile_count count, edge taken_edge)\n {\n   edge c;\n@@ -866,16 +871,10 @@ update_bb_profile_for_threading (basic_b\n     }\n   bb->count -= count;\n \n-  bb->frequency -= edge_frequency;\n-  if (bb->frequency < 0)\n-    bb->frequency = 0;\n-\n   /* Compute the probability of TAKEN_EDGE being reached via threaded edge.\n      Watch for overflows.  */\n-  if (bb->frequency)\n-    /* FIXME: We should get edge frequency as count.  */\n-    prob = profile_probability::probability_in_gcov_type\n-\t\t (edge_frequency, bb->frequency);\n+  if (bb->count.nonzero_p ())\n+    prob = count.probability_in (bb->count);\n   else\n     prob = profile_probability::never ();\n   if (prob > taken_edge->probability)\n@@ -899,9 +898,9 @@ update_bb_profile_for_threading (basic_b\n   if (prob == profile_probability::never ())\n     {\n       if (dump_file)\n-\tfprintf (dump_file, \"Edge frequencies of bb %i has been reset, \"\n-\t\t \"frequency of block should end up being 0, it is %i\\n\",\n-\t\t bb->index, bb->frequency);\n+\tfprintf (dump_file, \"Edge probabilities of bb %i has been reset, \"\n+\t\t \"count of block should end up being 0, it is non-zero\\n\",\n+\t\t bb->index);\n       EDGE_SUCC (bb, 0)->probability = profile_probability::guessed_always ();\n       ei = ei_start (bb->succs);\n       ei_next (&ei);\n@@ -942,18 +941,10 @@ scale_bbs_frequencies_int (basic_block *\n \n   for (i = 0; i < nbbs; i++)\n     {\n-      bbs[i]->frequency = RDIV (bbs[i]->frequency * num, den);\n-      /* Make sure the frequencies do not grow over BB_FREQ_MAX.  */\n-      if (bbs[i]->frequency > BB_FREQ_MAX)\n-\tbbs[i]->frequency = BB_FREQ_MAX;\n       bbs[i]->count = bbs[i]->count.apply_scale (num, den);\n     }\n }\n \n-/* numbers smaller than this value are safe to multiply without getting\n-   64bit overflow.  */\n-#define MAX_SAFE_MULTIPLIER (1 << (sizeof (int64_t) * 4 - 1))\n-\n /* Multiply all frequencies of basic blocks in array BBS of length NBBS\n    by NUM/DEN, in gcov_type arithmetic.  More accurate than previous\n    function but considerably slower.  */\n@@ -962,28 +953,9 @@ scale_bbs_frequencies_gcov_type (basic_b\n \t\t\t\t gcov_type den)\n {\n   int i;\n-  gcov_type fraction = RDIV (num * 65536, den);\n-\n-  gcc_assert (fraction >= 0);\n \n-  if (num < MAX_SAFE_MULTIPLIER)\n-    for (i = 0; i < nbbs; i++)\n-      {\n-\tbbs[i]->frequency = RDIV (bbs[i]->frequency * num, den);\n-\tif (bbs[i]->count <= MAX_SAFE_MULTIPLIER)\n-\t  bbs[i]->count = bbs[i]->count.apply_scale (num, den);\n-\telse\n-\t  bbs[i]->count = bbs[i]->count.apply_scale (fraction, 65536);\n-      }\n-   else\n-    for (i = 0; i < nbbs; i++)\n-      {\n-\tif (sizeof (gcov_type) > sizeof (int))\n-\t  bbs[i]->frequency = RDIV (bbs[i]->frequency * num, den);\n-\telse\n-\t  bbs[i]->frequency = RDIV (bbs[i]->frequency * fraction, 65536);\n-\tbbs[i]->count = bbs[i]->count.apply_scale (fraction, 65536);\n-      }\n+  for (i = 0; i < nbbs; i++)\n+    bbs[i]->count = bbs[i]->count.apply_scale (num, den);\n }\n \n /* Multiply all frequencies of basic blocks in array BBS of length NBBS\n@@ -994,13 +966,9 @@ scale_bbs_frequencies_profile_count (bas\n \t\t\t\t     profile_count num, profile_count den)\n {\n   int i;\n-\n-  for (i = 0; i < nbbs; i++)\n-    {\n-      bbs[i]->frequency = RDIV (bbs[i]->frequency * num.to_gcov_type (),\n-\t\t\t\tden.to_gcov_type ());\n+  if (num == profile_count::zero () || den.nonzero_p ())\n+    for (i = 0; i < nbbs; i++)\n       bbs[i]->count = bbs[i]->count.apply_scale (num, den);\n-    }\n }\n \n /* Multiply all frequencies of basic blocks in array BBS of length NBBS\n@@ -1013,10 +981,7 @@ scale_bbs_frequencies (basic_block *bbs,\n   int i;\n \n   for (i = 0; i < nbbs; i++)\n-    {\n-      bbs[i]->frequency = p.apply (bbs[i]->frequency);\n-      bbs[i]->count = bbs[i]->count.apply_probability (p);\n-    }\n+    bbs[i]->count = bbs[i]->count.apply_probability (p);\n }\n \n /* Helper types for hash tables.  */\nIndex: cfg.h\n===================================================================\n--- cfg.h\t(revision 254348)\n+++ cfg.h\t(working copy)\n@@ -71,6 +71,9 @@ struct GTY(()) control_flow_graph {\n   /* Maximal number of entities in the single jumptable.  Used to estimate\n      final flowgraph size.  */\n   int max_jumptable_ents;\n+\n+  /* Maximal count of BB in function.  */\n+  profile_count count_max;\n };\n \n \n@@ -103,7 +106,7 @@ extern void debug_bb (basic_block);\n extern basic_block debug_bb_n (int);\n extern void dump_bb_info (FILE *, basic_block, int, dump_flags_t, bool, bool);\n extern void brief_dump_cfg (FILE *, dump_flags_t);\n-extern void update_bb_profile_for_threading (basic_block, int, profile_count, edge);\n+extern void update_bb_profile_for_threading (basic_block, profile_count, edge);\n extern void scale_bbs_frequencies_int (basic_block *, int, int, int);\n extern void scale_bbs_frequencies_gcov_type (basic_block *, int, gcov_type,\n \t\t\t\t\t     gcov_type);\nIndex: cfgbuild.c\n===================================================================\n--- cfgbuild.c\t(revision 254348)\n+++ cfgbuild.c\t(working copy)\n@@ -499,7 +499,6 @@ find_bb_boundaries (basic_block bb)\n \t  remove_edge (fallthru);\n \t  /* BB is unreachable at this point - we need to determine its profile\n \t     once edges are built.  */\n-\t  bb->frequency = 0;\n \t  bb->count = profile_count::uninitialized ();\n \t  flow_transfer_insn = NULL;\n \t  debug_insn = NULL;\n@@ -669,7 +668,6 @@ find_many_sub_basic_blocks (sbitmap bloc\n \t  {\n \t    bool initialized_src = false, uninitialized_src = false;\n \t    bb->count = profile_count::zero ();\n-\t    bb->frequency = 0;\n \t    FOR_EACH_EDGE (e, ei, bb->preds)\n \t      {\n \t\tif (e->count ().initialized_p ())\n@@ -679,8 +677,6 @@ find_many_sub_basic_blocks (sbitmap bloc\n \t\t  }\n \t\telse\n \t\t  uninitialized_src = true;\n-\t\tif (e->probability.initialized_p ())\n-\t\t  bb->frequency += EDGE_FREQUENCY (e);\n \t      }\n \t    /* When some edges are missing with read profile, this is\n \t       most likely because RTL expansion introduced loop.\n@@ -692,7 +688,7 @@ find_many_sub_basic_blocks (sbitmap bloc\n \t       precisely once.  */\n \t    if (!initialized_src\n \t\t|| (uninitialized_src\n-\t\t     && profile_status_for_fn (cfun) != PROFILE_READ))\n+\t\t     && profile_status_for_fn (cfun) < PROFILE_GUESSED))\n \t      bb->count = profile_count::uninitialized ();\n \t  }\n  \t/* If nothing changed, there is no need to create new BBs.  */\nIndex: cfgcleanup.c\n===================================================================\n--- cfgcleanup.c\t(revision 254348)\n+++ cfgcleanup.c\t(working copy)\n@@ -559,8 +559,6 @@ try_forward_edges (int mode, basic_block\n \t{\n \t  /* Save the values now, as the edge may get removed.  */\n \t  profile_count edge_count = e->count ();\n-\t  profile_probability edge_probability = e->probability;\n-\t  int edge_frequency;\n \t  int n = 0;\n \n \t  e->goto_locus = goto_locus;\n@@ -585,8 +583,6 @@ try_forward_edges (int mode, basic_block\n \t  /* We successfully forwarded the edge.  Now update profile\n \t     data: for each edge we traversed in the chain, remove\n \t     the original edge's execution count.  */\n-\t  edge_frequency = edge_probability.apply (b->frequency);\n-\n \t  do\n \t    {\n \t      edge t;\n@@ -596,16 +592,12 @@ try_forward_edges (int mode, basic_block\n \t\t  gcc_assert (n < nthreaded_edges);\n \t\t  t = threaded_edges [n++];\n \t\t  gcc_assert (t->src == first);\n-\t\t  update_bb_profile_for_threading (first, edge_frequency,\n-\t\t\t\t\t\t   edge_count, t);\n+\t\t  update_bb_profile_for_threading (first, edge_count, t);\n \t\t  update_br_prob_note (first);\n \t\t}\n \t      else\n \t\t{\n \t\t  first->count -= edge_count;\n-\t\t  first->frequency -= edge_frequency;\n-\t\t  if (first->frequency < 0)\n-\t\t    first->frequency = 0;\n \t\t  /* It is possible that as the result of\n \t\t     threading we've removed edge as it is\n \t\t     threaded to the fallthru edge.  Avoid\n@@ -2109,7 +2101,7 @@ try_crossjump_to_edge (int mode, edge e1\n   else\n     redirect_edges_to = osrc2;\n \n-  /* Recompute the frequencies and counts of outgoing edges.  */\n+  /* Recompute the counts of destinations of outgoing edges.  */\n   FOR_EACH_EDGE (s, ei, redirect_edges_to->succs)\n     {\n       edge s2;\n@@ -2132,24 +2124,19 @@ try_crossjump_to_edge (int mode, edge e1\n \t that there is no more than one in the chain, so we can't run\n \t into infinite loop.  */\n       if (FORWARDER_BLOCK_P (s->dest))\n-\t{\n-\t  s->dest->frequency += EDGE_FREQUENCY (s);\n-\t}\n+\ts->dest->count += s->count ();\n \n       if (FORWARDER_BLOCK_P (s2->dest))\n-\t{\n-\t  s2->dest->frequency -= EDGE_FREQUENCY (s);\n-\t  if (s2->dest->frequency < 0)\n-\t    s2->dest->frequency = 0;\n-\t}\n+\ts2->dest->count -= s->count ();\n \n-      if (!redirect_edges_to->frequency && !src1->frequency)\n+      /* FIXME: Is this correct? Should be rewritten to count API.  */\n+      if (redirect_edges_to->count.nonzero_p () && src1->count.nonzero_p ())\n \ts->probability = s->probability.combine_with_freq\n-\t\t\t   (redirect_edges_to->frequency,\n-\t\t\t    s2->probability, src1->frequency);\n+\t\t\t   (redirect_edges_to->count.to_frequency (cfun),\n+\t\t\t    s2->probability, src1->count.to_frequency (cfun));\n     }\n \n-  /* Adjust count and frequency for the block.  An earlier jump\n+  /* Adjust count for the block.  An earlier jump\n      threading pass may have left the profile in an inconsistent\n      state (see update_bb_profile_for_threading) so we must be\n      prepared for overflows.  */\n@@ -2157,9 +2144,6 @@ try_crossjump_to_edge (int mode, edge e1\n   do\n     {\n       tmp->count += src1->count;\n-      tmp->frequency += src1->frequency;\n-      if (tmp->frequency > BB_FREQ_MAX)\n-        tmp->frequency = BB_FREQ_MAX;\n       if (tmp == redirect_edges_to)\n         break;\n       tmp = find_fallthru_edge (tmp->succs)->dest;\nIndex: cfgexpand.c\n===================================================================\n--- cfgexpand.c\t(revision 254348)\n+++ cfgexpand.c\t(working copy)\n@@ -2516,7 +2516,6 @@ expand_gimple_cond (basic_block bb, gcon\n   redirect_edge_succ (false_edge, new_bb);\n   false_edge->flags |= EDGE_FALLTHRU;\n   new_bb->count = false_edge->count ();\n-  new_bb->frequency = EDGE_FREQUENCY (false_edge);\n   loop_p loop = find_common_loop (bb->loop_father, dest->loop_father);\n   add_bb_to_loop (new_bb, loop);\n   if (loop->latch == bb\n@@ -3847,11 +3846,7 @@ expand_gimple_tailcall (basic_block bb,\n       if (!(e->flags & (EDGE_ABNORMAL | EDGE_EH)))\n \t{\n \t  if (e->dest != EXIT_BLOCK_PTR_FOR_FN (cfun))\n-\t    {\n-\t      e->dest->frequency -= EDGE_FREQUENCY (e);\n-\t      if (e->dest->frequency < 0)\n-\t\te->dest->frequency = 0;\n-\t    }\n+\t    e->dest->count -= e->count ();\n \t  probability += e->probability;\n \t  remove_edge (e);\n \t}\n@@ -5860,7 +5855,6 @@ construct_init_block (void)\n   init_block = create_basic_block (NEXT_INSN (get_insns ()),\n \t\t\t\t   get_last_insn (),\n \t\t\t\t   ENTRY_BLOCK_PTR_FOR_FN (cfun));\n-  init_block->frequency = ENTRY_BLOCK_PTR_FOR_FN (cfun)->frequency;\n   init_block->count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;\n   add_bb_to_loop (init_block, ENTRY_BLOCK_PTR_FOR_FN (cfun)->loop_father);\n   if (e)\n@@ -5924,7 +5918,7 @@ construct_exit_block (void)\n   while (NEXT_INSN (head) && NOTE_P (NEXT_INSN (head)))\n     head = NEXT_INSN (head);\n   /* But make sure exit_block starts with RETURN_LABEL, otherwise the\n-     bb frequency counting will be confused.  Any instructions before that\n+     bb count counting will be confused.  Any instructions before that\n      label are emitted for the case where PREV_BB falls through into the\n      exit block, so append those instructions to prev_bb in that case.  */\n   if (NEXT_INSN (head) != return_label)\n@@ -5937,7 +5931,6 @@ construct_exit_block (void)\n \t}\n     }\n   exit_block = create_basic_block (NEXT_INSN (head), end, prev_bb);\n-  exit_block->frequency = EXIT_BLOCK_PTR_FOR_FN (cfun)->frequency;\n   exit_block->count = EXIT_BLOCK_PTR_FOR_FN (cfun)->count;\n   add_bb_to_loop (exit_block, EXIT_BLOCK_PTR_FOR_FN (cfun)->loop_father);\n \n@@ -5957,10 +5950,7 @@ construct_exit_block (void)\n     if (e2 != e)\n       {\n \texit_block->count -= e2->count ();\n-\texit_block->frequency -= EDGE_FREQUENCY (e2);\n       }\n-  if (exit_block->frequency < 0)\n-    exit_block->frequency = 0;\n   update_bb_for_insn (exit_block);\n }\n \nIndex: cfghooks.c\n===================================================================\n--- cfghooks.c\t(revision 254348)\n+++ cfghooks.c\t(working copy)\n@@ -146,10 +146,12 @@ verify_flow_info (void)\n \t  error (\"verify_flow_info: Wrong count of block %i\", bb->index);\n \t  err = 1;\n \t}\n-      if (bb->frequency < 0)\n+      /* FIXME: Graphite and SLJL and target code still tends to produce\n+\t edges with no probablity.  */\n+      if (profile_status_for_fn (cfun) >= PROFILE_GUESSED\n+          && !bb->count.initialized_p () && !flag_graphite && 0)\n \t{\n-\t  error (\"verify_flow_info: Wrong frequency of block %i %i\",\n-\t\t bb->index, bb->frequency);\n+\t  error (\"verify_flow_info: Missing count of block %i\", bb->index);\n \t  err = 1;\n \t}\n \n@@ -164,7 +166,7 @@ verify_flow_info (void)\n \t  /* FIXME: Graphite and SLJL and target code still tends to produce\n \t     edges with no probablity.  */\n \t  if (profile_status_for_fn (cfun) >= PROFILE_GUESSED\n-\t      && !e->probability.initialized_p () && 0)\n+\t      && !e->probability.initialized_p () && !flag_graphite && 0)\n \t    {\n \t      error (\"Uninitialized probability of edge %i->%i\", e->src->index,\n \t\t     e->dest->index);\n@@ -315,7 +317,6 @@ dump_bb_for_graph (pretty_printer *pp, b\n   /* TODO: Add pretty printer for counter.  */\n   if (bb->count.initialized_p ())\n     pp_printf (pp, \"COUNT:\" \"%\" PRId64, bb->count.to_gcov_type ());\n-  pp_printf (pp, \" FREQ:%i |\", bb->frequency);\n   pp_write_text_to_stream (pp);\n   if (!(dump_flags & TDF_SLIM))\n     cfg_hooks->dump_bb_for_graph (pp, bb);\n@@ -513,7 +514,6 @@ split_block_1 (basic_block bb, void *i)\n     return NULL;\n \n   new_bb->count = bb->count;\n-  new_bb->frequency = bb->frequency;\n   new_bb->discriminator = bb->discriminator;\n \n   if (dom_info_available_p (CDI_DOMINATORS))\n@@ -626,7 +626,6 @@ split_edge (edge e)\n {\n   basic_block ret;\n   profile_count count = e->count ();\n-  int freq = EDGE_FREQUENCY (e);\n   edge f;\n   bool irr = (e->flags & EDGE_IRREDUCIBLE_LOOP) != 0;\n   struct loop *loop;\n@@ -640,7 +639,6 @@ split_edge (edge e)\n \n   ret = cfg_hooks->split_edge (e);\n   ret->count = count;\n-  ret->frequency = freq;\n   single_succ_edge (ret)->probability = profile_probability::always ();\n \n   if (irr)\n@@ -869,7 +867,6 @@ make_forwarder_block (basic_block bb, bo\n   fallthru = split_block_after_labels (bb);\n   dummy = fallthru->src;\n   dummy->count = profile_count::zero ();\n-  dummy->frequency = 0;\n   bb = fallthru->dest;\n \n   /* Redirect back edges we want to keep.  */\n@@ -879,10 +876,6 @@ make_forwarder_block (basic_block bb, bo\n \n       if (redirect_edge_p (e))\n \t{\n-\t  dummy->frequency += EDGE_FREQUENCY (e);\n-\t  if (dummy->frequency > BB_FREQ_MAX)\n-\t    dummy->frequency = BB_FREQ_MAX;\n-\n \t  dummy->count += e->count ();\n \t  ei_next (&ei);\n \t  continue;\n@@ -1101,19 +1094,10 @@ duplicate_block (basic_block bb, edge e,\n       new_bb->count = new_count;\n       bb->count -= new_count;\n \n-      new_bb->frequency = EDGE_FREQUENCY (e);\n-      bb->frequency -= EDGE_FREQUENCY (e);\n-\n       redirect_edge_and_branch_force (e, new_bb);\n-\n-      if (bb->frequency < 0)\n-\tbb->frequency = 0;\n     }\n   else\n-    {\n-      new_bb->count = bb->count;\n-      new_bb->frequency = bb->frequency;\n-    }\n+    new_bb->count = bb->count;\n \n   set_bb_original (new_bb, bb);\n   set_bb_copy (bb, new_bb);\n@@ -1463,13 +1447,6 @@ account_profile_record (struct profile_r\n       if (bb != ENTRY_BLOCK_PTR_FOR_FN (cfun)\n \t  && profile_status_for_fn (cfun) != PROFILE_ABSENT)\n \t{\n-\t  int sum = 0;\n-\t  FOR_EACH_EDGE (e, ei, bb->preds)\n-\t    sum += EDGE_FREQUENCY (e);\n-\t  if (abs (sum - bb->frequency) > 100\n-\t      || (MAX (sum, bb->frequency) > 10\n-\t\t  && abs ((sum - bb->frequency) * 100 / (MAX (sum, bb->frequency) + 1)) > 10))\n-\t    record->num_mismatched_freq_in[after_pass]++;\n \t  profile_count lsum = profile_count::zero ();\n \t  FOR_EACH_EDGE (e, ei, bb->preds)\n \t    lsum += e->count ();\nIndex: cfgloop.c\n===================================================================\n--- cfgloop.c\t(revision 254348)\n+++ cfgloop.c\t(working copy)\n@@ -607,7 +607,7 @@ find_subloop_latch_edge_by_profile (vec<\n       tcount += e->count();\n     }\n \n-  if (!tcount.initialized_p () || tcount < HEAVY_EDGE_MIN_SAMPLES\n+  if (!tcount.initialized_p () || !(tcount.ipa () > HEAVY_EDGE_MIN_SAMPLES)\n       || (tcount - mcount).apply_scale (HEAVY_EDGE_RATIO, 1) > tcount)\n     return NULL;\n \nIndex: cfgloopanal.c\n===================================================================\n--- cfgloopanal.c\t(revision 254348)\n+++ cfgloopanal.c\t(working copy)\n@@ -213,9 +213,10 @@ average_num_loop_insns (const struct loo\n \tif (NONDEBUG_INSN_P (insn))\n \t  binsns++;\n \n-      ratio = loop->header->frequency == 0\n+      ratio = loop->header->count.to_frequency (cfun) == 0\n \t      ? BB_FREQ_MAX\n-\t      : (bb->frequency * BB_FREQ_MAX) / loop->header->frequency;\n+\t      : (bb->count.to_frequency (cfun) * BB_FREQ_MAX)\n+\t\t / loop->header->count.to_frequency (cfun);\n       ninsns += binsns * ratio;\n     }\n   free (bbs);\n@@ -245,8 +246,8 @@ expected_loop_iterations_unbounded (cons\n   /* If we have no profile at all, use AVG_LOOP_NITER.  */\n   if (profile_status_for_fn (cfun) == PROFILE_ABSENT)\n     expected = PARAM_VALUE (PARAM_AVG_LOOP_NITER);\n-  else if (loop->latch && (loop->latch->count.reliable_p ()\n-\t\t\t   || loop->header->count.reliable_p ()))\n+  else if (loop->latch && (loop->latch->count.initialized_p ()\n+\t\t\t   || loop->header->count.initialized_p ()))\n     {\n       profile_count count_in = profile_count::zero (),\n \t\t    count_latch = profile_count::zero ();\n@@ -258,45 +259,25 @@ expected_loop_iterations_unbounded (cons\n \t  count_in += e->count ();\n \n       if (!count_latch.initialized_p ())\n-\t;\n-      else if (!(count_in > profile_count::zero ()))\n+\texpected = PARAM_VALUE (PARAM_AVG_LOOP_NITER);\n+      else if (!count_in.nonzero_p ())\n \texpected = count_latch.to_gcov_type () * 2;\n       else\n \t{\n \t  expected = (count_latch.to_gcov_type () + count_in.to_gcov_type ()\n \t\t      - 1) / count_in.to_gcov_type ();\n-\t  if (read_profile_p)\n+\t  if (read_profile_p\n+\t      && count_latch.reliable_p () && count_in.reliable_p ())\n \t    *read_profile_p = true;\n \t}\n     }\n-  if (expected == -1)\n-    {\n-      int freq_in, freq_latch;\n-\n-      freq_in = 0;\n-      freq_latch = 0;\n-\n-      FOR_EACH_EDGE (e, ei, loop->header->preds)\n-\tif (flow_bb_inside_loop_p (loop, e->src))\n-\t  freq_latch += EDGE_FREQUENCY (e);\n-\telse\n-\t  freq_in += EDGE_FREQUENCY (e);\n-\n-      if (freq_in == 0)\n-\t{\n-\t  /* If we have no profile at all, use AVG_LOOP_NITER iterations.  */\n-\t  if (!freq_latch)\n-\t    expected = PARAM_VALUE (PARAM_AVG_LOOP_NITER);\n-\t  else\n-\t    expected = freq_latch * 2;\n-\t}\n-      else\n-        expected = (freq_latch + freq_in - 1) / freq_in;\n-    }\n+  else\n+    expected = PARAM_VALUE (PARAM_AVG_LOOP_NITER);\n \n   HOST_WIDE_INT max = get_max_loop_iterations_int (loop);\n   if (max != -1 && max < expected)\n     return max;\n+ \n   return expected;\n }\n \nIndex: cfgloopmanip.c\n===================================================================\n--- cfgloopmanip.c\t(revision 254348)\n+++ cfgloopmanip.c\t(working copy)\n@@ -536,7 +536,6 @@ scale_loop_profile (struct loop *loop, p\n       if (e)\n \t{\n \t  edge other_e;\n-\t  int freq_delta;\n \t  profile_count count_delta;\n \n           FOR_EACH_EDGE (other_e, ei, e->src->succs)\n@@ -545,23 +544,18 @@ scale_loop_profile (struct loop *loop, p\n \t      break;\n \n \t  /* Probability of exit must be 1/iterations.  */\n-\t  freq_delta = EDGE_FREQUENCY (e);\n \t  count_delta = e->count ();\n \t  e->probability = profile_probability::always ()\n \t\t\t\t.apply_scale (1, iteration_bound);\n \t  other_e->probability = e->probability.invert ();\n-\t  freq_delta -= EDGE_FREQUENCY (e);\n \t  count_delta -= e->count ();\n \n-\t  /* If latch exists, change its frequency and count, since we changed\n+\t  /* If latch exists, change its count, since we changed\n \t     probability of exit.  Theoretically we should update everything from\n \t     source of exit edge to latch, but for vectorizer this is enough.  */\n \t  if (loop->latch\n \t      && loop->latch != e->src)\n \t    {\n-\t      loop->latch->frequency += freq_delta;\n-\t      if (loop->latch->frequency < 0)\n-\t\tloop->latch->frequency = 0;\n \t      loop->latch->count += count_delta;\n \t    }\n \t}\n@@ -571,7 +565,6 @@ scale_loop_profile (struct loop *loop, p\n \t we look at the actual profile, if it is available.  */\n       p = p.apply_scale (iteration_bound, iterations);\n \n-      bool determined = false;\n       if (loop->header->count.initialized_p ())\n \t{\n \t  profile_count count_in = profile_count::zero ();\n@@ -584,21 +577,8 @@ scale_loop_profile (struct loop *loop, p\n \t    {\n \t      p = count_in.probability_in (loop->header->count.apply_scale\n \t\t\t\t\t\t (iteration_bound, 1));\n-\t      determined = true;\n \t    }\n \t}\n-      if (!determined && loop->header->frequency)\n-\t{\n-\t  int freq_in = 0;\n-\n-\t  FOR_EACH_EDGE (e, ei, loop->header->preds)\n-\t    if (e->src != loop->latch)\n-\t      freq_in += EDGE_FREQUENCY (e);\n-\n-\t  if (freq_in != 0)\n-\t    p = profile_probability::probability_in_gcov_type\n-\t\t\t (freq_in * iteration_bound, loop->header->frequency);\n-\t}\n       if (!(p > profile_probability::never ()))\n \tp = profile_probability::very_unlikely ();\n     }\n@@ -800,7 +780,7 @@ create_empty_loop_on_edge (edge entry_ed\n   loop->latch = loop_latch;\n   add_loop (loop, outer);\n \n-  /* TODO: Fix frequencies and counts.  */\n+  /* TODO: Fix counts.  */\n   scale_loop_frequencies (loop, profile_probability::even ());\n \n   /* Update dominators.  */\n@@ -866,13 +846,11 @@ loopify (edge latch_edge, edge header_ed\n   basic_block pred_bb = header_edge->src;\n   struct loop *loop = alloc_loop ();\n   struct loop *outer = loop_outer (succ_bb->loop_father);\n-  int freq;\n   profile_count cnt;\n \n   loop->header = header_edge->dest;\n   loop->latch = latch_edge->src;\n \n-  freq = EDGE_FREQUENCY (header_edge);\n   cnt = header_edge->count ();\n \n   /* Redirect edges.  */\n@@ -901,10 +879,9 @@ loopify (edge latch_edge, edge header_ed\n     remove_bb_from_loops (switch_bb);\n   add_bb_to_loop (switch_bb, outer);\n \n-  /* Fix frequencies.  */\n+  /* Fix counts.  */\n   if (redirect_all_edges)\n     {\n-      switch_bb->frequency = freq;\n       switch_bb->count = cnt;\n     }\n   scale_loop_frequencies (loop, false_scale);\n@@ -1167,7 +1144,7 @@ duplicate_loop_to_header_edge (struct lo\n     {\n       /* Calculate coefficients by that we have to scale frequencies\n \t of duplicated loop bodies.  */\n-      freq_in = header->frequency;\n+      freq_in = header->count.to_frequency (cfun);\n       freq_le = EDGE_FREQUENCY (latch_edge);\n       if (freq_in == 0)\n \tfreq_in = 1;\nIndex: cfgrtl.c\n===================================================================\n--- cfgrtl.c\t(revision 254348)\n+++ cfgrtl.c\t(working copy)\n@@ -1533,6 +1533,7 @@ force_nonfallthru_and_redirect (edge e,\n \n \t  basic_block bb = create_basic_block (BB_HEAD (e->dest), NULL,\n \t\t\t\t\t       ENTRY_BLOCK_PTR_FOR_FN (cfun));\n+\t  bb->count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;\n \n \t  /* Change the existing edge's source to be the new block, and add\n \t     a new edge from the entry block to the new block.  */\n@@ -1628,7 +1629,6 @@ force_nonfallthru_and_redirect (edge e,\n \n       jump_block = create_basic_block (new_head, NULL, e->src);\n       jump_block->count = count;\n-      jump_block->frequency = EDGE_FREQUENCY (e);\n \n       /* Make sure new block ends up in correct hot/cold section.  */\n \n@@ -1652,7 +1652,6 @@ force_nonfallthru_and_redirect (edge e,\n \t{\n \t  new_edge->probability = new_edge->probability.apply_scale (1, 2);\n \t  jump_block->count = jump_block->count.apply_scale (1, 2);\n-\t  jump_block->frequency /= 2;\n \t  edge new_edge2 = make_edge (new_edge->src, target,\n \t\t\t\t      e->flags & ~EDGE_FALLTHRU);\n \t  new_edge2->probability = probability - new_edge->probability;\n@@ -2245,9 +2244,23 @@ void\n update_br_prob_note (basic_block bb)\n {\n   rtx note;\n-  if (!JUMP_P (BB_END (bb)) || !BRANCH_EDGE (bb)->probability.initialized_p ())\n-    return;\n   note = find_reg_note (BB_END (bb), REG_BR_PROB, NULL_RTX);\n+  if (!JUMP_P (BB_END (bb)) || !BRANCH_EDGE (bb)->probability.initialized_p ())\n+    {\n+      if (note)\n+\t{\n+\t  rtx *note_link, this_rtx;\n+\n+\t  note_link = &REG_NOTES (BB_END (bb));\n+\t  for (this_rtx = *note_link; this_rtx; this_rtx = XEXP (this_rtx, 1))\n+\t    if (this_rtx == note)\n+\t      {\n+\t\t*note_link = XEXP (this_rtx, 1);\n+\t\tbreak;\n+\t      }\n+\t}\n+      return;\n+    }\n   if (!note\n       || XINT (note, 0) == BRANCH_EDGE (bb)->probability.to_reg_br_prob_note ())\n     return;\n@@ -3623,7 +3636,6 @@ relink_block_chain (bool stay_in_cfglayo\n \t    fprintf (dump_file, \"compensation \");\n \t  else\n \t    fprintf (dump_file, \"bb %i \", bb->index);\n-\t  fprintf (dump_file, \" [%i]\\n\", bb->frequency);\n \t}\n     }\n \n@@ -5034,7 +5046,7 @@ rtl_account_profile_record (basic_block\n \t    += insn_cost (insn, true) * bb->count.to_gcov_type ();\n \telse if (profile_status_for_fn (cfun) == PROFILE_GUESSED)\n \t  record->time[after_pass]\n-\t    += insn_cost (insn, true) * bb->frequency;\n+\t    += insn_cost (insn, true) * bb->count.to_frequency (cfun);\n       }\n }\n \nIndex: cgraph.c\n===================================================================\n--- cgraph.c\t(revision 254348)\n+++ cgraph.c\t(working copy)\n@@ -862,7 +862,7 @@ symbol_table::create_edge (cgraph_node *\n   edge->next_callee = NULL;\n   edge->lto_stmt_uid = 0;\n \n-  edge->count = count;\n+  edge->count = count.ipa ();\n   edge->frequency = freq;\n   gcc_checking_assert (freq >= 0);\n   gcc_checking_assert (freq <= CGRAPH_FREQ_MAX);\n@@ -1308,7 +1308,7 @@ cgraph_edge::redirect_call_stmt_to_calle\n \t  /* We are producing the final function body and will throw away the\n \t     callgraph edges really soon.  Reset the counts/frequencies to\n \t     keep verifier happy in the case of roundoff errors.  */\n-\t  e->count = gimple_bb (e->call_stmt)->count;\n+\t  e->count = gimple_bb (e->call_stmt)->count.ipa ();\n \t  e->frequency = compute_call_stmt_bb_frequency\n \t\t\t  (e->caller->decl, gimple_bb (e->call_stmt));\n \t}\n@@ -1338,7 +1338,7 @@ cgraph_edge::redirect_call_stmt_to_calle\n \t    prob = profile_probability::even ();\n \t  new_stmt = gimple_ic (e->call_stmt,\n \t\t\t\tdyn_cast<cgraph_node *> (ref->referred),\n-\t\t\t\tprob, e->count, e->count + e2->count);\n+\t\t\t\tprob);\n \t  e->speculative = false;\n \t  e->caller->set_call_stmt_including_clones (e->call_stmt, new_stmt,\n \t\t\t\t\t\t     false);\n@@ -1644,7 +1644,7 @@ cgraph_update_edges_for_call_stmt_node (\n \t  /* Otherwise remove edge and create new one; we can't simply redirect\n \t     since function has changed, so inline plan and other information\n \t     attached to edge is invalid.  */\n-\t  count = e->count;\n+\t  count = e->count.ipa ();\n \t  frequency = e->frequency;\n  \t  if (e->indirect_unknown_callee || e->inline_failed)\n \t    e->remove ();\n@@ -1655,7 +1655,7 @@ cgraph_update_edges_for_call_stmt_node (\n \t{\n \t  /* We are seeing new direct call; compute profile info based on BB.  */\n \t  basic_block bb = gimple_bb (new_stmt);\n-\t  count = bb->count;\n+\t  count = bb->count.ipa ();\n \t  frequency = compute_call_stmt_bb_frequency (current_function_decl,\n \t\t\t\t\t\t      bb);\n \t}\n@@ -3082,9 +3082,14 @@ bool\n cgraph_edge::verify_count_and_frequency ()\n {\n   bool error_found = false;\n-  if (count < 0)\n+  if (!count.verify ())\n     {\n-      error (\"caller edge count is negative\");\n+      error (\"caller edge count invalid\");\n+      error_found = true;\n+    }\n+  if (!count.ipa_p ())\n+    {\n+      error (\"caller edge count is local\");\n       error_found = true;\n     }\n   if (frequency < 0)\n@@ -3183,9 +3188,14 @@ cgraph_node::verify_node (void)\n \t       identifier_to_locale (e->callee->name ()));\n \terror_found = true;\n       }\n-  if (count < 0)\n+  if (!count.verify ())\n+    {\n+      error (\"cgraph count invalid\");\n+      error_found = true;\n+    }\n+  if (!count.ipa_p ())\n     {\n-      error (\"execution count is negative\");\n+      error (\"cgraph count is local\");\n       error_found = true;\n     }\n   if (global.inlined_to && same_comdat_group)\n@@ -3269,7 +3279,9 @@ cgraph_node::verify_node (void)\n     {\n       if (e->verify_count_and_frequency ())\n \terror_found = true;\n+      /* FIXME: re-enable once cgraph is converted to counts.  */\n       if (gimple_has_body_p (e->caller->decl)\n+\t  && 0\n \t  && !e->caller->global.inlined_to\n \t  && !e->speculative\n \t  /* Optimized out calls are redirected to __builtin_unreachable.  */\n@@ -3292,9 +3304,11 @@ cgraph_node::verify_node (void)\n     {\n       if (e->verify_count_and_frequency ())\n \terror_found = true;\n+      /* FIXME: re-enable once cgraph is converted to counts.  */\n       if (gimple_has_body_p (e->caller->decl)\n \t  && !e->caller->global.inlined_to\n \t  && !e->speculative\n+\t  && 0\n \t  && (e->frequency\n \t      != compute_call_stmt_bb_frequency (e->caller->decl,\n \t\t\t\t\t\t gimple_bb (e->call_stmt))))\nIndex: cgraphbuild.c\n===================================================================\n--- cgraphbuild.c\t(revision 254348)\n+++ cgraphbuild.c\t(working copy)\n@@ -190,21 +190,8 @@ record_eh_tables (cgraph_node *node, fun\n int\n compute_call_stmt_bb_frequency (tree decl, basic_block bb)\n {\n-  int entry_freq = ENTRY_BLOCK_PTR_FOR_FN\n-  \t\t     (DECL_STRUCT_FUNCTION (decl))->frequency;\n-  int freq = bb->frequency;\n-\n-  if (profile_status_for_fn (DECL_STRUCT_FUNCTION (decl)) == PROFILE_ABSENT)\n-    return CGRAPH_FREQ_BASE;\n-\n-  if (!entry_freq)\n-    entry_freq = 1, freq++;\n-\n-  freq = freq * CGRAPH_FREQ_BASE / entry_freq;\n-  if (freq > CGRAPH_FREQ_MAX)\n-    freq = CGRAPH_FREQ_MAX;\n-\n-  return freq;\n+  return bb->count.to_cgraph_frequency\n+      (ENTRY_BLOCK_PTR_FOR_FN (DECL_STRUCT_FUNCTION (decl))->count);\n }\n \n /* Mark address taken in STMT.  */\n@@ -415,7 +402,7 @@ cgraph_edge::rebuild_edges (void)\n   node->remove_callees ();\n   node->remove_all_references ();\n \n-  node->count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;\n+  node->count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.ipa ();\n \n   FOR_EACH_BB_FN (bb, cfun)\n     {\nIndex: cgraphunit.c\n===================================================================\n--- cgraphunit.c\t(revision 254348)\n+++ cgraphunit.c\t(working copy)\n@@ -1601,12 +1601,9 @@ init_lowered_empty_function (tree decl,\n \n   /* Create BB for body of the function and connect it properly.  */\n   ENTRY_BLOCK_PTR_FOR_FN (cfun)->count = count;\n-  ENTRY_BLOCK_PTR_FOR_FN (cfun)->frequency = BB_FREQ_MAX;\n   EXIT_BLOCK_PTR_FOR_FN (cfun)->count = count;\n-  EXIT_BLOCK_PTR_FOR_FN (cfun)->frequency = BB_FREQ_MAX;\n   bb = create_basic_block (NULL, ENTRY_BLOCK_PTR_FOR_FN (cfun));\n   bb->count = count;\n-  bb->frequency = BB_FREQ_MAX;\n   e = make_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun), bb, EDGE_FALLTHRU);\n   e->probability = profile_probability::always ();\n   e = make_edge (bb, EXIT_BLOCK_PTR_FOR_FN (cfun), 0);\n@@ -1852,8 +1849,12 @@ cgraph_node::expand_thunk (bool output_a\n       else\n \tresdecl = DECL_RESULT (thunk_fndecl);\n \n+      profile_count cfg_count = count;\n+      if (!cfg_count.initialized_p ())\n+\tcfg_count = profile_count::from_gcov_type (BB_FREQ_MAX).guessed_local ();\n+\n       bb = then_bb = else_bb = return_bb\n-\t= init_lowered_empty_function (thunk_fndecl, true, count);\n+\t= init_lowered_empty_function (thunk_fndecl, true, cfg_count);\n \n       bsi = gsi_start_bb (bb);\n \n@@ -1966,14 +1967,11 @@ cgraph_node::expand_thunk (bool output_a\n \t\t     adjustment, because that's why we're emitting a\n \t\t     thunk.  */\n \t\t  then_bb = create_basic_block (NULL, bb);\n-\t\t  then_bb->count = count - count.apply_scale (1, 16);\n-\t\t  then_bb->frequency = BB_FREQ_MAX - BB_FREQ_MAX / 16;\n+\t\t  then_bb->count = cfg_count - cfg_count.apply_scale (1, 16);\n \t\t  return_bb = create_basic_block (NULL, then_bb);\n-\t\t  return_bb->count = count;\n-\t\t  return_bb->frequency = BB_FREQ_MAX;\n+\t\t  return_bb->count = cfg_count;\n \t\t  else_bb = create_basic_block (NULL, else_bb);\n-\t\t  then_bb->count = count.apply_scale (1, 16);\n-\t\t  then_bb->frequency = BB_FREQ_MAX / 16;\n+\t\t  else_bb->count = cfg_count.apply_scale (1, 16);\n \t\t  add_bb_to_loop (then_bb, bb->loop_father);\n \t\t  add_bb_to_loop (return_bb, bb->loop_father);\n \t\t  add_bb_to_loop (else_bb, bb->loop_father);\n@@ -2028,8 +2026,10 @@ cgraph_node::expand_thunk (bool output_a\n \t}\n \n       cfun->gimple_df->in_ssa_p = true;\n+      counts_to_freqs ();\n       profile_status_for_fn (cfun)\n-        = count.initialized_p () ? PROFILE_READ : PROFILE_GUESSED;\n+        = cfg_count.initialized_p () && cfg_count.ipa_p ()\n+\t  ? PROFILE_READ : PROFILE_GUESSED;\n       /* FIXME: C++ FE should stop setting TREE_ASM_WRITTEN on thunks.  */\n       TREE_ASM_WRITTEN (thunk_fndecl) = false;\n       delete_unreachable_blocks ();\nIndex: except.c\n===================================================================\n--- except.c\t(revision 254348)\n+++ except.c\t(working copy)\n@@ -1003,7 +1003,6 @@ dw2_build_landing_pads (void)\n \n       bb = emit_to_new_bb_before (seq, label_rtx (lp->post_landing_pad));\n       bb->count = bb->next_bb->count;\n-      bb->frequency = bb->next_bb->frequency;\n       make_single_succ_edge (bb, bb->next_bb, e_flags);\n       if (current_loops)\n \t{\nIndex: final.c\n===================================================================\n--- final.c\t(revision 254348)\n+++ final.c\t(working copy)\n@@ -694,8 +694,8 @@ compute_alignments (void)\n     }\n   loop_optimizer_init (AVOID_CFG_MODIFICATIONS);\n   FOR_EACH_BB_FN (bb, cfun)\n-    if (bb->frequency > freq_max)\n-      freq_max = bb->frequency;\n+    if (bb->count.to_frequency (cfun) > freq_max)\n+      freq_max = bb->count.to_frequency (cfun);\n   freq_threshold = freq_max / PARAM_VALUE (PARAM_ALIGN_THRESHOLD);\n \n   if (dump_file)\n@@ -713,7 +713,8 @@ compute_alignments (void)\n \t  if (dump_file)\n \t    fprintf (dump_file,\n \t\t     \"BB %4i freq %4i loop %2i loop_depth %2i skipped.\\n\",\n-\t\t     bb->index, bb->frequency, bb->loop_father->num,\n+\t\t     bb->index, bb->count.to_frequency (cfun),\n+\t\t     bb->loop_father->num,\n \t\t     bb_loop_depth (bb));\n \t  continue;\n \t}\n@@ -731,7 +732,7 @@ compute_alignments (void)\n \t{\n \t  fprintf (dump_file, \"BB %4i freq %4i loop %2i loop_depth\"\n \t\t   \" %2i fall %4i branch %4i\",\n-\t\t   bb->index, bb->frequency, bb->loop_father->num,\n+\t\t   bb->index, bb->count.to_frequency (cfun), bb->loop_father->num,\n \t\t   bb_loop_depth (bb),\n \t\t   fallthru_frequency, branch_frequency);\n \t  if (!bb->loop_father->inner && bb->loop_father->num)\n@@ -753,9 +754,10 @@ compute_alignments (void)\n \n       if (!has_fallthru\n \t  && (branch_frequency > freq_threshold\n-\t      || (bb->frequency > bb->prev_bb->frequency * 10\n-\t\t  && (bb->prev_bb->frequency\n-\t\t      <= ENTRY_BLOCK_PTR_FOR_FN (cfun)->frequency / 2))))\n+\t      || (bb->count.to_frequency (cfun) \n+\t\t\t> bb->prev_bb->count.to_frequency (cfun) * 10\n+\t\t  && (bb->prev_bb->count.to_frequency (cfun)\n+\t\t      <= ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.to_frequency (cfun) / 2))))\n \t{\n \t  log = JUMP_ALIGN (label);\n \t  if (dump_file)\n@@ -1942,8 +1944,6 @@ dump_basic_block_info (FILE *file, rtx_i\n       edge_iterator ei;\n \n       fprintf (file, \"%s BLOCK %d\", ASM_COMMENT_START, bb->index);\n-      if (bb->frequency)\n-        fprintf (file, \" freq:%d\", bb->frequency);\n       if (bb->count.initialized_p ())\n \t{\n           fprintf (file, \", count:\");\nIndex: gimple-pretty-print.c\n===================================================================\n--- gimple-pretty-print.c\t(revision 254348)\n+++ gimple-pretty-print.c\t(working copy)\n@@ -82,21 +82,17 @@ debug_gimple_stmt (gimple *gs)\n    by xstrdup_for_dump.  */\n \n static const char *\n-dump_profile (int frequency, profile_count &count)\n+dump_profile (profile_count &count)\n {\n-  float minimum = 0.01f;\n-\n-  gcc_assert (0 <= frequency && frequency <= REG_BR_PROB_BASE);\n-  float fvalue = frequency * 100.0f / REG_BR_PROB_BASE;\n-  if (fvalue < minimum && frequency > 0)\n-    return \"[0.01%]\";\n-\n   char *buf;\n-  if (count.initialized_p ())\n-    buf = xasprintf (\"[%.2f%%] [count: %\" PRId64 \"]\", fvalue,\n+  if (!count.initialized_p ())\n+    return NULL;\n+  if (count.ipa_p ())\n+    buf = xasprintf (\"[count: %\" PRId64 \"]\",\n+\t\t     count.to_gcov_type ());\n+  else if (count.initialized_p ())\n+    buf = xasprintf (\"[local count: %\" PRId64 \"]\",\n \t\t     count.to_gcov_type ());\n-  else\n-    buf = xasprintf (\"[%.2f%%] [count: INV]\", fvalue);\n \n   const char *ret = xstrdup_for_dump (buf);\n   free (buf);\n@@ -2695,8 +2691,7 @@ dump_gimple_bb_header (FILE *outf, basic\n \tfprintf (outf, \"%*sbb_%d:\\n\", indent, \"\", bb->index);\n       else\n \tfprintf (outf, \"%*s<bb %d> %s:\\n\",\n-\t\t indent, \"\", bb->index, dump_profile (bb->frequency,\n-\t\t\t\t\t\t      bb->count));\n+\t\t indent, \"\", bb->index, dump_profile (bb->count));\n     }\n }\n \nIndex: gimple-ssa-isolate-paths.c\n===================================================================\n--- gimple-ssa-isolate-paths.c\t(revision 254348)\n+++ gimple-ssa-isolate-paths.c\t(working copy)\n@@ -154,7 +154,6 @@ isolate_path (basic_block bb, basic_bloc\n   if (!duplicate)\n     {\n       duplicate = duplicate_block (bb, NULL, NULL);\n-      bb->frequency = 0;\n       bb->count = profile_count::zero ();\n       if (!ret_zero)\n \tfor (ei = ei_start (duplicate->succs); (e2 = ei_safe_edge (ei)); )\n@@ -168,7 +167,7 @@ isolate_path (basic_block bb, basic_bloc\n       flush_pending_stmts (e2);\n \n       /* Update profile only when redirection is really processed.  */\n-      bb->frequency += EDGE_FREQUENCY (e);\n+      bb->count += e->count ();\n     }\n \n   /* There may be more than one statement in DUPLICATE which exhibits\nIndex: gimple-streamer-in.c\n===================================================================\n--- gimple-streamer-in.c\t(revision 254348)\n+++ gimple-streamer-in.c\t(working copy)\n@@ -266,7 +266,6 @@ input_bb (struct lto_input_block *ib, en\n \n   bb->count = profile_count::stream_in (ib).apply_scale\n \t\t (count_materialization_scale, REG_BR_PROB_BASE);\n-  bb->frequency = streamer_read_hwi (ib);\n   bb->flags = streamer_read_hwi (ib);\n \n   /* LTO_bb1 has statements.  LTO_bb0 does not.  */\nIndex: gimple-streamer-out.c\n===================================================================\n--- gimple-streamer-out.c\t(revision 254348)\n+++ gimple-streamer-out.c\t(working copy)\n@@ -210,7 +210,6 @@ output_bb (struct output_block *ob, basi\n \n   streamer_write_uhwi (ob, bb->index);\n   bb->count.stream_out (ob);\n-  streamer_write_hwi (ob, bb->frequency);\n   streamer_write_hwi (ob, bb->flags);\n \n   if (!gsi_end_p (bsi) || phi_nodes (bb))\nIndex: haifa-sched.c\n===================================================================\n--- haifa-sched.c\t(revision 254348)\n+++ haifa-sched.c\t(working copy)\n@@ -3917,8 +3917,8 @@ sched_pressure_start_bb (basic_block bb)\n       - call_saved_regs_num[cl]).  */\n   {\n     int i;\n-    int entry_freq = ENTRY_BLOCK_PTR_FOR_FN (cfun)->frequency;\n-    int bb_freq = bb->frequency;\n+    int entry_freq = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.to_frequency (cfun);\n+    int bb_freq = bb->count.to_frequency (cfun);\n \n     if (bb_freq == 0)\n       {\n@@ -8141,8 +8141,6 @@ init_before_recovery (basic_block *befor\n \n       single->count = last->count;\n       empty->count = last->count;\n-      single->frequency = last->frequency;\n-      empty->frequency = last->frequency;\n       BB_COPY_PARTITION (single, last);\n       BB_COPY_PARTITION (empty, last);\n \n@@ -8236,7 +8234,6 @@ sched_create_recovery_edges (basic_block\n      in sel-sched.c `check_ds' in create_speculation_check.  */\n   e->probability = profile_probability::very_unlikely ();\n   rec->count = e->count ();\n-  rec->frequency = EDGE_FREQUENCY (e);\n   e2->probability = e->probability.invert ();\n \n   rtx_code_label *label = block_label (second_bb);\nIndex: hsa-gen.c\n===================================================================\n--- hsa-gen.c\t(revision 254348)\n+++ hsa-gen.c\t(working copy)\n@@ -6374,7 +6374,7 @@ convert_switch_statements (void)\n \n \t\tedge next_edge = make_edge (cur_bb, next_bb, EDGE_FALSE_VALUE);\n \t\tnext_edge->probability = new_edge->probability.invert ();\n-\t\tnext_bb->frequency = EDGE_FREQUENCY (next_edge);\n+\t\tnext_bb->count = next_edge->count ();\n \t\tcur_bb = next_bb;\n \t      }\n \t    else /* Link last IF statement and default label\nIndex: ipa-cp.c\n===================================================================\n--- ipa-cp.c\t(revision 254348)\n+++ ipa-cp.c\t(working copy)\n@@ -3257,6 +3257,8 @@ ipcp_propagate_stage (struct ipa_topo_in\n   if (dump_file)\n     fprintf (dump_file, \"\\n Propagating constants:\\n\\n\");\n \n+  max_count = profile_count::uninitialized ();\n+\n   FOR_EACH_DEFINED_FUNCTION (node)\n   {\n     struct ipa_node_params *info = IPA_NODE_REF (node);\n@@ -3270,8 +3272,7 @@ ipcp_propagate_stage (struct ipa_topo_in\n       }\n     if (node->definition && !node->alias)\n       overall_size += ipa_fn_summaries->get (node)->self_size;\n-    if (node->count > max_count)\n-      max_count = node->count;\n+    max_count = max_count.max (node->count);\n   }\n \n   max_new_size = overall_size;\n@@ -5125,7 +5126,7 @@ make_pass_ipa_cp (gcc::context *ctxt)\n void\n ipa_cp_c_finalize (void)\n {\n-  max_count = profile_count::zero ();\n+  max_count = profile_count::uninitialized ();\n   overall_size = 0;\n   max_new_size = 0;\n }\nIndex: ipa-fnsummary.c\n===================================================================\n--- ipa-fnsummary.c\t(revision 254348)\n+++ ipa-fnsummary.c\t(working copy)\n@@ -1608,7 +1608,7 @@ static basic_block\n get_minimal_bb (basic_block init_bb, basic_block use_bb)\n {\n   struct loop *l = find_common_loop (init_bb->loop_father, use_bb->loop_father);\n-  if (l && l->header->frequency < init_bb->frequency)\n+  if (l && l->header->count < init_bb->count)\n     return l->header;\n   return init_bb;\n }\n@@ -1664,20 +1664,21 @@ param_change_prob (gimple *stmt, int i)\n     {\n       int init_freq;\n \n-      if (!bb->frequency)\n+      if (!bb->count.to_frequency (cfun))\n \treturn REG_BR_PROB_BASE;\n \n       if (SSA_NAME_IS_DEFAULT_DEF (base))\n-\tinit_freq = ENTRY_BLOCK_PTR_FOR_FN (cfun)->frequency;\n+\tinit_freq = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.to_frequency (cfun);\n       else\n \tinit_freq = get_minimal_bb\n \t\t      (gimple_bb (SSA_NAME_DEF_STMT (base)),\n-\t\t       gimple_bb (stmt))->frequency;\n+\t\t       gimple_bb (stmt))->count.to_frequency (cfun);\n \n       if (!init_freq)\n \tinit_freq = 1;\n-      if (init_freq < bb->frequency)\n-\treturn MAX (GCOV_COMPUTE_SCALE (init_freq, bb->frequency), 1);\n+      if (init_freq < bb->count.to_frequency (cfun))\n+\treturn MAX (GCOV_COMPUTE_SCALE (init_freq,\n+\t\t\t\t\tbb->count.to_frequency (cfun)), 1);\n       else\n \treturn REG_BR_PROB_BASE;\n     }\n@@ -1692,7 +1693,7 @@ param_change_prob (gimple *stmt, int i)\n \n       if (init != error_mark_node)\n \treturn 0;\n-      if (!bb->frequency)\n+      if (!bb->count.to_frequency (cfun))\n \treturn REG_BR_PROB_BASE;\n       ao_ref_init (&refd, op);\n       info.stmt = stmt;\n@@ -1708,17 +1709,17 @@ param_change_prob (gimple *stmt, int i)\n       /* Assume that every memory is initialized at entry.\n          TODO: Can we easilly determine if value is always defined\n          and thus we may skip entry block?  */\n-      if (ENTRY_BLOCK_PTR_FOR_FN (cfun)->frequency)\n-\tmax = ENTRY_BLOCK_PTR_FOR_FN (cfun)->frequency;\n+      if (ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.to_frequency (cfun))\n+\tmax = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.to_frequency (cfun);\n       else\n \tmax = 1;\n \n       EXECUTE_IF_SET_IN_BITMAP (info.bb_set, 0, index, bi)\n-\tmax = MIN (max, BASIC_BLOCK_FOR_FN (cfun, index)->frequency);\n+\tmax = MIN (max, BASIC_BLOCK_FOR_FN (cfun, index)->count.to_frequency (cfun));\n \n       BITMAP_FREE (info.bb_set);\n-      if (max < bb->frequency)\n-\treturn MAX (GCOV_COMPUTE_SCALE (max, bb->frequency), 1);\n+      if (max < bb->count.to_frequency (cfun))\n+\treturn MAX (GCOV_COMPUTE_SCALE (max, bb->count.to_frequency (cfun)), 1);\n       else\n \treturn REG_BR_PROB_BASE;\n     }\nIndex: ipa-inline.c\n===================================================================\n--- ipa-inline.c\t(revision 254348)\n+++ ipa-inline.c\t(working copy)\n@@ -640,8 +640,8 @@ compute_uninlined_call_time (struct cgra\n \t\t\t ? edge->caller->global.inlined_to\n \t\t\t : edge->caller);\n \n-  if (edge->count > profile_count::zero ()\n-      && caller->count > profile_count::zero ())\n+  if (edge->count.nonzero_p ()\n+      && caller->count.nonzero_p ())\n     uninlined_call_time *= (sreal)edge->count.to_gcov_type ()\n \t\t\t   / caller->count.to_gcov_type ();\n   if (edge->frequency)\n@@ -665,8 +665,8 @@ compute_inlined_call_time (struct cgraph\n \t\t\t : edge->caller);\n   sreal caller_time = ipa_fn_summaries->get (caller)->time;\n \n-  if (edge->count > profile_count::zero ()\n-      && caller->count > profile_count::zero ())\n+  if (edge->count.nonzero_p ()\n+      && caller->count.nonzero_p ())\n     time *= (sreal)edge->count.to_gcov_type () / caller->count.to_gcov_type ();\n   if (edge->frequency)\n     time *= cgraph_freq_base_rec * edge->frequency;\n@@ -733,7 +733,7 @@ want_inline_small_function_p (struct cgr\n       want_inline = false;\n     }\n   else if ((DECL_DECLARED_INLINE_P (callee->decl)\n-\t    || e->count > profile_count::zero ())\n+\t    || e->count.nonzero_p ())\n \t   && ipa_fn_summaries->get (callee)->min_size\n \t\t- ipa_call_summaries->get (e)->call_stmt_size\n \t      > 16 * MAX_INLINE_INSNS_SINGLE)\n@@ -843,7 +843,7 @@ want_inline_self_recursive_call_p (struc\n       reason = \"recursive call is cold\";\n       want_inline = false;\n     }\n-  else if (outer_node->count == profile_count::zero ())\n+  else if (!outer_node->count.nonzero_p ())\n     {\n       reason = \"not executed in profile\";\n       want_inline = false;\n@@ -881,7 +881,7 @@ want_inline_self_recursive_call_p (struc\n       int i;\n       for (i = 1; i < depth; i++)\n \tmax_prob = max_prob * max_prob / CGRAPH_FREQ_BASE;\n-      if (max_count > profile_count::zero () && edge->count > profile_count::zero ()\n+      if (max_count.nonzero_p () && edge->count.nonzero_p () \n \t  && (edge->count.to_gcov_type () * CGRAPH_FREQ_BASE\n \t      / outer_node->count.to_gcov_type ()\n \t      >= max_prob))\n@@ -889,7 +889,7 @@ want_inline_self_recursive_call_p (struc\n \t  reason = \"profile of recursive call is too large\";\n \t  want_inline = false;\n \t}\n-      if (max_count == profile_count::zero ()\n+      if (!max_count.nonzero_p ()\n \t  && (edge->frequency * CGRAPH_FREQ_BASE / caller_freq\n \t      >= max_prob))\n \t{\n@@ -915,7 +915,7 @@ want_inline_self_recursive_call_p (struc\n      methods.  */\n   else\n     {\n-      if (max_count > profile_count::zero () && edge->count.initialized_p ()\n+      if (max_count.nonzero_p () && edge->count.initialized_p ()\n \t  && (edge->count.to_gcov_type () * 100\n \t      / outer_node->count.to_gcov_type ()\n \t      <= PARAM_VALUE (PARAM_MIN_INLINE_RECURSIVE_PROBABILITY)))\n@@ -923,7 +923,7 @@ want_inline_self_recursive_call_p (struc\n \t  reason = \"profile of recursive call is too small\";\n \t  want_inline = false;\n \t}\n-      else if ((max_count == profile_count::zero ()\n+      else if ((!max_count.nonzero_p ()\n \t        || !edge->count.initialized_p ())\n \t       && (edge->frequency * 100 / caller_freq\n \t           <= PARAM_VALUE (PARAM_MIN_INLINE_RECURSIVE_PROBABILITY)))\n@@ -1070,7 +1070,7 @@ edge_badness (struct cgraph_edge *edge,\n      then calls without.\n   */\n   else if (opt_for_fn (caller->decl, flag_guess_branch_prob)\n-\t   || caller->count > profile_count::zero ())\n+\t   || caller->count.nonzero_p ())\n     {\n       sreal numerator, denominator;\n       int overall_growth;\n@@ -1080,7 +1080,7 @@ edge_badness (struct cgraph_edge *edge,\n \t\t   - inlined_time);\n       if (numerator == 0)\n \tnumerator = ((sreal) 1 >> 8);\n-      if (caller->count > profile_count::zero ())\n+      if (caller->count.nonzero_p ())\n \tnumerator *= caller->count.to_gcov_type ();\n       else if (caller->count.initialized_p ())\n \tnumerator = numerator >> 11;\n@@ -1521,7 +1521,7 @@ recursive_inlining (struct cgraph_edge *\n \t{\n \t  fprintf (dump_file,\n \t\t   \"   Inlining call of depth %i\", depth);\n-\t  if (node->count > profile_count::zero ())\n+\t  if (node->count.nonzero_p ())\n \t    {\n \t      fprintf (dump_file, \" called approx. %.2f times per call\",\n \t\t       (double)curr->count.to_gcov_type ()\n@@ -1789,8 +1789,7 @@ inline_small_functions (void)\n \t  }\n \n \tfor (edge = node->callers; edge; edge = edge->next_caller)\n-\t  if (!(max_count >= edge->count))\n-\t    max_count = edge->count;\n+\t  max_count = max_count.max (edge->count);\n       }\n   ipa_free_postorder_info ();\n   initialize_growth_caches ();\n@@ -2049,7 +2048,7 @@ inline_small_functions (void)\n       update_caller_keys (&edge_heap, where, updated_nodes, NULL);\n       /* Offline copy count has possibly changed, recompute if profile is\n \t available.  */\n-      if (max_count > profile_count::zero ())\n+      if (max_count.nonzero_p ())\n         {\n \t  struct cgraph_node *n = cgraph_node::get (edge->callee->decl);\n \t  if (n != edge->callee && n->analyzed)\nIndex: ipa-profile.c\n===================================================================\n--- ipa-profile.c\t(revision 254348)\n+++ ipa-profile.c\t(working copy)\n@@ -179,53 +179,54 @@ ipa_profile_generate_summary (void)\n   hash_table<histogram_hash> hashtable (10);\n   \n   FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node)\n-    FOR_EACH_BB_FN (bb, DECL_STRUCT_FUNCTION (node->decl))\n-      {\n-\tint time = 0;\n-\tint size = 0;\n-        for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))\n-\t  {\n-\t    gimple *stmt = gsi_stmt (gsi);\n-\t    if (gimple_code (stmt) == GIMPLE_CALL\n-\t\t&& !gimple_call_fndecl (stmt))\n-\t      {\n-\t\thistogram_value h;\n-\t\th = gimple_histogram_value_of_type\n-\t\t      (DECL_STRUCT_FUNCTION (node->decl),\n-\t\t       stmt, HIST_TYPE_INDIR_CALL);\n-\t\t/* No need to do sanity check: gimple_ic_transform already\n-\t\t   takes away bad histograms.  */\n-\t\tif (h)\n-\t\t  {\n-\t\t    /* counter 0 is target, counter 1 is number of execution we called target,\n-\t\t       counter 2 is total number of executions.  */\n-\t\t    if (h->hvalue.counters[2])\n-\t\t      {\n-\t\t\tstruct cgraph_edge * e = node->get_edge (stmt);\n-\t\t\tif (e && !e->indirect_unknown_callee)\n-\t\t\t  continue;\n-\t\t\te->indirect_info->common_target_id\n-\t\t\t  = h->hvalue.counters [0];\n-\t\t\te->indirect_info->common_target_probability\n-\t\t\t  = GCOV_COMPUTE_SCALE (h->hvalue.counters [1], h->hvalue.counters [2]);\n-\t\t\tif (e->indirect_info->common_target_probability > REG_BR_PROB_BASE)\n-\t\t\t  {\n-\t\t\t    if (dump_file)\n-\t\t\t      fprintf (dump_file, \"Probability capped to 1\\n\");\n-\t\t\t    e->indirect_info->common_target_probability = REG_BR_PROB_BASE;\n-\t\t\t  }\n-\t\t      }\n-\t\t    gimple_remove_histogram_value (DECL_STRUCT_FUNCTION (node->decl),\n-\t\t\t\t\t\t    stmt, h);\n-\t\t  }\n-\t      }\n-\t    time += estimate_num_insns (stmt, &eni_time_weights);\n-\t    size += estimate_num_insns (stmt, &eni_size_weights);\n-\t  }\n-\tif (bb->count.initialized_p ())\n-\t  account_time_size (&hashtable, histogram, bb->count.to_gcov_type (),\n-\t\t\t     time, size);\n-      }\n+    if (ENTRY_BLOCK_PTR_FOR_FN (DECL_STRUCT_FUNCTION (node->decl))->count.ipa_p ())\n+      FOR_EACH_BB_FN (bb, DECL_STRUCT_FUNCTION (node->decl))\n+\t{\n+\t  int time = 0;\n+\t  int size = 0;\n+\t  for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))\n+\t    {\n+\t      gimple *stmt = gsi_stmt (gsi);\n+\t      if (gimple_code (stmt) == GIMPLE_CALL\n+\t\t  && !gimple_call_fndecl (stmt))\n+\t\t{\n+\t\t  histogram_value h;\n+\t\t  h = gimple_histogram_value_of_type\n+\t\t\t(DECL_STRUCT_FUNCTION (node->decl),\n+\t\t\t stmt, HIST_TYPE_INDIR_CALL);\n+\t\t  /* No need to do sanity check: gimple_ic_transform already\n+\t\t     takes away bad histograms.  */\n+\t\t  if (h)\n+\t\t    {\n+\t\t      /* counter 0 is target, counter 1 is number of execution we called target,\n+\t\t\t counter 2 is total number of executions.  */\n+\t\t      if (h->hvalue.counters[2])\n+\t\t\t{\n+\t\t\t  struct cgraph_edge * e = node->get_edge (stmt);\n+\t\t\t  if (e && !e->indirect_unknown_callee)\n+\t\t\t    continue;\n+\t\t\t  e->indirect_info->common_target_id\n+\t\t\t    = h->hvalue.counters [0];\n+\t\t\t  e->indirect_info->common_target_probability\n+\t\t\t    = GCOV_COMPUTE_SCALE (h->hvalue.counters [1], h->hvalue.counters [2]);\n+\t\t\t  if (e->indirect_info->common_target_probability > REG_BR_PROB_BASE)\n+\t\t\t    {\n+\t\t\t      if (dump_file)\n+\t\t\t\tfprintf (dump_file, \"Probability capped to 1\\n\");\n+\t\t\t      e->indirect_info->common_target_probability = REG_BR_PROB_BASE;\n+\t\t\t    }\n+\t\t\t}\n+\t\t      gimple_remove_histogram_value (DECL_STRUCT_FUNCTION (node->decl),\n+\t\t\t\t\t\t      stmt, h);\n+\t\t    }\n+\t\t}\n+\t      time += estimate_num_insns (stmt, &eni_time_weights);\n+\t      size += estimate_num_insns (stmt, &eni_size_weights);\n+\t    }\n+\t  if (bb->count.ipa_p () && bb->count.initialized_p ())\n+\t    account_time_size (&hashtable, histogram, bb->count.ipa ().to_gcov_type (),\n+\t\t\t       time, size);\n+\t}\n   histogram.qsort (cmp_counts);\n }\n \nIndex: ipa-split.c\n===================================================================\n--- ipa-split.c\t(revision 254348)\n+++ ipa-split.c\t(working copy)\n@@ -444,7 +444,7 @@ consider_split (struct split_point *curr\n \n   /* Do not split when we would end up calling function anyway.  */\n   if (incoming_freq\n-      >= (ENTRY_BLOCK_PTR_FOR_FN (cfun)->frequency\n+      >= (ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.to_frequency (cfun)\n \t  * PARAM_VALUE (PARAM_PARTIAL_INLINING_ENTRY_PROBABILITY) / 100))\n     {\n       /* When profile is guessed, we can not expect it to give us\n@@ -454,13 +454,14 @@ consider_split (struct split_point *curr\n \t is likely noticeable win.  */\n       if (back_edge\n \t  && profile_status_for_fn (cfun) != PROFILE_READ\n-\t  && incoming_freq < ENTRY_BLOCK_PTR_FOR_FN (cfun)->frequency)\n+\t  && incoming_freq\n+\t\t < ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.to_frequency (cfun))\n \t{\n \t  if (dump_file && (dump_flags & TDF_DETAILS))\n \t    fprintf (dump_file,\n \t\t     \"  Split before loop, accepting despite low frequencies %i %i.\\n\",\n \t\t     incoming_freq,\n-\t\t     ENTRY_BLOCK_PTR_FOR_FN (cfun)->frequency);\n+\t\t     ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.to_frequency (cfun));\n \t}\n       else\n \t{\n@@ -714,8 +715,10 @@ consider_split (struct split_point *curr\n      out smallest size of header.\n      In future we might re-consider this heuristics.  */\n   if (!best_split_point.split_bbs\n-      || best_split_point.entry_bb->frequency > current->entry_bb->frequency\n-      || (best_split_point.entry_bb->frequency == current->entry_bb->frequency\n+      || best_split_point.entry_bb->count.to_frequency (cfun)\n+\t > current->entry_bb->count.to_frequency (cfun)\n+      || (best_split_point.entry_bb->count.to_frequency (cfun)\n+\t  == current->entry_bb->count.to_frequency (cfun)\n \t  && best_split_point.split_size < current->split_size))\n \t\n     {\n@@ -1285,7 +1288,7 @@ split_function (basic_block return_bb, s\n \t  FOR_EACH_EDGE (e, ei, return_bb->preds)\n \t    if (bitmap_bit_p (split_point->split_bbs, e->src->index))\n \t      {\n-\t\tnew_return_bb->frequency += EDGE_FREQUENCY (e);\n+\t\tnew_return_bb->count += e->count ();\n \t\tredirect_edge_and_branch (e, new_return_bb);\n \t\tredirected = true;\n \t\tbreak;\nIndex: ira-build.c\n===================================================================\n--- ira-build.c\t(revision 254348)\n+++ ira-build.c\t(working copy)\n@@ -2202,7 +2202,8 @@ loop_compare_func (const void *v1p, cons\n     return -1;\n   if (! l1->to_remove_p && l2->to_remove_p)\n     return 1;\n-  if ((diff = l1->loop->header->frequency - l2->loop->header->frequency) != 0)\n+  if ((diff = l1->loop->header->count.to_frequency (cfun)\n+\t      - l2->loop->header->count.to_frequency (cfun)) != 0)\n     return diff;\n   if ((diff = (int) loop_depth (l1->loop) - (int) loop_depth (l2->loop)) != 0)\n     return diff;\n@@ -2260,7 +2261,7 @@ mark_loops_for_removal (void)\n \t  (ira_dump_file,\n \t   \"  Mark loop %d (header %d, freq %d, depth %d) for removal (%s)\\n\",\n \t   sorted_loops[i]->loop_num, sorted_loops[i]->loop->header->index,\n-\t   sorted_loops[i]->loop->header->frequency,\n+\t   sorted_loops[i]->loop->header->count.to_frequency (cfun),\n \t   loop_depth (sorted_loops[i]->loop),\n \t   low_pressure_loop_node_p (sorted_loops[i]->parent)\n \t   && low_pressure_loop_node_p (sorted_loops[i])\n@@ -2293,7 +2294,7 @@ mark_all_loops_for_removal (void)\n \t     \"  Mark loop %d (header %d, freq %d, depth %d) for removal\\n\",\n \t     ira_loop_nodes[i].loop_num,\n \t     ira_loop_nodes[i].loop->header->index,\n-\t     ira_loop_nodes[i].loop->header->frequency,\n+\t     ira_loop_nodes[i].loop->header->count.to_frequency (cfun),\n \t     loop_depth (ira_loop_nodes[i].loop));\n       }\n }\nIndex: loop-doloop.c\n===================================================================\n--- loop-doloop.c\t(revision 254348)\n+++ loop-doloop.c\t(working copy)\n@@ -506,7 +506,6 @@ doloop_modify (struct loop *loop, struct\n       set_immediate_dominator (CDI_DOMINATORS, new_preheader, preheader);\n \n       set_zero->count = profile_count::uninitialized ();\n-      set_zero->frequency = 0;\n \n       te = single_succ_edge (preheader);\n       for (; ass; ass = XEXP (ass, 1))\n@@ -522,7 +521,6 @@ doloop_modify (struct loop *loop, struct\n \t     also be very hard to show that it is impossible, so we must\n \t     handle this case.  */\n \t  set_zero->count = preheader->count;\n-\t  set_zero->frequency = preheader->frequency;\n \t}\n \n       if (EDGE_COUNT (set_zero->preds) == 0)\nIndex: loop-unroll.c\n===================================================================\n--- loop-unroll.c\t(revision 254348)\n+++ loop-unroll.c\t(working copy)\n@@ -863,7 +863,7 @@ unroll_loop_runtime_iterations (struct l\n   unsigned i, j;\n   profile_probability p;\n   basic_block preheader, *body, swtch, ezc_swtch = NULL;\n-  int may_exit_copy, iter_freq, new_freq;\n+  int may_exit_copy;\n   profile_count iter_count, new_count;\n   unsigned n_peel;\n   edge e;\n@@ -970,12 +970,10 @@ unroll_loop_runtime_iterations (struct l\n   /* Record the place where switch will be built for preconditioning.  */\n   swtch = split_edge (loop_preheader_edge (loop));\n \n-  /* Compute frequency/count increments for each switch block and initialize\n+  /* Compute count increments for each switch block and initialize\n      innermost switch block.  Switch blocks and peeled loop copies are built\n      from innermost outward.  */\n-  iter_freq = new_freq = swtch->frequency / (max_unroll + 1);\n   iter_count = new_count = swtch->count.apply_scale (1, max_unroll + 1);\n-  swtch->frequency = new_freq;\n   swtch->count = new_count;\n \n   for (i = 0; i < n_peel; i++)\n@@ -995,8 +993,7 @@ unroll_loop_runtime_iterations (struct l\n       p = profile_probability::always ().apply_scale (1, i + 2);\n \n       preheader = split_edge (loop_preheader_edge (loop));\n-      /* Add in frequency/count of edge from switch block.  */\n-      preheader->frequency += iter_freq;\n+      /* Add in count of edge from switch block.  */\n       preheader->count += iter_count;\n       branch_code = compare_and_jump_seq (copy_rtx (niter), GEN_INT (j), EQ,\n \t\t\t\t\t  block_label (preheader), p,\n@@ -1009,9 +1006,7 @@ unroll_loop_runtime_iterations (struct l\n       swtch = split_edge_and_insert (single_pred_edge (swtch), branch_code);\n       set_immediate_dominator (CDI_DOMINATORS, preheader, swtch);\n       single_succ_edge (swtch)->probability = p.invert ();\n-      new_freq += iter_freq;\n       new_count += iter_count;\n-      swtch->frequency = new_freq;\n       swtch->count = new_count;\n       e = make_edge (swtch, preheader,\n \t\t     single_succ_edge (swtch)->flags & EDGE_IRREDUCIBLE_LOOP);\n@@ -1024,12 +1019,10 @@ unroll_loop_runtime_iterations (struct l\n       p = profile_probability::always ().apply_scale (1, max_unroll + 1);\n       swtch = ezc_swtch;\n       preheader = split_edge (loop_preheader_edge (loop));\n-      /* Recompute frequency/count adjustments since initial peel copy may\n+      /* Recompute count adjustments since initial peel copy may\n \t have exited and reduced those values that were computed above.  */\n-      iter_freq = swtch->frequency / (max_unroll + 1);\n       iter_count = swtch->count.apply_scale (1, max_unroll + 1);\n-      /* Add in frequency/count of edge from switch block.  */\n-      preheader->frequency += iter_freq;\n+      /* Add in count of edge from switch block.  */\n       preheader->count += iter_count;\n       branch_code = compare_and_jump_seq (copy_rtx (niter), const0_rtx, EQ,\n \t\t\t\t\t  block_label (preheader), p,\nIndex: lto-streamer-in.c\n===================================================================\n--- lto-streamer-in.c\t(revision 254348)\n+++ lto-streamer-in.c\t(working copy)\n@@ -1192,6 +1192,7 @@ input_function (tree fn_decl, struct dat\n     gimple_set_body (fn_decl, bb_seq (ei_edge (ei)->dest));\n   }\n \n+  counts_to_freqs ();\n   fixup_call_stmt_edges (node, stmts);\n   execute_all_ipa_stmt_fixups (node, stmts);\n \nIndex: omp-expand.c\n===================================================================\n--- omp-expand.c\t(revision 254348)\n+++ omp-expand.c\t(working copy)\n@@ -1399,6 +1399,7 @@ expand_omp_taskreg (struct omp_region *r\n \n       if (optimize)\n \toptimize_omp_library_calls (entry_stmt);\n+      counts_to_freqs ();\n       cgraph_edge::rebuild_edges ();\n \n       /* Some EH regions might become dead, see PR34608.  If\nIndex: omp-simd-clone.c\n===================================================================\n--- omp-simd-clone.c\t(revision 254348)\n+++ omp-simd-clone.c\t(working copy)\n@@ -1132,6 +1132,7 @@ simd_clone_adjust (struct cgraph_node *n\n     {\n       basic_block orig_exit = EDGE_PRED (EXIT_BLOCK_PTR_FOR_FN (cfun), 0)->src;\n       incr_bb = create_empty_bb (orig_exit);\n+      incr_bb->count = profile_count::zero ();\n       add_bb_to_loop (incr_bb, body_bb->loop_father);\n       /* The succ of orig_exit was EXIT_BLOCK_PTR_FOR_FN (cfun), with an empty\n \t flag.  Set it now to be a FALLTHRU_EDGE.  */\n@@ -1142,11 +1143,13 @@ simd_clone_adjust (struct cgraph_node *n\n \t{\n \t  edge e = EDGE_PRED (EXIT_BLOCK_PTR_FOR_FN (cfun), i);\n \t  redirect_edge_succ (e, incr_bb);\n+\t  incr_bb->count += e->count ();\n \t}\n     }\n   else if (node->simdclone->inbranch)\n     {\n       incr_bb = create_empty_bb (entry_bb);\n+      incr_bb->count = profile_count::zero ();\n       add_bb_to_loop (incr_bb, body_bb->loop_father);\n     }\n \n@@ -1243,6 +1246,7 @@ simd_clone_adjust (struct cgraph_node *n\n       gsi_insert_after (&gsi, g, GSI_CONTINUE_LINKING);\n       edge e = make_edge (loop->header, incr_bb, EDGE_TRUE_VALUE);\n       e->probability = profile_probability::unlikely ().guessed ();\n+      incr_bb->count += e->count ();\n       edge fallthru = FALLTHRU_EDGE (loop->header);\n       fallthru->flags = EDGE_FALSE_VALUE;\n       fallthru->probability = profile_probability::likely ().guessed ();\nIndex: predict.c\n===================================================================\n--- predict.c\t(revision 254348)\n+++ predict.c\t(working copy)\n@@ -137,12 +137,12 @@ maybe_hot_frequency_p (struct function *\n   if (profile_status_for_fn (fun) == PROFILE_ABSENT)\n     return true;\n   if (node->frequency == NODE_FREQUENCY_EXECUTED_ONCE\n-      && freq < (ENTRY_BLOCK_PTR_FOR_FN (fun)->frequency * 2 / 3))\n+      && freq < (ENTRY_BLOCK_PTR_FOR_FN (fun)->count.to_frequency (cfun) * 2 / 3))\n     return false;\n   if (PARAM_VALUE (HOT_BB_FREQUENCY_FRACTION) == 0)\n     return false;\n   if (freq * PARAM_VALUE (HOT_BB_FREQUENCY_FRACTION)\n-      < ENTRY_BLOCK_PTR_FOR_FN (fun)->frequency)\n+      < ENTRY_BLOCK_PTR_FOR_FN (fun)->count.to_frequency (cfun))\n     return false;\n   return true;\n }\n@@ -175,10 +175,14 @@ set_hot_bb_threshold (gcov_type min)\n /* Return TRUE if frequency FREQ is considered to be hot.  */\n \n bool\n-maybe_hot_count_p (struct function *, profile_count count)\n+maybe_hot_count_p (struct function *fun, profile_count count)\n {\n   if (!count.initialized_p ())\n     return true;\n+  if (!count.ipa_p ())\n+    return maybe_hot_frequency_p (fun, count.to_frequency (fun));\n+  if (count.ipa () == profile_count::zero ())\n+    return false;\n   /* Code executed at most once is not hot.  */\n   if (count <= MAX (profile_info ? profile_info->runs : 1, 1))\n     return false;\n@@ -192,9 +196,7 @@ bool\n maybe_hot_bb_p (struct function *fun, const_basic_block bb)\n {\n   gcc_checking_assert (fun);\n-  if (!maybe_hot_count_p (fun, bb->count))\n-    return false;\n-  return maybe_hot_frequency_p (fun, bb->frequency);\n+  return maybe_hot_count_p (fun, bb->count);\n }\n \n /* Return true in case BB can be CPU intensive and should be optimized\n@@ -203,9 +205,7 @@ maybe_hot_bb_p (struct function *fun, co\n bool\n maybe_hot_edge_p (edge e)\n {\n-  if (!maybe_hot_count_p (cfun, e->count ()))\n-    return false;\n-  return maybe_hot_frequency_p (cfun, EDGE_FREQUENCY (e));\n+  return maybe_hot_count_p (cfun, e->count ());\n }\n \n /* Return true if profile COUNT and FREQUENCY, or function FUN static\n@@ -213,7 +213,7 @@ maybe_hot_edge_p (edge e)\n    \n static bool\n probably_never_executed (struct function *fun,\n-                         profile_count count, int)\n+                         profile_count count)\n {\n   gcc_checking_assert (fun);\n   if (count == profile_count::zero ())\n@@ -238,7 +238,7 @@ probably_never_executed (struct function\n bool\n probably_never_executed_bb_p (struct function *fun, const_basic_block bb)\n {\n-  return probably_never_executed (fun, bb->count, bb->frequency);\n+  return probably_never_executed (fun, bb->count);\n }\n \n \n@@ -259,7 +259,7 @@ probably_never_executed_edge_p (struct f\n {\n   if (unlikely_executed_edge_p (e))\n     return true;\n-  return probably_never_executed (fun, e->count (), EDGE_FREQUENCY (e));\n+  return probably_never_executed (fun, e->count ());\n }\n \n /* Return true when current function should always be optimized for size.  */\n@@ -1289,7 +1289,8 @@ combine_predictions_for_bb (basic_block\n     }\n   clear_bb_predictions (bb);\n \n-  if (!bb->count.initialized_p () && !dry_run)\n+  if ((!bb->count.nonzero_p () || !first->probability.initialized_p ())\n+      && !dry_run)\n     {\n       first->probability\n \t = profile_probability::from_reg_br_prob_base (combined_probability);\n@@ -3014,10 +3015,7 @@ propagate_freq (basic_block head, bitmap\n       BLOCK_INFO (bb)->npredecessors = count;\n       /* When function never returns, we will never process exit block.  */\n       if (!count && bb == EXIT_BLOCK_PTR_FOR_FN (cfun))\n-\t{\n-\t  bb->count = profile_count::zero ();\n-\t  bb->frequency = 0;\n-\t}\n+\tbb->count = profile_count::zero ();\n     }\n \n   BLOCK_INFO (head)->frequency = 1;\n@@ -3050,7 +3048,10 @@ propagate_freq (basic_block head, bitmap\n \t\t\t\t  * BLOCK_INFO (e->src)->frequency /\n \t\t\t\t  REG_BR_PROB_BASE);  */\n \n-\t\tsreal tmp = e->probability.to_reg_br_prob_base ();\n+\t\t/* FIXME: Graphite is producing edges with no profile. Once\n+\t\t   this is fixed, drop this.  */\n+\t\tsreal tmp = e->probability.initialized_p () ?\n+\t\t\t    e->probability.to_reg_br_prob_base () : 0;\n \t\ttmp *= BLOCK_INFO (e->src)->frequency;\n \t\ttmp *= real_inv_br_prob_base;\n \t\tfrequency += tmp;\n@@ -3082,7 +3083,10 @@ propagate_freq (basic_block head, bitmap\n \t     = ((e->probability * BLOCK_INFO (bb)->frequency)\n \t     / REG_BR_PROB_BASE); */\n \n-\t  sreal tmp = e->probability.to_reg_br_prob_base ();\n+\t  /* FIXME: Graphite is producing edges with no profile. Once\n+\t     this is fixed, drop this.  */\n+\t  sreal tmp = e->probability.initialized_p () ?\n+\t\t      e->probability.to_reg_br_prob_base () : 0;\n \t  tmp *= BLOCK_INFO (bb)->frequency;\n \t  EDGE_INFO (e)->back_edge_prob = tmp * real_inv_br_prob_base;\n \t}\n@@ -3196,10 +3200,26 @@ drop_profile (struct cgraph_node *node,\n     }\n \n   basic_block bb;\n-  FOR_ALL_BB_FN (bb, fn)\n+  push_cfun (DECL_STRUCT_FUNCTION (node->decl));\n+  if (flag_guess_branch_prob)\n     {\n-      bb->count = profile_count::uninitialized ();\n+      bool clear_zeros\n+\t = ENTRY_BLOCK_PTR_FOR_FN\n+\t\t (DECL_STRUCT_FUNCTION (node->decl))->count.nonzero_p ();\n+      FOR_ALL_BB_FN (bb, fn)\n+\tif (clear_zeros || !(bb->count == profile_count::zero ()))\n+\t  bb->count = bb->count.guessed_local ();\n+      DECL_STRUCT_FUNCTION (node->decl)->cfg->count_max =\n+        DECL_STRUCT_FUNCTION (node->decl)->cfg->count_max.guessed_local ();\n     }\n+  else\n+    {\n+      FOR_ALL_BB_FN (bb, fn)\n+\tbb->count = profile_count::uninitialized ();\n+      DECL_STRUCT_FUNCTION (node->decl)->cfg->count_max\n+\t = profile_count::uninitialized ();\n+    }\n+  pop_cfun ();\n \n   struct cgraph_edge *e;\n   for (e = node->callees; e; e = e->next_caller)\n@@ -3300,33 +3320,16 @@ handle_missing_profiles (void)\n bool\n counts_to_freqs (void)\n {\n-  gcov_type count_max;\n-  profile_count true_count_max = profile_count::zero ();\n+  profile_count true_count_max = profile_count::uninitialized ();\n   basic_block bb;\n \n-  /* Don't overwrite the estimated frequencies when the profile for\n-     the function is missing.  We may drop this function PROFILE_GUESSED\n-     later in drop_profile ().  */\n-  if (!ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.initialized_p ()\n-      || ENTRY_BLOCK_PTR_FOR_FN (cfun)->count == profile_count::zero ())\n-    return false;\n-\n   FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (cfun), NULL, next_bb)\n-    if (bb->count > true_count_max)\n-      true_count_max = bb->count;\n+    if (!(bb->count < true_count_max))\n+      true_count_max = true_count_max.max (bb->count);\n \n-  /* If we have no counts to base frequencies on, keep those that are\n-     already there.  */\n-  if (!(true_count_max > 0))\n-    return false;\n-\n-  count_max = true_count_max.to_gcov_type ();\n+  cfun->cfg->count_max = true_count_max;\n \n-  FOR_ALL_BB_FN (bb, cfun)\n-    if (bb->count.initialized_p ())\n-      bb->frequency = RDIV (bb->count.to_gcov_type () * BB_FREQ_MAX, count_max);\n-\n-  return true;\n+  return true_count_max.nonzero_p ();\n }\n \n /* Return true if function is likely to be expensive, so there is no point to\n@@ -3348,11 +3351,11 @@ expensive_function_p (int threshold)\n   /* Frequencies are out of range.  This either means that function contains\n      internal loop executing more than BB_FREQ_MAX times or profile feedback\n      is available and function has not been executed at all.  */\n-  if (ENTRY_BLOCK_PTR_FOR_FN (cfun)->frequency == 0)\n+  if (ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.to_frequency (cfun) == 0)\n     return true;\n \n   /* Maximally BB_FREQ_MAX^2 so overflow won't happen.  */\n-  limit = ENTRY_BLOCK_PTR_FOR_FN (cfun)->frequency * threshold;\n+  limit = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.to_frequency (cfun) * threshold;\n   FOR_EACH_BB_FN (bb, cfun)\n     {\n       rtx_insn *insn;\n@@ -3360,7 +3363,7 @@ expensive_function_p (int threshold)\n       FOR_BB_INSNS (bb, insn)\n \tif (active_insn_p (insn))\n \t  {\n-\t    sum += bb->frequency;\n+\t    sum += bb->count.to_frequency (cfun);\n \t    if (sum > limit)\n \t      return true;\n \t}\n@@ -3409,7 +3412,6 @@ propagate_unlikely_bbs_forward (void)\n \t\t     \"Basic block %i is marked unlikely by forward prop\\n\",\n \t\t     bb->index);\n \t  bb->count = profile_count::zero ();\n-\t  bb->frequency = 0;\n \t}\n       else\n         bb->aux = NULL;\n@@ -3440,9 +3442,6 @@ determine_unlikely_bbs ()\n \t  bb->count = profile_count::zero ();\n \t}\n \n-      if (bb->count == profile_count::zero ())\n-        bb->frequency = 0;\n-\n       FOR_EACH_EDGE (e, ei, bb->succs)\n \tif (!(e->probability == profile_probability::never ())\n \t    && unlikely_executed_edge_p (e))\n@@ -3497,7 +3496,6 @@ determine_unlikely_bbs ()\n \t\t \"Basic block %i is marked unlikely by backward prop\\n\",\n \t\t bb->index);\n       bb->count = profile_count::zero ();\n-      bb->frequency = 0;\n       FOR_EACH_EDGE (e, ei, bb->preds)\n \tif (!(e->probability == profile_probability::never ()))\n \t  {\n@@ -3554,8 +3552,13 @@ estimate_bb_frequencies (bool force)\n \n \t  FOR_EACH_EDGE (e, ei, bb->succs)\n \t    {\n-\t      EDGE_INFO (e)->back_edge_prob\n-\t\t = e->probability.to_reg_br_prob_base ();\n+\t      /* FIXME: Graphite is producing edges with no profile. Once\n+\t\t this is fixed, drop this.  */\n+\t      if (e->probability.initialized_p ())\n+\t        EDGE_INFO (e)->back_edge_prob\n+\t\t   = e->probability.to_reg_br_prob_base ();\n+\t      else\n+\t\tEDGE_INFO (e)->back_edge_prob = REG_BR_PROB_BASE / 2;\n \t      EDGE_INFO (e)->back_edge_prob *= real_inv_br_prob_base;\n \t    }\n \t}\n@@ -3564,16 +3567,28 @@ estimate_bb_frequencies (bool force)\n          to outermost to examine frequencies for back edges.  */\n       estimate_loops ();\n \n+      bool global0 = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.initialized_p ()\n+\t\t     && ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.ipa_p ();\n+\n       freq_max = 0;\n       FOR_EACH_BB_FN (bb, cfun)\n \tif (freq_max < BLOCK_INFO (bb)->frequency)\n \t  freq_max = BLOCK_INFO (bb)->frequency;\n \n       freq_max = real_bb_freq_max / freq_max;\n+      cfun->cfg->count_max = profile_count::uninitialized ();\n       FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (cfun), NULL, next_bb)\n \t{\n \t  sreal tmp = BLOCK_INFO (bb)->frequency * freq_max + real_one_half;\n-\t  bb->frequency = tmp.to_int ();\n+\t  profile_count count = profile_count::from_gcov_type (tmp.to_int ());\t\n+\n+\t  /* If we have profile feedback in which this function was never\n+\t     executed, then preserve this info.  */\n+\t  if (global0)\n+\t    bb->count = count.global0 ();\n+\t  else if (!(bb->count == profile_count::zero ()))\n+\t    bb->count = count.guessed_local ();\n+          cfun->cfg->count_max = cfun->cfg->count_max.max (bb->count);\n \t}\n \n       free_aux_for_blocks ();\n@@ -3598,7 +3613,8 @@ compute_function_frequency (void)\n   if (profile_status_for_fn (cfun) != PROFILE_READ)\n     {\n       int flags = flags_from_decl_or_type (current_function_decl);\n-      if (ENTRY_BLOCK_PTR_FOR_FN (cfun)->count == profile_count::zero ()\n+      if ((ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.ipa_p ()\n+\t   && ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.ipa() == profile_count::zero ())\n \t  || lookup_attribute (\"cold\", DECL_ATTRIBUTES (current_function_decl))\n \t     != NULL)\n \t{\n@@ -3717,7 +3733,7 @@ pass_profile::execute (function *fun)\n    {\n      struct loop *loop;\n      FOR_EACH_LOOP (loop, LI_FROM_INNERMOST)\n-       if (loop->header->frequency)\n+       if (loop->header->count.initialized_p ())\n          fprintf (dump_file, \"Loop got predicted %d to iterate %i times.\\n\",\n        \t   loop->num,\n        \t   (int)expected_loop_iterations_unbounded (loop));\n@@ -3843,15 +3859,12 @@ rebuild_frequencies (void)\n      which may also lead to frequencies incorrectly reduced to 0. There\n      is less precision in the probabilities, so we only do this for small\n      max counts.  */\n-  profile_count count_max = profile_count::zero ();\n+  cfun->cfg->count_max = profile_count::uninitialized ();\n   basic_block bb;\n   FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (cfun), NULL, next_bb)\n-    if (bb->count > count_max)\n-      count_max = bb->count;\n+    cfun->cfg->count_max = cfun->cfg->count_max.max (bb->count);\n \n-  if (profile_status_for_fn (cfun) == PROFILE_GUESSED\n-      || (!flag_auto_profile && profile_status_for_fn (cfun) == PROFILE_READ\n-\t  && count_max < REG_BR_PROB_BASE / 10))\n+  if (profile_status_for_fn (cfun) == PROFILE_GUESSED)\n     {\n       loop_optimizer_init (0);\n       add_noreturn_fake_exit_edges ();\n@@ -4017,17 +4030,19 @@ force_edge_cold (edge e, bool impossible\n \t after loop transforms.  */\n       if (!(prob_sum > profile_probability::never ())\n \t  && count_sum == profile_count::zero ()\n-\t  && single_pred_p (e->src) && e->src->frequency > (impossible ? 0 : 1))\n+\t  && single_pred_p (e->src) && e->src->count.to_frequency (cfun)\n+\t     > (impossible ? 0 : 1))\n \t{\n-\t  int old_frequency = e->src->frequency;\n+\t  int old_frequency = e->src->count.to_frequency (cfun);\n \t  if (dump_file && (dump_flags & TDF_DETAILS))\n \t    fprintf (dump_file, \"Making bb %i %s.\\n\", e->src->index,\n \t\t     impossible ? \"impossible\" : \"cold\");\n-\t  e->src->frequency = MIN (e->src->frequency, impossible ? 0 : 1);\n+\t  int new_frequency = MIN (e->src->count.to_frequency (cfun),\n+\t\t\t\t   impossible ? 0 : 1);\n \t  if (impossible)\n \t    e->src->count = profile_count::zero ();\n \t  else\n-\t    e->src->count = e->count ().apply_scale (e->src->frequency,\n+\t    e->src->count = e->count ().apply_scale (new_frequency,\n \t\t\t\t\t\t     old_frequency);\n \t  force_edge_cold (single_pred_edge (e->src), impossible);\n \t}\nIndex: profile-count.c\n===================================================================\n--- profile-count.c\t(revision 254348)\n+++ profile-count.c\t(working copy)\n@@ -42,7 +42,11 @@ profile_count::dump (FILE *f) const\n   else\n     {\n       fprintf (f, \"%\" PRId64, m_val);\n-      if (m_quality == profile_adjusted)\n+      if (m_quality == profile_guessed_local)\n+\tfprintf (f, \" (estimated locally)\");\n+      else if (m_quality == profile_guessed_global0)\n+\tfprintf (f, \" (estimated locally, globally 0)\");\n+      else if (m_quality == profile_adjusted)\n \tfprintf (f, \" (adjusted)\");\n       else if (m_quality == profile_afdo)\n \tfprintf (f, \" (auto FDO)\");\n@@ -65,6 +69,7 @@ profile_count::debug () const\n bool\n profile_count::differs_from_p (profile_count other) const\n {\n+  gcc_checking_assert (compatible_p (other));\n   if (!initialized_p () || !other.initialized_p ())\n     return false;\n   if ((uint64_t)m_val - (uint64_t)other.m_val < 100\n@@ -213,3 +218,40 @@ slow_safe_scale_64bit (uint64_t a, uint6\n   *res = (uint64_t) -1;\n   return false;\n }\n+\n+/* Return count as frequency within FUN scaled in range 0 to REG_FREQ_MAX\n+   Used for legacy code and should not be used anymore.  */\n+\n+int\n+profile_count::to_frequency (struct function *fun) const\n+{\n+  if (!initialized_p ())\n+    return BB_FREQ_MAX;\n+  if (*this == profile_count::zero ())\n+    return 0;\n+  gcc_assert (REG_BR_PROB_BASE == BB_FREQ_MAX\n+\t      && fun->cfg->count_max.initialized_p ());\n+  profile_probability prob = probability_in (fun->cfg->count_max);\n+  if (!prob.initialized_p ())\n+    return REG_BR_PROB_BASE;\n+  return prob.to_reg_br_prob_base ();\n+}\n+\n+/* Return count as frequency within FUN scaled in range 0 to CGRAPH_FREQ_MAX\n+   where CGRAPH_FREQ_BASE means that count equals to entry block count.\n+   Used for legacy code and should not be used anymore.  */\n+\n+int\n+profile_count::to_cgraph_frequency (profile_count entry_bb_count) const\n+{\n+  if (!initialized_p ())\n+    return CGRAPH_FREQ_BASE;\n+  if (*this == profile_count::zero ())\n+    return 0;\n+  gcc_checking_assert (entry_bb_count.initialized_p ());\n+  uint64_t scale;\n+  if (!safe_scale_64bit (!entry_bb_count.m_val ? m_val + 1 : m_val,\n+\t\t\t CGRAPH_FREQ_BASE, MAX (1, entry_bb_count.m_val), &scale))\n+    return CGRAPH_FREQ_MAX;\n+  return MIN (scale, CGRAPH_FREQ_MAX);\n+}\nIndex: profile-count.h\n===================================================================\n--- profile-count.h\t(revision 254348)\n+++ profile-count.h\t(working copy)\n@@ -21,21 +21,37 @@ along with GCC; see the file COPYING3.\n #ifndef GCC_PROFILE_COUNT_H\n #define GCC_PROFILE_COUNT_H\n \n+struct function;\n+\n /* Quality of the profile count.  Because gengtype does not support enums\n    inside of classes, this is in global namespace.  */\n enum profile_quality {\n+  /* Profile is based on static branch prediction heuristics and may\n+     or may not match reality.  It is local to function and can not be compared\n+     inter-procedurally.  Never used by probabilities (they are always local).\n+   */\n+  profile_guessed_local = 0,\n+  /* Profile was read by feedback and was 0, we used local heuristics to guess\n+     better.  This is the case of functions not run in profile fedback.\n+     Never used by probabilities.  */\n+  profile_guessed_global0 = 1,\n+\n+\n   /* Profile is based on static branch prediction heuristics.  It may or may\n-     not reflect the reality.  */\n-  profile_guessed = 0,\n+     not reflect the reality but it can be compared interprocedurally\n+     (for example, we inlined function w/o profile feedback into function\n+      with feedback and propagated from that).\n+     Never used by probablities.  */\n+  profile_guessed = 2,\n   /* Profile was determined by autofdo.  */\n-  profile_afdo = 1,\n+  profile_afdo = 3,\n   /* Profile was originally based on feedback but it was adjusted\n      by code duplicating optimization.  It may not precisely reflect the\n      particular code path.  */\n-  profile_adjusted = 2,\n+  profile_adjusted = 4,\n   /* Profile was read from profile feedback or determined by accurate static\n      method.  */\n-  profile_precise = 3\n+  profile_precise = 5\n };\n \n /* The base value for branch probability notes and edge probabilities.  */\n@@ -114,15 +130,15 @@ safe_scale_64bit (uint64_t a, uint64_t b\n \n class GTY((user)) profile_probability\n {\n-  static const int n_bits = 30;\n+  static const int n_bits = 29;\n   /* We can technically use ((uint32_t) 1 << (n_bits - 1)) - 2 but that\n      will lead to harder multiplication sequences.  */\n   static const uint32_t max_probability = (uint32_t) 1 << (n_bits - 2);\n   static const uint32_t uninitialized_probability\n \t\t = ((uint32_t) 1 << (n_bits - 1)) - 1;\n \n-  uint32_t m_val : 30;\n-  enum profile_quality m_quality : 2;\n+  uint32_t m_val : 29;\n+  enum profile_quality m_quality : 3;\n \n   friend class profile_count;\n public:\n@@ -226,14 +242,14 @@ public:\n   static profile_probability from_reg_br_prob_note (int v)\n     {\n       profile_probability ret;\n-      ret.m_val = ((unsigned int)v) / 4;\n-      ret.m_quality = (enum profile_quality)(v & 3);\n+      ret.m_val = ((unsigned int)v) / 8;\n+      ret.m_quality = (enum profile_quality)(v & 7);\n       return ret;\n     }\n   int to_reg_br_prob_note () const\n     {\n       gcc_checking_assert (initialized_p ());\n-      int ret = m_val * 4 + m_quality;\n+      int ret = m_val * 8 + m_quality;\n       gcc_checking_assert (profile_probability::from_reg_br_prob_note (ret)\n \t\t\t   == *this);\n       return ret;\n@@ -489,8 +505,9 @@ public:\n     {\n       if (m_val == uninitialized_probability)\n \treturn m_quality == profile_guessed;\n-      else\n-\treturn m_val <= max_probability;\n+      else if (m_quality < profile_guessed)\n+\treturn false;\n+      return m_val <= max_probability;\n     }\n \n   /* Comparsions are three-state and conservative.  False is returned if\n@@ -530,9 +547,32 @@ public:\n   void stream_out (struct lto_output_stream *);\n };\n \n-/* Main data type to hold profile counters in GCC.  In most cases profile\n-   counts originate from profile feedback. They are 64bit integers\n-   representing number of executions during the train run.\n+/* Main data type to hold profile counters in GCC. Profile counts originate\n+   either from profile feedback, static profile estimation or both.  We do not\n+   perform whole program profile propagation and thus profile estimation\n+   counters are often local to function, while counters from profile feedback\n+   (or special cases of profile estimation) can be used inter-procedurally.\n+\n+   There are 3 basic types\n+     1) local counters which are result of intra-procedural static profile\n+        estimation.\n+     2) ipa counters which are result of profile feedback or special case\n+        of static profile estimation (such as in function main).\n+     3) counters which counts as 0 inter-procedurally (beause given function\n+        was never run in train feedback) but they hold local static profile\n+        estimate.\n+\n+   Counters of type 1 and 3 can not be mixed with counters of different type\n+   within operation (because whole function should use one type of counter)\n+   with exception that global zero mix in most operations where outcome is\n+   well defined.\n+\n+   To take local counter and use it inter-procedurally use ipa member function\n+   which strips information irelevant at the inter-procedural level.\n+\n+   Counters are 61bit integers representing number of executions during the\n+   train run or normalized frequency within the function.\n+\n    As the profile is maintained during the compilation, many adjustments are\n    made.  Not all transformations can be made precisely, most importantly\n    when code is being duplicated.  It also may happen that part of CFG has\n@@ -567,12 +607,25 @@ class GTY(()) profile_count\n      64bit.  Although a counter cannot be negative, we use a signed\n      type to hold various extra stages.  */\n \n-  static const int n_bits = 62;\n+  static const int n_bits = 61;\n   static const uint64_t max_count = ((uint64_t) 1 << n_bits) - 2;\n   static const uint64_t uninitialized_count = ((uint64_t) 1 << n_bits) - 1;\n \n   uint64_t m_val : n_bits;\n-  enum profile_quality m_quality : 2;\n+  enum profile_quality m_quality : 3;\n+\n+  /* Return true if both values can meaningfully appear in single function\n+     body.  We have either all counters in function local or global, otherwise\n+     operations between them are not really defined well.  */\n+  bool compatible_p (const profile_count other) const\n+    {\n+      if (!initialized_p () || !other.initialized_p ())\n+\treturn true;\n+      if (*this == profile_count::zero ()\n+\t  || other == profile_count::zero ())\n+\treturn true;\n+      return ipa_p () == other.ipa_p ();\n+    }\n public:\n \n   /* Used for counters which are expected to be never executed.  */\n@@ -597,7 +650,7 @@ public:\n     {\n       profile_count c;\n       c.m_val = uninitialized_count;\n-      c.m_quality = profile_guessed;\n+      c.m_quality = profile_guessed_local;\n       return c;\n     }\n \n@@ -630,6 +683,11 @@ public:\n     {\n       return m_quality >= profile_adjusted;\n     }\n+  /* Return true if vlaue can be operated inter-procedurally.  */\n+  bool ipa_p () const\n+    {\n+      return !initialized_p () || m_quality >= profile_guessed_global0;\n+    }\n \n   /* When merging basic blocks, the two different profile counts are unified.\n      Return true if this can be done without losing info about profile.\n@@ -671,6 +729,7 @@ public:\n \treturn profile_count::uninitialized ();\n \n       profile_count ret;\n+      gcc_checking_assert (compatible_p (other));\n       ret.m_val = m_val + other.m_val;\n       ret.m_quality = MIN (m_quality, other.m_quality);\n       return ret;\n@@ -688,6 +747,7 @@ public:\n \treturn *this = profile_count::uninitialized ();\n       else\n \t{\n+          gcc_checking_assert (compatible_p (other));\n \t  m_val += other.m_val;\n \t  m_quality = MIN (m_quality, other.m_quality);\n \t}\n@@ -699,6 +759,7 @@ public:\n \treturn *this;\n       if (!initialized_p () || !other.initialized_p ())\n \treturn profile_count::uninitialized ();\n+      gcc_checking_assert (compatible_p (other));\n       profile_count ret;\n       ret.m_val = m_val >= other.m_val ? m_val - other.m_val : 0;\n       ret.m_quality = MIN (m_quality, other.m_quality);\n@@ -712,6 +773,7 @@ public:\n \treturn *this = profile_count::uninitialized ();\n       else\n \t{\n+          gcc_checking_assert (compatible_p (other));\n \t  m_val = m_val >= other.m_val ? m_val - other.m_val: 0;\n \t  m_quality = MIN (m_quality, other.m_quality);\n \t}\n@@ -721,48 +783,115 @@ public:\n   /* Return false if profile_count is bogus.  */\n   bool verify () const\n     {\n-      return m_val != uninitialized_count || m_quality == profile_guessed;\n+      return m_val != uninitialized_count || m_quality == profile_guessed_local;\n     }\n \n   /* Comparsions are three-state and conservative.  False is returned if\n      the inequality can not be decided.  */\n   bool operator< (const profile_count &other) const\n     {\n-      return initialized_p () && other.initialized_p () && m_val < other.m_val;\n+      if (!initialized_p () || !other.initialized_p ())\n+\treturn false;\n+      if (*this == profile_count::zero ())\n+\treturn !(other == profile_count::zero ());\n+      if (other == profile_count::zero ())\n+\treturn false;\n+      gcc_checking_assert (compatible_p (other));\n+      return m_val < other.m_val;\n     }\n   bool operator> (const profile_count &other) const\n     {\n+      if (!initialized_p () || !other.initialized_p ())\n+\treturn false;\n+      if (*this  == profile_count::zero ())\n+\treturn false;\n+      if (other == profile_count::zero ())\n+\treturn !(*this == profile_count::zero ());\n+      gcc_checking_assert (compatible_p (other));\n       return initialized_p () && other.initialized_p () && m_val > other.m_val;\n     }\n   bool operator< (const gcov_type other) const\n     {\n+      gcc_checking_assert (ipa_p ());\n       gcc_checking_assert (other >= 0);\n       return initialized_p () && m_val < (uint64_t) other;\n     }\n   bool operator> (const gcov_type other) const\n     {\n+      gcc_checking_assert (ipa_p ());\n       gcc_checking_assert (other >= 0);\n       return initialized_p () && m_val > (uint64_t) other;\n     }\n \n   bool operator<= (const profile_count &other) const\n     {\n-      return initialized_p () && other.initialized_p () && m_val <= other.m_val;\n+      if (!initialized_p () || !other.initialized_p ())\n+\treturn false;\n+      if (*this == profile_count::zero ())\n+\treturn true;\n+      if (other == profile_count::zero ())\n+\treturn (*this == profile_count::zero ());\n+      gcc_checking_assert (compatible_p (other));\n+      return m_val <= other.m_val;\n     }\n   bool operator>= (const profile_count &other) const\n     {\n-      return initialized_p () && other.initialized_p () && m_val >= other.m_val;\n+      if (!initialized_p () || !other.initialized_p ())\n+\treturn false;\n+      if (other == profile_count::zero ())\n+\treturn true;\n+      if (*this == profile_count::zero ())\n+\treturn !(other == profile_count::zero ());\n+      gcc_checking_assert (compatible_p (other));\n+      return m_val >= other.m_val;\n     }\n   bool operator<= (const gcov_type other) const\n     {\n+      gcc_checking_assert (ipa_p ());\n       gcc_checking_assert (other >= 0);\n       return initialized_p () && m_val <= (uint64_t) other;\n     }\n   bool operator>= (const gcov_type other) const\n     {\n+      gcc_checking_assert (ipa_p ());\n       gcc_checking_assert (other >= 0);\n       return initialized_p () && m_val >= (uint64_t) other;\n     }\n+  /* Return true when value is not zero and can be used for scaling. \n+     This is different from *this > 0 because that requires counter to\n+     be IPA.  */\n+  bool nonzero_p () const\n+    {\n+      return initialized_p () && m_val != 0;\n+    }\n+\n+  /* Make counter forcingly nonzero.  */\n+  profile_count force_nonzero () const\n+    {\n+      if (!initialized_p ())\n+\treturn *this;\n+      profile_count ret = *this;\n+      if (ret.m_val == 0)\n+\tret.m_val = 1;\n+      return ret;\n+    }\n+\n+  profile_count max (profile_count other) const\n+    {\n+      if (!initialized_p ())\n+\treturn other;\n+      if (!other.initialized_p ())\n+\treturn *this;\n+      if (*this == profile_count::zero ())\n+\treturn other;\n+      if (other == profile_count::zero ())\n+\treturn *this;\n+      gcc_checking_assert (compatible_p (other));\n+      if (m_val < other.m_val || (m_val == other.m_val\n+\t\t\t\t  && m_quality < other.m_quality))\n+\treturn other;\n+      return *this;\n+    }\n \n   /* PROB is a probability in scale 0...REG_BR_PROB_BASE.  Scale counter\n      accordingly.  */\n@@ -814,13 +943,13 @@ public:\n     }\n   profile_count apply_scale (profile_count num, profile_count den) const\n     {\n-      if (m_val == 0)\n+      if (*this == profile_count::zero ())\n \treturn *this;\n-      if (num.m_val == 0)\n+      if (num == profile_count::zero ())\n \treturn num;\n       if (!initialized_p () || !num.initialized_p () || !den.initialized_p ())\n \treturn profile_count::uninitialized ();\n-      gcc_checking_assert (den > 0);\n+      gcc_checking_assert (den.m_val);\n       if (num == den)\n \treturn *this;\n \n@@ -828,7 +957,30 @@ public:\n       uint64_t val;\n       safe_scale_64bit (m_val, num.m_val, den.m_val, &val);\n       ret.m_val = MIN (val, max_count);\n-      ret.m_quality = MIN (m_quality, profile_adjusted);\n+      ret.m_quality = MIN (MIN (MIN (m_quality, profile_adjusted),\n+\t\t\t        num.m_quality), den.m_quality);\n+      if (num.ipa_p () && !ret.ipa_p ())\n+\tret.m_quality = MIN (num.m_quality, profile_guessed);\n+      return ret;\n+    }\n+\n+  /* Return THIS with quality dropped to GUESSED_LOCAL.  */\n+  profile_count guessed_local () const\n+    {\n+      profile_count ret = *this;\n+      if (!initialized_p ())\n+\treturn *this;\n+      ret.m_quality = profile_guessed_local;\n+      return ret;\n+    }\n+\n+  /* We know that profile is globally0 but keep local profile if present.  */\n+  profile_count global0 () const\n+    {\n+      profile_count ret = *this;\n+      if (!initialized_p ())\n+\treturn *this;\n+      ret.m_quality = profile_guessed_global0;\n       return ret;\n     }\n \n@@ -836,10 +988,21 @@ public:\n   profile_count guessed () const\n     {\n       profile_count ret = *this;\n-      ret.m_quality = profile_guessed;\n+      ret.m_quality = MIN (ret.m_quality, profile_guessed);\n       return ret;\n     }\n \n+  /* Return variant of profile counte which is always safe to compare\n+     acorss functions.  */\n+  profile_count ipa () const\n+    {\n+      if (m_quality > profile_guessed_global0)\n+\treturn *this;\n+      if (m_quality == profile_guessed_global0)\n+\treturn profile_count::zero ();\n+      return profile_count::uninitialized ();\n+    }\n+\n   /* Return THIS with quality dropped to AFDO.  */\n   profile_count afdo () const\n     {\n@@ -852,21 +1015,26 @@ public:\n      OVERALL.  */\n   profile_probability probability_in (const profile_count overall) const\n     {\n-      if (!m_val)\n+      if (*this == profile_count::zero ())\n \treturn profile_probability::never ();\n       if (!initialized_p () || !overall.initialized_p ()\n \t  || !overall.m_val)\n \treturn profile_probability::uninitialized ();\n       profile_probability ret;\n-      if (overall < m_val)\n+      gcc_checking_assert (compatible_p (overall));\n+\n+      if (overall.m_val < m_val)\n \tret.m_val = profile_probability::max_probability;\n       else\n \tret.m_val = RDIV (m_val * profile_probability::max_probability,\n \t\t\t  overall.m_val);\n-      ret.m_quality = MIN (m_quality, overall.m_quality);\n+      ret.m_quality = MAX (MIN (m_quality, overall.m_quality), profile_guessed);\n       return ret;\n     }\n \n+  int to_frequency (struct function *fun) const;\n+  int to_cgraph_frequency (profile_count entry_bb_count) const;\n+\n   /* Output THIS to F.  */\n   void dump (FILE *f) const;\n \nIndex: profile.c\n===================================================================\n--- profile.c\t(revision 254348)\n+++ profile.c\t(working copy)\n@@ -476,38 +476,6 @@ read_profile_edge_counts (gcov_type *exe\n     return num_edges;\n }\n \n-#define OVERLAP_BASE 10000\n-\n-/* Compare the static estimated profile to the actual profile, and\n-   return the \"degree of overlap\" measure between them.\n-\n-   Degree of overlap is a number between 0 and OVERLAP_BASE. It is\n-   the sum of each basic block's minimum relative weights between\n-   two profiles. And overlap of OVERLAP_BASE means two profiles are\n-   identical.  */\n-\n-static int\n-compute_frequency_overlap (void)\n-{\n-  gcov_type count_total = 0, freq_total = 0;\n-  int overlap = 0;\n-  basic_block bb;\n-\n-  FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (cfun), NULL, next_bb)\n-    {\n-      count_total += bb_gcov_count (bb);\n-      freq_total += bb->frequency;\n-    }\n-\n-  if (count_total == 0 || freq_total == 0)\n-    return 0;\n-\n-  FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (cfun), NULL, next_bb)\n-    overlap += MIN (bb_gcov_count (bb) * OVERLAP_BASE / count_total,\n-\t\t    bb->frequency * OVERLAP_BASE / freq_total);\n-\n-  return overlap;\n-}\n \n /* Compute the branch probabilities for the various branches.\n    Annotate them accordingly.  \n@@ -676,14 +644,6 @@ compute_branch_probabilities (unsigned c\n \t    }\n \t}\n     }\n-  if (dump_file)\n-    {\n-      int overlap = compute_frequency_overlap ();\n-      gimple_dump_cfg (dump_file, dump_flags);\n-      fprintf (dump_file, \"Static profile overlap: %d.%d%%\\n\",\n-\t       overlap / (OVERLAP_BASE / 100),\n-\t       overlap % (OVERLAP_BASE / 100));\n-    }\n \n   total_num_passes += passes;\n   if (dump_file)\n@@ -829,10 +789,18 @@ compute_branch_probabilities (unsigned c\n \t}\n     }\n \n-  FOR_ALL_BB_FN (bb, cfun)\n-    {\n+  /* If we have real data, use them!  */\n+  if (bb_gcov_count (ENTRY_BLOCK_PTR_FOR_FN (cfun))\n+      || !flag_guess_branch_prob)\n+    FOR_ALL_BB_FN (bb, cfun)\n       bb->count = profile_count::from_gcov_type (bb_gcov_count (bb));\n-    }\n+  /* If function was not trained, preserve local estimates including statically\n+     determined zero counts.  */\n+  else\n+    FOR_ALL_BB_FN (bb, cfun)\n+      if (!(bb->count == profile_count::zero ()))\n+        bb->count = bb->count.global0 ();\n+\n   bb_gcov_counts.release ();\n   delete edge_gcov_counts;\n   edge_gcov_counts = NULL;\nIndex: regs.h\n===================================================================\n--- regs.h\t(revision 254348)\n+++ regs.h\t(working copy)\n@@ -130,8 +130,10 @@ extern size_t reg_info_p_size;\n    frequency.  */\n #define REG_FREQ_FROM_BB(bb) (optimize_function_for_size_p (cfun)\t      \\\n \t\t\t      ? REG_FREQ_MAX\t\t\t\t      \\\n-\t\t\t      : ((bb)->frequency * REG_FREQ_MAX / BB_FREQ_MAX)\\\n-\t\t\t      ? ((bb)->frequency * REG_FREQ_MAX / BB_FREQ_MAX)\\\n+\t\t\t      : ((bb)->count.to_frequency (cfun)\t      \\\n+\t\t\t\t* REG_FREQ_MAX / BB_FREQ_MAX)\t\t      \\\n+\t\t\t      ? ((bb)->count.to_frequency (cfun)\t      \\\n+\t\t\t\t * REG_FREQ_MAX / BB_FREQ_MAX)\t\t      \\\n \t\t\t      : 1)\n \n /* Indexed by N, gives number of insns in which register N dies.\nIndex: sched-ebb.c\n===================================================================\n--- sched-ebb.c\t(revision 254348)\n+++ sched-ebb.c\t(working copy)\n@@ -231,11 +231,9 @@ rank (rtx_insn *insn1, rtx_insn *insn2)\n   basic_block bb1 = BLOCK_FOR_INSN (insn1);\n   basic_block bb2 = BLOCK_FOR_INSN (insn2);\n \n-  if (bb1->count > bb2->count\n-      || bb1->frequency > bb2->frequency)\n+  if (bb1->count > bb2->count)\n     return -1;\n-  if (bb1->count < bb2->count\n-      || bb1->frequency < bb2->frequency)\n+  if (bb1->count < bb2->count)\n     return 1;\n   return 0;\n }\nIndex: shrink-wrap.c\n===================================================================\n--- shrink-wrap.c\t(revision 254348)\n+++ shrink-wrap.c\t(working copy)\n@@ -561,7 +561,7 @@ handle_simple_exit (edge e)\n       BB_END (old_bb) = end;\n \n       redirect_edge_succ (e, new_bb);\n-      new_bb->frequency = EDGE_FREQUENCY (e);\n+      new_bb->count = e->count ();\n       e->flags |= EDGE_FALLTHRU;\n \n       e = make_single_succ_edge (new_bb, EXIT_BLOCK_PTR_FOR_FN (cfun), 0);\n@@ -887,7 +887,7 @@ try_shrink_wrapping (edge *entry_edge, r\n     if (!dominated_by_p (CDI_DOMINATORS, e->src, pro))\n       {\n \tnum += EDGE_FREQUENCY (e);\n-\tden += e->src->frequency;\n+\tden += e->src->count.to_frequency (cfun);\n       }\n \n   if (den == 0)\n@@ -920,8 +920,6 @@ try_shrink_wrapping (edge *entry_edge, r\n \tif (dump_file)\n \t  fprintf (dump_file, \"Duplicated %d to %d\\n\", bb->index, dup->index);\n \n-\tbb->frequency = RDIV (num * bb->frequency, den);\n-\tdup->frequency -= bb->frequency;\n \tbb->count = bb->count.apply_scale (num, den);\n \tdup->count -= bb->count;\n       }\n@@ -995,8 +993,7 @@ try_shrink_wrapping (edge *entry_edge, r\n \t  continue;\n \t}\n \n-      new_bb->count += e->src->count.apply_probability (e->probability);\n-      new_bb->frequency += EDGE_FREQUENCY (e);\n+      new_bb->count += e->count ();\n \n       redirect_edge_and_branch_force (e, new_bb);\n       if (dump_file)\n@@ -1181,7 +1178,7 @@ place_prologue_for_one_component (unsign\n \t     work: this does not always add up to the block frequency at\n \t     all, and even if it does, rounding error makes for bad\n \t     decisions.  */\n-\t  SW (bb)->own_cost = bb->frequency;\n+\t  SW (bb)->own_cost = bb->count.to_frequency (cfun);\n \n \t  edge e;\n \t  edge_iterator ei;\nIndex: testsuite/gcc.dg/no-strict-overflow-3.c\n===================================================================\n--- testsuite/gcc.dg/no-strict-overflow-3.c\t(revision 254348)\n+++ testsuite/gcc.dg/no-strict-overflow-3.c\t(working copy)\n@@ -9,7 +9,7 @@\n int\n foo (int i, int j)\n {\n-  return i + 100 < j + 1000;\n+  return i + 100 < j + 1234;\n }\n \n-/* { dg-final { scan-tree-dump \"1000\" \"optimized\" } } */\n+/* { dg-final { scan-tree-dump \"1234\" \"optimized\" } } */\nIndex: testsuite/gcc.dg/strict-overflow-3.c\n===================================================================\n--- testsuite/gcc.dg/strict-overflow-3.c\t(revision 254348)\n+++ testsuite/gcc.dg/strict-overflow-3.c\t(working copy)\n@@ -9,7 +9,7 @@\n int\n foo (int i, int j)\n {\n-  return i + 100 < j + 1000;\n+  return i + 100 < j + 1234;\n }\n \n-/* { dg-final { scan-tree-dump-not \"1000\" \"optimized\" } } */\n+/* { dg-final { scan-tree-dump-not \"1234\" \"optimized\" } } */\nIndex: testsuite/gcc.dg/tree-ssa/builtin-sprintf-2.c\n===================================================================\n--- testsuite/gcc.dg/tree-ssa/builtin-sprintf-2.c\t(revision 254348)\n+++ testsuite/gcc.dg/tree-ssa/builtin-sprintf-2.c\t(working copy)\n@@ -290,7 +290,7 @@ RNG (0,  6,   8, \"%s%ls\", \"1\", L\"2\");\n \n /*  Only conditional calls to must_not_eliminate must be made (with\n     any probability):\n-    { dg-final { scan-tree-dump-times \"> \\\\\\[\\[0-9.\\]+%\\\\\\] \\\\\\[count: \\[0-9INV\\]*\\\\\\]:\\n *must_not_eliminate\" 127 \"optimized\" { target { ilp32 || lp64 } } } }\n-    { dg-final { scan-tree-dump-times \"> \\\\\\[\\[0-9.\\]+%\\\\\\] \\\\\\[count: \\[0-9INV\\]*\\\\\\]:\\n *must_not_eliminate\" 96 \"optimized\" { target { { ! ilp32 } && { ! lp64 } } } } }\n+    { dg-final { scan-tree-dump-times \"> \\\\\\[local count: \\[0-9INV\\]*\\\\\\]:\\n *must_not_eliminate\" 127 \"optimized\" { target { ilp32 || lp64 } } } }\n+    { dg-final { scan-tree-dump-times \"> \\\\\\[local count: \\[0-9INV\\]*\\\\\\]:\\n *must_not_eliminate\" 96 \"optimized\" { target { { ! ilp32 } && { ! lp64 } } } } }\n     No unconditional calls to abort should be made:\n     { dg-final { scan-tree-dump-not \";\\n *must_not_eliminate\" \"optimized\" } } */\nIndex: testsuite/gcc.dg/tree-ssa/dump-2.c\n===================================================================\n--- testsuite/gcc.dg/tree-ssa/dump-2.c\t(revision 254348)\n+++ testsuite/gcc.dg/tree-ssa/dump-2.c\t(working copy)\n@@ -6,4 +6,4 @@ int f(void)\n   return 0;\n }\n \n-/* { dg-final { scan-tree-dump \"<bb \\[0-9\\]> \\\\\\[100\\\\\\.00%\\\\\\] \\\\\\[count: INV\\\\\\]:\" \"optimized\" } } */\n+/* { dg-final { scan-tree-dump \"<bb \\[0-9\\]> \\\\\\[local count: 10000\\\\\\]:\" \"optimized\" } } */\nIndex: testsuite/gcc.dg/tree-ssa/ifc-10.c\n===================================================================\n--- testsuite/gcc.dg/tree-ssa/ifc-10.c\t(revision 254348)\n+++ testsuite/gcc.dg/tree-ssa/ifc-10.c\t(working copy)\n@@ -26,5 +26,5 @@ int foo (int x, int n)\n    which is folded by vectorizer.  Both outgoing edges must have probability\n    100% so the resulting profile match after folding.  */\n /* { dg-final { scan-tree-dump-times \"Invalid sum of outgoing probabilities 200.0\" 1 \"ifcvt\" } } */\n-/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming frequencies\" 1 \"ifcvt\" } } */\n+/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming counts\" 1 \"ifcvt\" } } */\n \nIndex: testsuite/gcc.dg/tree-ssa/ifc-11.c\n===================================================================\n--- testsuite/gcc.dg/tree-ssa/ifc-11.c\t(revision 254348)\n+++ testsuite/gcc.dg/tree-ssa/ifc-11.c\t(working copy)\n@@ -24,5 +24,4 @@ int foo (float *x)\n    which is folded by vectorizer.  Both outgoing edges must have probability\n    100% so the resulting profile match after folding.  */\n /* { dg-final { scan-tree-dump-times \"Invalid sum of outgoing probabilities 200.0\" 1 \"ifcvt\" } } */\n-/* Sum is wrong here, but not enough for error to be reported.  */\n-/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming frequencies\" 0 \"ifcvt\" } } */\n+/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming counts\" 1 \"ifcvt\" } } */\nIndex: testsuite/gcc.dg/tree-ssa/ifc-12.c\n===================================================================\n--- testsuite/gcc.dg/tree-ssa/ifc-12.c\t(revision 254348)\n+++ testsuite/gcc.dg/tree-ssa/ifc-12.c\t(working copy)\n@@ -29,6 +29,5 @@ int foo (int x)\n    which is folded by vectorizer.  Both outgoing edges must have probability\n    100% so the resulting profile match after folding.  */\n /* { dg-final { scan-tree-dump-times \"Invalid sum of outgoing probabilities 200.0\" 1 \"ifcvt\" } } */\n-/* Sum is wrong here, but not enough for error to be reported.  */\n-/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming frequencies\" 0 \"ifcvt\" } } */\n+/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming counts\" 1 \"ifcvt\" } } */\n \nIndex: testsuite/gcc.dg/tree-ssa/ifc-20040816-1.c\n===================================================================\n--- testsuite/gcc.dg/tree-ssa/ifc-20040816-1.c\t(revision 254348)\n+++ testsuite/gcc.dg/tree-ssa/ifc-20040816-1.c\t(working copy)\n@@ -39,4 +39,4 @@ int main1 ()\n    which is folded by vectorizer.  Both outgoing edges must have probability\n    100% so the resulting profile match after folding.  */\n /* { dg-final { scan-tree-dump-times \"Invalid sum of outgoing probabilities 200.0\" 1 \"ifcvt\" } } */\n-/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming frequencies\" 1 \"ifcvt\" } } */\n+/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming counts\" 1 \"ifcvt\" } } */\nIndex: testsuite/gcc.dg/tree-ssa/ifc-20040816-2.c\n===================================================================\n--- testsuite/gcc.dg/tree-ssa/ifc-20040816-2.c\t(revision 254348)\n+++ testsuite/gcc.dg/tree-ssa/ifc-20040816-2.c\t(working copy)\n@@ -43,5 +43,4 @@ void foo(const int * __restrict__ zr_in,\n    which is folded by vectorizer.  Both outgoing edges must have probability\n    100% so the resulting profile match after folding.  */\n /* { dg-final { scan-tree-dump-times \"Invalid sum of outgoing probabilities 200.0\" 1 \"ifcvt\" } } */\n-/* Sum is wrong here, but not enough for error to be reported.  */\n-/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming frequencies\" 0 \"ifcvt\" } } */\n+/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming counts\" 1 \"ifcvt\" } } */\nIndex: testsuite/gcc.dg/tree-ssa/ifc-5.c\n===================================================================\n--- testsuite/gcc.dg/tree-ssa/ifc-5.c\t(revision 254348)\n+++ testsuite/gcc.dg/tree-ssa/ifc-5.c\t(working copy)\n@@ -27,4 +27,4 @@ dct_unquantize_h263_inter_c (short *bloc\n    which is folded by vectorizer.  Both outgoing edges must have probability\n    100% so the resulting profile match after folding.  */\n /* { dg-final { scan-tree-dump-times \"Invalid sum of outgoing probabilities 200.0\" 1 \"ifcvt\" } } */\n-/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming frequencies\" 1 \"ifcvt\" } } */\n+/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming counts\" 1 \"ifcvt\" } } */\nIndex: testsuite/gcc.dg/tree-ssa/ifc-8.c\n===================================================================\n--- testsuite/gcc.dg/tree-ssa/ifc-8.c\t(revision 254348)\n+++ testsuite/gcc.dg/tree-ssa/ifc-8.c\t(working copy)\n@@ -22,5 +22,4 @@ void test ()\n    which is folded by vectorizer.  Both outgoing edges must have probability\n    100% so the resulting profile match after folding.  */\n /* { dg-final { scan-tree-dump-times \"Invalid sum of outgoing probabilities 200.0\" 1 \"ifcvt\" } } */\n-/* Sum is wrong here, but not enough for error to be reported.  */\n-/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming frequencies\" 0 \"ifcvt\" } } */\n+/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming counts\" 1 \"ifcvt\" } } */\nIndex: testsuite/gcc.dg/tree-ssa/ifc-9.c\n===================================================================\n--- testsuite/gcc.dg/tree-ssa/ifc-9.c\t(revision 254348)\n+++ testsuite/gcc.dg/tree-ssa/ifc-9.c\t(working copy)\n@@ -26,4 +26,4 @@ int foo (int x, int n)\n    which is folded by vectorizer.  Both outgoing edges must have probability\n    100% so the resulting profile match after folding.  */\n /* { dg-final { scan-tree-dump-times \"Invalid sum of outgoing probabilities 200.0\" 1 \"ifcvt\" } } */\n-/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming frequencies\" 1 \"ifcvt\" } } */\n+/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming counts\" 1 \"ifcvt\" } } */\nIndex: testsuite/gcc.dg/tree-ssa/ifc-cd.c\n===================================================================\n--- testsuite/gcc.dg/tree-ssa/ifc-cd.c\t(revision 254348)\n+++ testsuite/gcc.dg/tree-ssa/ifc-cd.c\t(working copy)\n@@ -32,5 +32,4 @@ void foo (int *x1, int *x2, int *x3, int\n    which is folded by vectorizer.  Both outgoing edges must have probability\n    100% so the resulting profile match after folding.  */\n /* { dg-final { scan-tree-dump-times \"Invalid sum of outgoing probabilities 200.0\" 1 \"ifcvt\" } } */\n-/* Sum is wrong here, but not enough for error to be reported.  */\n-/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming frequencies\" 0 \"ifcvt\" } } */\n+/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming counts\" 1 \"ifcvt\" } } */\nIndex: testsuite/gcc.dg/tree-ssa/ifc-pr56541.c\n===================================================================\n--- testsuite/gcc.dg/tree-ssa/ifc-pr56541.c\t(revision 254348)\n+++ testsuite/gcc.dg/tree-ssa/ifc-pr56541.c\t(working copy)\n@@ -29,5 +29,4 @@ void foo()\n    which is folded by vectorizer.  Both outgoing edges must have probability\n    100% so the resulting profile match after folding.  */\n /* { dg-final { scan-tree-dump-times \"Invalid sum of outgoing probabilities 200.0\" 1 \"ifcvt\" } } */\n-/* Sum is wrong here, but not enough for error to be reported.  */\n-/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming frequencies\" 0 \"ifcvt\" } } */\n+/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming counts\" 1 \"ifcvt\" } } */\nIndex: testsuite/gcc.dg/tree-ssa/ifc-pr68583.c\n===================================================================\n--- testsuite/gcc.dg/tree-ssa/ifc-pr68583.c\t(revision 254348)\n+++ testsuite/gcc.dg/tree-ssa/ifc-pr68583.c\t(working copy)\n@@ -26,5 +26,5 @@ void foo (long *a)\n    which is folded by vectorizer.  Both outgoing edges must have probability\n    100% so the resulting profile match after folding.  */\n /* { dg-final { scan-tree-dump-times \"Invalid sum of outgoing probabilities 200.0\" 1 \"ifcvt\" } } */\n-/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming frequencies\" 1 \"ifcvt\" } } */\n+/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming counts\" 1 \"ifcvt\" } } */\n \nIndex: testsuite/gcc.dg/tree-ssa/ifc-pr69489-1.c\n===================================================================\n--- testsuite/gcc.dg/tree-ssa/ifc-pr69489-1.c\t(revision 254348)\n+++ testsuite/gcc.dg/tree-ssa/ifc-pr69489-1.c\t(working copy)\n@@ -20,5 +20,4 @@ void foo (int a[], int b[])\n    which is folded by vectorizer.  Both outgoing edges must have probability\n    100% so the resulting profile match after folding.  */\n /* { dg-final { scan-tree-dump-times \"Invalid sum of outgoing probabilities 200.0\" 1 \"ifcvt\" } } */\n-/* Sum is wrong here, but not enough for error to be reported.  */\n-/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming frequencies\" 0 \"ifcvt\" } } */\n+/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming counts\" 1 \"ifcvt\" } } */\nIndex: testsuite/gcc.dg/tree-ssa/ifc-pr69489-2.c\n===================================================================\n--- testsuite/gcc.dg/tree-ssa/ifc-pr69489-2.c\t(revision 254348)\n+++ testsuite/gcc.dg/tree-ssa/ifc-pr69489-2.c\t(working copy)\n@@ -21,4 +21,4 @@ foo (const char *u, const char *v, long\n    which is folded by vectorizer.  Both outgoing edges must have probability\n    100% so the resulting profile match after folding.  */\n /* { dg-final { scan-tree-dump-times \"Invalid sum of outgoing probabilities 200.0\" 1 \"ifcvt\" } } */\n-/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming frequencies\" 1 \"ifcvt\" } } */\n+/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming counts\" 1 \"ifcvt\" } } */\nIndex: testsuite/gcc.target/i386/pr61403.c\n===================================================================\n--- testsuite/gcc.target/i386/pr61403.c\t(revision 254348)\n+++ testsuite/gcc.target/i386/pr61403.c\t(working copy)\n@@ -23,4 +23,4 @@ norm (struct XYZ *in, struct XYZ *out, i\n     }\n }\n \n-/* { dg-final { scan-assembler \"blend\" } } */\n+/* { dg-final { scan-assembler \"rsqrtps\" } } */\nIndex: tracer.c\n===================================================================\n--- tracer.c\t(revision 254348)\n+++ tracer.c\t(working copy)\n@@ -179,7 +179,7 @@ find_best_predecessor (basic_block bb)\n   if (!best || ignore_bb_p (best->src))\n     return NULL;\n   if (EDGE_FREQUENCY (best) * REG_BR_PROB_BASE\n-      < bb->frequency * branch_ratio_cutoff)\n+      < bb->count.to_frequency (cfun) * branch_ratio_cutoff)\n     return NULL;\n   return best;\n }\n@@ -194,7 +194,7 @@ find_trace (basic_block bb, basic_block\n   edge e;\n \n   if (dump_file)\n-    fprintf (dump_file, \"Trace seed %i [%i]\", bb->index, bb->frequency);\n+    fprintf (dump_file, \"Trace seed %i [%i]\", bb->index, bb->count.to_frequency (cfun));\n \n   while ((e = find_best_predecessor (bb)) != NULL)\n     {\n@@ -203,11 +203,11 @@ find_trace (basic_block bb, basic_block\n \t  || find_best_successor (bb2) != e)\n \tbreak;\n       if (dump_file)\n-\tfprintf (dump_file, \",%i [%i]\", bb->index, bb->frequency);\n+\tfprintf (dump_file, \",%i [%i]\", bb->index, bb->count.to_frequency (cfun));\n       bb = bb2;\n     }\n   if (dump_file)\n-    fprintf (dump_file, \" forward %i [%i]\", bb->index, bb->frequency);\n+    fprintf (dump_file, \" forward %i [%i]\", bb->index, bb->count.to_frequency (cfun));\n   trace[i++] = bb;\n \n   /* Follow the trace in forward direction.  */\n@@ -218,7 +218,7 @@ find_trace (basic_block bb, basic_block\n \t  || find_best_predecessor (bb) != e)\n \tbreak;\n       if (dump_file)\n-\tfprintf (dump_file, \",%i [%i]\", bb->index, bb->frequency);\n+\tfprintf (dump_file, \",%i [%i]\", bb->index, bb->count.to_frequency (cfun));\n       trace[i++] = bb;\n     }\n   if (dump_file)\n@@ -282,11 +282,11 @@ tail_duplicate (void)\n     {\n       int n = count_insns (bb);\n       if (!ignore_bb_p (bb))\n-\tblocks[bb->index] = heap.insert (-bb->frequency, bb);\n+\tblocks[bb->index] = heap.insert (-bb->count.to_frequency (cfun), bb);\n \n       counts [bb->index] = n;\n       ninsns += n;\n-      weighted_insns += n * bb->frequency;\n+      weighted_insns += n * bb->count.to_frequency (cfun);\n     }\n \n   if (profile_info && profile_status_for_fn (cfun) == PROFILE_READ)\n@@ -314,7 +314,7 @@ tail_duplicate (void)\n       n = find_trace (bb, trace);\n \n       bb = trace[0];\n-      traced_insns += bb->frequency * counts [bb->index];\n+      traced_insns += bb->count.to_frequency (cfun) * counts [bb->index];\n       if (blocks[bb->index])\n \t{\n \t  heap.delete_node (blocks[bb->index]);\n@@ -330,7 +330,7 @@ tail_duplicate (void)\n \t      heap.delete_node (blocks[bb2->index]);\n \t      blocks[bb2->index] = NULL;\n \t    }\n-\t  traced_insns += bb2->frequency * counts [bb2->index];\n+\t  traced_insns += bb2->count.to_frequency (cfun) * counts [bb2->index];\n \t  if (EDGE_COUNT (bb2->preds) > 1\n \t      && can_duplicate_block_p (bb2)\n \t      /* We have the tendency to duplicate the loop header\n@@ -345,11 +345,11 @@ tail_duplicate (void)\n \t      /* Reconsider the original copy of block we've duplicated.\n \t         Removing the most common predecessor may make it to be\n \t         head.  */\n-\t      blocks[bb2->index] = heap.insert (-bb2->frequency, bb2);\n+\t      blocks[bb2->index] = heap.insert (-bb2->count.to_frequency (cfun), bb2);\n \n \t      if (dump_file)\n \t\tfprintf (dump_file, \"Duplicated %i as %i [%i]\\n\",\n-\t\t\t bb2->index, copy->index, copy->frequency);\n+\t\t\t bb2->index, copy->index, copy->count.to_frequency (cfun));\n \n \t      bb2 = copy;\n \t      changed = true;\nIndex: trans-mem.c\n===================================================================\n--- trans-mem.c\t(revision 254348)\n+++ trans-mem.c\t(working copy)\n@@ -2932,7 +2932,6 @@ expand_transaction (struct tm_region *re\n       edge ef = make_edge (test_bb, join_bb, EDGE_FALSE_VALUE);\n       redirect_edge_pred (fallthru_edge, join_bb);\n \n-      join_bb->frequency = test_bb->frequency = transaction_bb->frequency;\n       join_bb->count = test_bb->count = transaction_bb->count;\n \n       ei->probability = profile_probability::always ();\n@@ -2940,7 +2939,6 @@ expand_transaction (struct tm_region *re\n       ef->probability = profile_probability::unlikely ();\n \n       code_bb->count = et->count ();\n-      code_bb->frequency = EDGE_FREQUENCY (et);\n \n       transaction_bb = join_bb;\n     }\n@@ -2964,7 +2962,6 @@ expand_transaction (struct tm_region *re\n       gsi_insert_after (&gsi, stmt, GSI_CONTINUE_LINKING);\n \n       edge ei = make_edge (transaction_bb, test_bb, EDGE_FALLTHRU);\n-      test_bb->frequency = transaction_bb->frequency;\n       test_bb->count = transaction_bb->count;\n       ei->probability = profile_probability::always ();\n \n@@ -3006,7 +3003,6 @@ expand_transaction (struct tm_region *re\n       edge e = make_edge (transaction_bb, test_bb, fallthru_edge->flags);\n       e->probability = fallthru_edge->probability;\n       test_bb->count = fallthru_edge->count ();\n-      test_bb->frequency = EDGE_FREQUENCY (e);\n \n       // Now update the edges to the inst/uninist implementations.\n       // For now assume that the paths are equally likely.  When using HTM,\nIndex: tree-call-cdce.c\n===================================================================\n--- tree-call-cdce.c\t(revision 254348)\n+++ tree-call-cdce.c\t(working copy)\n@@ -906,7 +906,6 @@ shrink_wrap_one_built_in_call_with_conds\n      Here we take the second approach because it's slightly simpler\n      and because it's easy to see that it doesn't lose profile counts.  */\n   bi_call_bb->count = profile_count::zero ();\n-  bi_call_bb->frequency = 0;\n   while (!edges.is_empty ())\n     {\n       edge_pair e = edges.pop ();\n@@ -919,16 +918,10 @@ shrink_wrap_one_built_in_call_with_conds\n       nocall_edge->probability = profile_probability::always ()\n \t\t\t\t - call_edge->probability;\n \n-      unsigned int call_frequency\n-\t = call_edge->probability.apply (src_bb->frequency);\n-\n       bi_call_bb->count += call_edge->count ();\n-      bi_call_bb->frequency += call_frequency;\n \n       if (nocall_edge->dest != join_tgt_bb)\n-\t{\n-\t  nocall_edge->dest->frequency = src_bb->frequency - call_frequency;\n-\t}\n+\tnocall_edge->dest->count = src_bb->count - bi_call_bb->count;\n     }\n \n   if (dom_info_available_p (CDI_DOMINATORS))\nIndex: tree-cfg.c\n===================================================================\n--- tree-cfg.c\t(revision 254348)\n+++ tree-cfg.c\t(working copy)\n@@ -1071,7 +1071,6 @@ gimple_find_sub_bbs (gimple_seq seq, gim\n       tree_guess_outgoing_edge_probabilities (bb);\n       if (all || profile_status_for_fn (cfun) == PROFILE_READ)\n         bb->count = cnt;\n-      bb->frequency = freq;\n \n       bb = bb->next_bb;\n     }\n@@ -2081,7 +2080,6 @@ gimple_merge_blocks (basic_block a, basi\n   if (a->loop_father == b->loop_father)\n     {\n       a->count = a->count.merge (b->count);\n-      a->frequency = MAX (a->frequency, b->frequency);\n     }\n \n   /* Merge the sequences.  */\n@@ -2840,7 +2838,6 @@ gimple_split_edge (edge edge_in)\n   after_bb = split_edge_bb_loc (edge_in);\n \n   new_bb = create_empty_bb (after_bb);\n-  new_bb->frequency = EDGE_FREQUENCY (edge_in);\n   new_bb->count = edge_in->count ();\n \n   e = redirect_edge_and_branch (edge_in, new_bb);\n@@ -6306,9 +6303,8 @@ gimple_duplicate_sese_region (edge entry\n   bool free_region_copy = false, copying_header = false;\n   struct loop *loop = entry->dest->loop_father;\n   edge exit_copy;\n-  vec<basic_block> doms;\n+  vec<basic_block> doms = vNULL;\n   edge redirected;\n-  int total_freq = 0, entry_freq = 0;\n   profile_count total_count = profile_count::uninitialized ();\n   profile_count entry_count = profile_count::uninitialized ();\n \n@@ -6376,21 +6372,10 @@ gimple_duplicate_sese_region (edge entry\n       if (entry_count > total_count)\n \tentry_count = total_count;\n     }\n-  if (!(total_count > 0) || !(entry_count > 0))\n-    {\n-      total_freq = entry->dest->frequency;\n-      entry_freq = EDGE_FREQUENCY (entry);\n-      /* Fix up corner cases, to avoid division by zero or creation of negative\n-\t frequencies.  */\n-      if (total_freq == 0)\n-\ttotal_freq = 1;\n-      else if (entry_freq > total_freq)\n-\tentry_freq = total_freq;\n-    }\n \n   copy_bbs (region, n_region, region_copy, &exit, 1, &exit_copy, loop,\n \t    split_edge_bb_loc (entry), update_dominance);\n-  if (total_count > 0 && entry_count > 0)\n+  if (total_count.initialized_p () && entry_count.initialized_p ())\n     {\n       scale_bbs_frequencies_profile_count (region, n_region,\n \t\t\t\t           total_count - entry_count,\n@@ -6398,12 +6383,6 @@ gimple_duplicate_sese_region (edge entry\n       scale_bbs_frequencies_profile_count (region_copy, n_region, entry_count,\n \t\t\t\t           total_count);\n     }\n-  else\n-    {\n-      scale_bbs_frequencies_int (region, n_region, total_freq - entry_freq,\n-\t\t\t\t total_freq);\n-      scale_bbs_frequencies_int (region_copy, n_region, entry_freq, total_freq);\n-    }\n \n   if (copying_header)\n     {\n@@ -6492,7 +6471,6 @@ gimple_duplicate_sese_tail (edge entry,\n   struct loop *orig_loop = entry->dest->loop_father;\n   basic_block switch_bb, entry_bb, nentry_bb;\n   vec<basic_block> doms;\n-  int total_freq = 0, exit_freq = 0;\n   profile_count total_count = profile_count::uninitialized (),\n \t\texit_count = profile_count::uninitialized ();\n   edge exits[2], nexits[2], e;\n@@ -6537,30 +6515,16 @@ gimple_duplicate_sese_tail (edge entry,\n      inside.  */\n   doms = get_dominated_by_region (CDI_DOMINATORS, region, n_region);\n \n-  if (exit->src->count > 0)\n-    {\n-      total_count = exit->src->count;\n-      exit_count = exit->count ();\n-      /* Fix up corner cases, to avoid division by zero or creation of negative\n-\t frequencies.  */\n-      if (exit_count > total_count)\n-\texit_count = total_count;\n-    }\n-  else\n-    {\n-      total_freq = exit->src->frequency;\n-      exit_freq = EDGE_FREQUENCY (exit);\n-      /* Fix up corner cases, to avoid division by zero or creation of negative\n-\t frequencies.  */\n-      if (total_freq == 0)\n-\ttotal_freq = 1;\n-      if (exit_freq > total_freq)\n-\texit_freq = total_freq;\n-    }\n+  total_count = exit->src->count;\n+  exit_count = exit->count ();\n+  /* Fix up corner cases, to avoid division by zero or creation of negative\n+     frequencies.  */\n+  if (exit_count > total_count)\n+    exit_count = total_count;\n \n   copy_bbs (region, n_region, region_copy, exits, 2, nexits, orig_loop,\n \t    split_edge_bb_loc (exit), true);\n-  if (total_count.initialized_p ())\n+  if (total_count.initialized_p () && exit_count.initialized_p ())\n     {\n       scale_bbs_frequencies_profile_count (region, n_region,\n \t\t\t\t           total_count - exit_count,\n@@ -6568,12 +6532,6 @@ gimple_duplicate_sese_tail (edge entry,\n       scale_bbs_frequencies_profile_count (region_copy, n_region, exit_count,\n \t\t\t\t           total_count);\n     }\n-  else\n-    {\n-      scale_bbs_frequencies_int (region, n_region, total_freq - exit_freq,\n-\t\t\t\t total_freq);\n-      scale_bbs_frequencies_int (region_copy, n_region, exit_freq, total_freq);\n-    }\n \n   /* Create the switch block, and put the exit condition to it.  */\n   entry_bb = entry->dest;\n@@ -7614,9 +7572,15 @@ move_sese_region_to_fn (struct function\n      FIXME, this is silly.  The CFG ought to become a parameter to\n      these helpers.  */\n   push_cfun (dest_cfun);\n-  make_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun), entry_bb, EDGE_FALLTHRU);\n+  ENTRY_BLOCK_PTR_FOR_FN (cfun)->count = entry_bb->count;\n+  make_single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun), entry_bb, EDGE_FALLTHRU);\n   if (exit_bb)\n-    make_edge (exit_bb,  EXIT_BLOCK_PTR_FOR_FN (cfun), 0);\n+    {\n+      make_single_succ_edge (exit_bb,  EXIT_BLOCK_PTR_FOR_FN (cfun), 0);\n+      EXIT_BLOCK_PTR_FOR_FN (cfun)->count = exit_bb->count;\n+    }\n+  else\n+    EXIT_BLOCK_PTR_FOR_FN (cfun)->count = profile_count::zero ();\n   pop_cfun ();\n \n   /* Back in the original function, the SESE region has disappeared,\n@@ -8691,7 +8655,7 @@ gimple_account_profile_record (basic_blo\n       else if (profile_status_for_fn (cfun) == PROFILE_GUESSED)\n \trecord->time[after_pass]\n \t  += estimate_num_insns (gsi_stmt (i),\n-\t\t\t\t &eni_time_weights) * bb->frequency;\n+\t\t\t\t &eni_time_weights) * bb->count.to_frequency (cfun);\n     }\n }\n \n@@ -8843,7 +8807,6 @@ insert_cond_bb (basic_block bb, gimple *\n   edge e = make_edge (bb, new_bb, EDGE_TRUE_VALUE);\n   e->probability = prob;\n   new_bb->count = e->count ();\n-  new_bb->frequency = prob.apply (bb->frequency);\n   make_single_succ_edge (new_bb, fall->dest, EDGE_FALLTHRU);\n \n   /* Fix edge for split bb.  */\nIndex: tree-complex.c\n===================================================================\n--- tree-complex.c\t(revision 254348)\n+++ tree-complex.c\t(working copy)\n@@ -1191,7 +1191,6 @@ expand_complex_div_wide (gimple_stmt_ite\n       bb_join = e->dest;\n       bb_true = create_empty_bb (bb_cond);\n       bb_false = create_empty_bb (bb_true);\n-      bb_true->frequency = bb_false->frequency = bb_cond->frequency / 2;\n       bb_true->count = bb_false->count\n \t = bb_cond->count.apply_probability (profile_probability::even ());\n \nIndex: tree-eh.c\n===================================================================\n--- tree-eh.c\t(revision 254348)\n+++ tree-eh.c\t(working copy)\n@@ -3224,6 +3224,7 @@ lower_resx (basic_block bb, gresx *stmt,\n \t      gimple_stmt_iterator gsi2;\n \n \t      new_bb = create_empty_bb (bb);\n+\t      new_bb->count = bb->count;\n \t      add_bb_to_loop (new_bb, bb->loop_father);\n \t      lab = gimple_block_label (new_bb);\n \t      gsi2 = gsi_start_bb (new_bb);\nIndex: tree-inline.c\n===================================================================\n--- tree-inline.c\t(revision 254348)\n+++ tree-inline.c\t(working copy)\n@@ -1763,16 +1763,15 @@ remap_gimple_stmt (gimple *stmt, copy_bo\n    later  */\n \n static basic_block\n-copy_bb (copy_body_data *id, basic_block bb, int frequency_scale,\n+copy_bb (copy_body_data *id, basic_block bb,\n          profile_count num, profile_count den)\n {\n   gimple_stmt_iterator gsi, copy_gsi, seq_gsi;\n   basic_block copy_basic_block;\n   tree decl;\n-  gcov_type freq;\n   basic_block prev;\n-  bool scale = num.initialized_p ()\n-\t       && (den > 0 || num == profile_count::zero ());\n+  bool scale = !num.initialized_p ()\n+\t       || (den.nonzero_p () || num == profile_count::zero ());\n \n   /* Search for previous copied basic block.  */\n   prev = bb->prev_bb;\n@@ -1784,15 +1783,8 @@ copy_bb (copy_body_data *id, basic_block\n   copy_basic_block = create_basic_block (NULL, (basic_block) prev->aux);\n   if (scale)\n     copy_basic_block->count = bb->count.apply_scale (num, den);\n-\n-  /* We are going to rebuild frequencies from scratch.  These values\n-     have just small importance to drive canonicalize_loop_headers.  */\n-  freq = apply_scale ((gcov_type)bb->frequency, frequency_scale);\n-\n-  /* We recompute frequencies after inlining, so this is quite safe.  */\n-  if (freq > BB_FREQ_MAX)\n-    freq = BB_FREQ_MAX;\n-  copy_basic_block->frequency = freq;\n+  else if (num.initialized_p ())\n+    copy_basic_block->count = bb->count;\n \n   copy_gsi = gsi_start_bb (copy_basic_block);\n \n@@ -2068,8 +2060,8 @@ copy_bb (copy_body_data *id, basic_block\n \t\t\t      fprintf (dump_file,\n \t\t\t\t       \"Orig bb: %i, orig bb freq %i, new bb freq %i\\n\",\n \t\t\t\t       bb->index,\n-\t\t\t\t       bb->frequency,\n-\t\t\t\t       copy_basic_block->frequency);\n+\t\t\t\t       bb->count.to_frequency (cfun),\n+\t\t\t\t       copy_basic_block->count.to_frequency (cfun));\n \t\t\t    }\n \t\t\t}\n \t\t    }\n@@ -2507,11 +2499,8 @@ initialize_cfun (tree new_fndecl, tree c\n \n   profile_status_for_fn (cfun) = profile_status_for_fn (src_cfun);\n \n-  /* FIXME: When all counts are known to be zero, scaling is also meaningful.\n-   */\n   if (ENTRY_BLOCK_PTR_FOR_FN (src_cfun)->count.initialized_p ()\n-      && count.initialized_p ()\n-      && ENTRY_BLOCK_PTR_FOR_FN (src_cfun)->count.initialized_p ())\n+      && count.ipa ().initialized_p ())\n     {\n       ENTRY_BLOCK_PTR_FOR_FN (cfun)->count =\n \tENTRY_BLOCK_PTR_FOR_FN (src_cfun)->count.apply_scale (count,\n@@ -2520,10 +2509,13 @@ initialize_cfun (tree new_fndecl, tree c\n \tEXIT_BLOCK_PTR_FOR_FN (src_cfun)->count.apply_scale (count,\n \t\t\t\t    ENTRY_BLOCK_PTR_FOR_FN (src_cfun)->count);\n     }\n-  ENTRY_BLOCK_PTR_FOR_FN (cfun)->frequency\n-    = ENTRY_BLOCK_PTR_FOR_FN (src_cfun)->frequency;\n-  EXIT_BLOCK_PTR_FOR_FN (cfun)->frequency =\n-    EXIT_BLOCK_PTR_FOR_FN (src_cfun)->frequency;\n+  else\n+    {\n+      ENTRY_BLOCK_PTR_FOR_FN (cfun)->count\n+\t   = ENTRY_BLOCK_PTR_FOR_FN (src_cfun)->count;\n+      EXIT_BLOCK_PTR_FOR_FN (cfun)->count\n+\t   = EXIT_BLOCK_PTR_FOR_FN (src_cfun)->count;\n+    }\n   if (src_cfun->eh)\n     init_eh_for_function ();\n \n@@ -2680,27 +2672,11 @@ redirect_all_calls (copy_body_data * id,\n     }\n }\n \n-/* Convert estimated frequencies into counts for NODE, scaling COUNT\n-   with each bb's frequency. Used when NODE has a 0-weight entry\n-   but we are about to inline it into a non-zero count call bb.\n-   See the comments for handle_missing_profiles() in predict.c for\n-   when this can happen for COMDATs.  */\n-\n-void\n-freqs_to_counts (struct cgraph_node *node, profile_count count)\n-{\n-  basic_block bb;\n-  struct function *fn = DECL_STRUCT_FUNCTION (node->decl);\n-\n-  FOR_ALL_BB_FN(bb, fn)\n-    bb->count = count.apply_scale (bb->frequency, BB_FREQ_MAX);\n-}\n-\n /* Make a copy of the body of FN so that it can be inserted inline in\n    another function.  Walks FN via CFG, returns new fndecl.  */\n \n static tree\n-copy_cfg_body (copy_body_data * id, profile_count count, int frequency_scale,\n+copy_cfg_body (copy_body_data * id, profile_count,\n \t       basic_block entry_block_map, basic_block exit_block_map,\n \t       basic_block new_entry)\n {\n@@ -2712,31 +2688,10 @@ copy_cfg_body (copy_body_data * id, prof\n   tree new_fndecl = NULL;\n   bool need_debug_cleanup = false;\n   int last;\n-  int incoming_frequency = 0;\n-  profile_count incoming_count = profile_count::zero ();\n-  profile_count num = count;\n   profile_count den = ENTRY_BLOCK_PTR_FOR_FN (src_cfun)->count;\n-  bool scale = num.initialized_p ()\n-\t       && (den > 0 || num == profile_count::zero ());\n+  profile_count num = entry_block_map->count;\n \n-  /* This can happen for COMDAT routines that end up with 0 counts\n-     despite being called (see the comments for handle_missing_profiles()\n-     in predict.c as to why). Apply counts to the blocks in the callee\n-     before inlining, using the guessed edge frequencies, so that we don't\n-     end up with a 0-count inline body which can confuse downstream\n-     optimizations such as function splitting.  */\n-  if (!(ENTRY_BLOCK_PTR_FOR_FN (src_cfun)->count > 0) && count > 0)\n-    {\n-      /* Apply the larger of the call bb count and the total incoming\n-         call edge count to the callee.  */\n-      profile_count in_count = profile_count::zero ();\n-      struct cgraph_edge *in_edge;\n-      for (in_edge = id->src_node->callers; in_edge;\n-           in_edge = in_edge->next_caller)\n-\tif (in_edge->count.initialized_p ())\n-          in_count += in_edge->count;\n-      freqs_to_counts (id->src_node, count > in_count ? count : in_count);\n-    }\n+  cfun_to_copy = id->src_cfun = DECL_STRUCT_FUNCTION (callee_fndecl);\n \n   /* Register specific tree functions.  */\n   gimple_register_cfg_hooks ();\n@@ -2750,25 +2705,18 @@ copy_cfg_body (copy_body_data * id, prof\n     {\n       edge e;\n       edge_iterator ei;\n+      den = profile_count::zero ();\n \n       FOR_EACH_EDGE (e, ei, new_entry->preds)\n \tif (!e->src->aux)\n-\t  incoming_frequency += EDGE_FREQUENCY (e);\n-      if (scale)\n-        incoming_count = incoming_count.apply_scale (num, den);\n-      else\n-\tincoming_count = profile_count::uninitialized ();\n-      incoming_frequency\n-\t= apply_scale ((gcov_type)incoming_frequency, frequency_scale);\n-      ENTRY_BLOCK_PTR_FOR_FN (cfun)->count = incoming_count;\n-      ENTRY_BLOCK_PTR_FOR_FN (cfun)->frequency = incoming_frequency;\n+\t  den += e->count ();\n+      ENTRY_BLOCK_PTR_FOR_FN (cfun)->count = den;\n     }\n \n   /* Must have a CFG here at this point.  */\n   gcc_assert (ENTRY_BLOCK_PTR_FOR_FN\n \t      (DECL_STRUCT_FUNCTION (callee_fndecl)));\n \n-  cfun_to_copy = id->src_cfun = DECL_STRUCT_FUNCTION (callee_fndecl);\n \n   ENTRY_BLOCK_PTR_FOR_FN (cfun_to_copy)->aux = entry_block_map;\n   EXIT_BLOCK_PTR_FOR_FN (cfun_to_copy)->aux = exit_block_map;\n@@ -2784,7 +2732,7 @@ copy_cfg_body (copy_body_data * id, prof\n   FOR_EACH_BB_FN (bb, cfun_to_copy)\n     if (!id->blocks_to_copy || bitmap_bit_p (id->blocks_to_copy, bb->index))\n       {\n-\tbasic_block new_bb = copy_bb (id, bb, frequency_scale, num, den);\n+\tbasic_block new_bb = copy_bb (id, bb, num, den);\n \tbb->aux = new_bb;\n \tnew_bb->aux = bb;\n \tnew_bb->loop_father = entry_block_map->loop_father;\n@@ -3011,7 +2959,7 @@ copy_tree_body (copy_body_data *id)\n    another function.  */\n \n static tree\n-copy_body (copy_body_data *id, profile_count count, int frequency_scale,\n+copy_body (copy_body_data *id, profile_count count,\n \t   basic_block entry_block_map, basic_block exit_block_map,\n \t   basic_block new_entry)\n {\n@@ -3020,7 +2968,7 @@ copy_body (copy_body_data *id, profile_c\n \n   /* If this body has a CFG, walk CFG and copy.  */\n   gcc_assert (ENTRY_BLOCK_PTR_FOR_FN (DECL_STRUCT_FUNCTION (fndecl)));\n-  body = copy_cfg_body (id, count, frequency_scale, entry_block_map, exit_block_map,\n+  body = copy_cfg_body (id, count, entry_block_map, exit_block_map,\n \t\t\tnew_entry);\n   copy_debug_stmts (id);\n \n@@ -4771,7 +4719,6 @@ expand_call_inline (basic_block bb, gimp\n      a self-referential call; if we're calling ourselves, we need to\n      duplicate our body before altering anything.  */\n   copy_body (id, cg_edge->callee->count,\n-  \t     GCOV_COMPUTE_SCALE (cg_edge->frequency, CGRAPH_FREQ_BASE),\n \t     bb, return_block, NULL);\n \n   reset_debug_bindings (id, stmt_gsi);\n@@ -5146,6 +5093,7 @@ optimize_inline_calls (tree fn)\n     }\n \n   /* Fold queued statements.  */\n+  counts_to_freqs ();\n   fold_marked_statements (last, id.statements_to_fold);\n   delete id.statements_to_fold;\n \n@@ -6090,7 +6038,7 @@ tree_function_versioning (tree old_decl,\n     }\n \n   /* Copy the Function's body.  */\n-  copy_body (&id, old_entry_block->count, REG_BR_PROB_BASE,\n+  copy_body (&id, old_entry_block->count,\n \t     ENTRY_BLOCK_PTR_FOR_FN (cfun), EXIT_BLOCK_PTR_FOR_FN (cfun),\n \t     new_entry);\n \n@@ -6122,6 +6070,7 @@ tree_function_versioning (tree old_decl,\n   free_dominance_info (CDI_DOMINATORS);\n   free_dominance_info (CDI_POST_DOMINATORS);\n \n+  counts_to_freqs ();\n   fold_marked_statements (0, id.statements_to_fold);\n   delete id.statements_to_fold;\n   delete_unreachable_blocks_update_callgraph (&id);\n@@ -6141,20 +6090,20 @@ tree_function_versioning (tree old_decl,\n       struct cgraph_edge *e;\n       rebuild_frequencies ();\n \n-      new_version_node->count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;\n+      new_version_node->count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.ipa ();\n       for (e = new_version_node->callees; e; e = e->next_callee)\n \t{\n \t  basic_block bb = gimple_bb (e->call_stmt);\n \t  e->frequency = compute_call_stmt_bb_frequency (current_function_decl,\n \t\t\t\t\t\t\t bb);\n-\t  e->count = bb->count;\n+\t  e->count = bb->count.ipa ();\n \t}\n       for (e = new_version_node->indirect_calls; e; e = e->next_callee)\n \t{\n \t  basic_block bb = gimple_bb (e->call_stmt);\n \t  e->frequency = compute_call_stmt_bb_frequency (current_function_decl,\n \t\t\t\t\t\t\t bb);\n-\t  e->count = bb->count;\n+\t  e->count = bb->count.ipa ();\n \t}\n     }\n \nIndex: tree-ssa-coalesce.c\n===================================================================\n--- tree-ssa-coalesce.c\t(revision 254348)\n+++ tree-ssa-coalesce.c\t(working copy)\n@@ -164,7 +164,7 @@ coalesce_cost (int frequency, bool optim\n static inline int\n coalesce_cost_bb (basic_block bb)\n {\n-  return coalesce_cost (bb->frequency, optimize_bb_for_size_p (bb));\n+  return coalesce_cost (bb->count.to_frequency (cfun), optimize_bb_for_size_p (bb));\n }\n \n \nIndex: tree-ssa-ifcombine.c\n===================================================================\n--- tree-ssa-ifcombine.c\t(revision 254348)\n+++ tree-ssa-ifcombine.c\t(working copy)\n@@ -366,7 +366,6 @@ update_profile_after_ifcombine (basic_bl\n \t\t\t\t - inner_taken->probability;\n \n   outer_to_inner->probability = profile_probability::always ();\n-  inner_cond_bb->frequency = outer_cond_bb->frequency;\n   outer2->probability = profile_probability::never ();\n }\n \nIndex: tree-ssa-loop-im.c\n===================================================================\n--- tree-ssa-loop-im.c\t(revision 254348)\n+++ tree-ssa-loop-im.c\t(working copy)\n@@ -1803,7 +1803,7 @@ execute_sm_if_changed (edge ex, tree mem\n   for (hash_set<basic_block>::iterator it = flag_bbs->begin ();\n        it != flag_bbs->end (); ++it)\n     {\n-       freq_sum += (*it)->frequency;\n+       freq_sum += (*it)->count.to_frequency (cfun);\n        if ((*it)->count.initialized_p ())\n          count_sum += (*it)->count, ncount ++;\n        if (dominated_by_p (CDI_DOMINATORS, ex->src, *it))\n@@ -1815,20 +1815,15 @@ execute_sm_if_changed (edge ex, tree mem\n \n   if (flag_probability.initialized_p ())\n     ;\n-  else if (ncount == nbbs && count_sum > 0 && preheader->count () >= count_sum)\n+  else if (ncount == nbbs\n+\t   && preheader->count () >= count_sum && preheader->count ().nonzero_p ())\n     {\n       flag_probability = count_sum.probability_in (preheader->count ());\n       if (flag_probability > cap)\n \tflag_probability = cap;\n     }\n-  else if (freq_sum > 0 && EDGE_FREQUENCY (preheader) >= freq_sum)\n-    {\n-      flag_probability = profile_probability::from_reg_br_prob_base\n-\t\t(GCOV_COMPUTE_SCALE (freq_sum, EDGE_FREQUENCY (preheader)));\n-      if (flag_probability > cap)\n-\tflag_probability = cap;\n-    }\n-  else\n+\n+  if (!flag_probability.initialized_p ())\n     flag_probability = cap;\n \n   /* ?? Insert store after previous store if applicable.  See note\n@@ -1861,7 +1856,6 @@ execute_sm_if_changed (edge ex, tree mem\n   old_dest = ex->dest;\n   new_bb = split_edge (ex);\n   then_bb = create_empty_bb (new_bb);\n-  then_bb->frequency = flag_probability.apply (new_bb->frequency);\n   then_bb->count = new_bb->count.apply_probability (flag_probability);\n   if (irr)\n     then_bb->flags = BB_IRREDUCIBLE_LOOP;\nIndex: tree-ssa-loop-ivcanon.c\n===================================================================\n--- tree-ssa-loop-ivcanon.c\t(revision 254348)\n+++ tree-ssa-loop-ivcanon.c\t(working copy)\n@@ -647,7 +647,6 @@ unloop_loops (bitmap loop_closed_ssa_inv\n \n       add_bb_to_loop (latch_edge->dest, current_loops->tree_root);\n       latch_edge->dest->count = profile_count::zero ();\n-      latch_edge->dest->frequency = 0;\n       set_immediate_dominator (CDI_DOMINATORS, latch_edge->dest, latch_edge->src);\n \n       gsi = gsi_start_bb (latch_edge->dest);\n@@ -1090,7 +1089,6 @@ try_peel_loop (struct loop *loop,\n \t}\n     }\n   profile_count entry_count = profile_count::zero ();\n-  int entry_freq = 0;\n \n   edge e;\n   edge_iterator ei;\n@@ -1099,15 +1097,10 @@ try_peel_loop (struct loop *loop,\n       {\n \tif (e->src->count.initialized_p ())\n \t  entry_count = e->src->count + e->src->count;\n-\tentry_freq += e->src->frequency;\n \tgcc_assert (!flow_bb_inside_loop_p (loop, e->src));\n       }\n   profile_probability p = profile_probability::very_unlikely ();\n-  if (loop->header->count > 0)\n-    p = entry_count.probability_in (loop->header->count);\n-  else if (loop->header->frequency)\n-    p = profile_probability::probability_in_gcov_type\n-\t\t (entry_freq, loop->header->frequency);\n+  p = entry_count.probability_in (loop->header->count);\n   scale_loop_profile (loop, p, 0);\n   bitmap_set_bit (peeled_loops, loop->num);\n   return true;\nIndex: tree-ssa-loop-ivopts.c\n===================================================================\n--- tree-ssa-loop-ivopts.c\t(revision 254348)\n+++ tree-ssa-loop-ivopts.c\t(working copy)\n@@ -4457,8 +4457,8 @@ get_address_cost (struct ivopts_data *da\n static comp_cost\n get_scaled_computation_cost_at (ivopts_data *data, gimple *at, comp_cost cost)\n {\n-   int loop_freq = data->current_loop->header->frequency;\n-   int bb_freq = gimple_bb (at)->frequency;\n+   int loop_freq = data->current_loop->header->count.to_frequency (cfun);\n+   int bb_freq = gimple_bb (at)->count.to_frequency (cfun);\n    if (loop_freq != 0)\n      {\n        gcc_assert (cost.scratch <= cost.cost);\nIndex: tree-ssa-loop-manip.c\n===================================================================\n--- tree-ssa-loop-manip.c\t(revision 254348)\n+++ tree-ssa-loop-manip.c\t(working copy)\n@@ -1122,6 +1122,9 @@ niter_for_unrolled_loop (struct loop *lo\n      converts back.  */\n   gcov_type new_est_niter = est_niter / factor;\n \n+  if (est_niter == -1)\n+    return -1;\n+\n   /* Without profile feedback, loops for which we do not know a better estimate\n      are assumed to roll 10 times.  When we unroll such loop, it appears to\n      roll too little, and it may even seem to be cold.  To avoid this, we\n@@ -1370,14 +1373,7 @@ tree_transform_and_unroll_loop (struct l\n \n   freq_h = loop->header->count;\n   freq_e = (loop_preheader_edge (loop))->count ();\n-  /* Use frequency only if counts are zero.  */\n-  if (!(freq_h > 0) && !(freq_e > 0))\n-    {\n-      freq_h = profile_count::from_gcov_type (loop->header->frequency);\n-      freq_e = profile_count::from_gcov_type\n-\t\t (EDGE_FREQUENCY (loop_preheader_edge (loop)));\n-    }\n-  if (freq_h > 0)\n+  if (freq_h.nonzero_p ())\n     {\n       /* Avoid dropping loop body profile counter to 0 because of zero count\n \t in loop's preheader.  */\n@@ -1392,7 +1388,6 @@ tree_transform_and_unroll_loop (struct l\n \t\t\t\t.apply_scale (1, new_est_niter + 1);\n \n   rest->count += new_exit->count ();\n-  rest->frequency += EDGE_FREQUENCY (new_exit);\n \n   new_nonexit = single_pred_edge (loop->latch);\n   prob = new_nonexit->probability;\nIndex: tree-ssa-loop-niter.c\n===================================================================\n--- tree-ssa-loop-niter.c\t(revision 254348)\n+++ tree-ssa-loop-niter.c\t(working copy)\n@@ -3901,7 +3901,7 @@ estimate_numbers_of_iterations (struct l\n      recomputing iteration bounds later in the compilation process will just\n      introduce random roundoff errors.  */\n   if (!loop->any_estimate\n-      && loop->header->count > 0)\n+      && loop->header->count.reliable_p ())\n     {\n       gcov_type nit = expected_loop_iterations_unbounded (loop);\n       bound = gcov_type_to_wide_int (nit);\nIndex: tree-ssa-loop-unswitch.c\n===================================================================\n--- tree-ssa-loop-unswitch.c\t(revision 254348)\n+++ tree-ssa-loop-unswitch.c\t(working copy)\n@@ -852,7 +852,7 @@ hoist_guard (struct loop *loop, edge gua\n   /* Determine the probability that we skip the loop.  Assume that loop has\n      same average number of iterations regardless outcome of guard.  */\n   new_edge->probability = guard->probability;\n-  profile_count skip_count = guard->src->count > 0\n+  profile_count skip_count = guard->src->count.nonzero_p ()\n \t\t   ? guard->count ().apply_scale (pre_header->count,\n \t\t\t\t\t       guard->src->count)\n \t\t   : guard->count ().apply_probability (new_edge->probability);\n@@ -875,7 +875,6 @@ hoist_guard (struct loop *loop, edge gua\n      to loop header...  */\n   e->probability = new_edge->probability.invert ();\n   e->dest->count = e->count ();\n-  e->dest->frequency = EDGE_FREQUENCY (e);\n \n   /* ... now update profile to represent that original guard will be optimized\n      away ...  */\nIndex: tree-ssa-sink.c\n===================================================================\n--- tree-ssa-sink.c\t(revision 254348)\n+++ tree-ssa-sink.c\t(working copy)\n@@ -226,7 +226,8 @@ select_best_block (basic_block early_bb,\n   /* If BEST_BB is at the same nesting level, then require it to have\n      significantly lower execution frequency to avoid gratutious movement.  */\n   if (bb_loop_depth (best_bb) == bb_loop_depth (early_bb)\n-      && best_bb->frequency < (early_bb->frequency * threshold / 100.0))\n+      && best_bb->count.to_frequency (cfun)\n+\t < (early_bb->count.to_frequency (cfun) * threshold / 100.0))\n     return best_bb;\n \n   /* No better block found, so return EARLY_BB, which happens to be the\nIndex: tree-ssa-tail-merge.c\n===================================================================\n--- tree-ssa-tail-merge.c\t(revision 254348)\n+++ tree-ssa-tail-merge.c\t(working copy)\n@@ -1530,8 +1530,6 @@ static void\n replace_block_by (basic_block bb1, basic_block bb2)\n {\n   edge pred_edge;\n-  edge e1, e2;\n-  edge_iterator ei;\n   unsigned int i;\n   gphi *bb2_phi;\n \n@@ -1560,9 +1558,13 @@ replace_block_by (basic_block bb1, basic\n \n   bb2->count += bb1->count;\n \n+  /* FIXME: Fix merging of probabilities.  They need to be redistributed\n+     according to the relative counts of merged BBs.  */\n+#if 0\n   /* Merge the outgoing edge counts from bb1 onto bb2.  */\n   profile_count out_sum = profile_count::zero ();\n   int out_freq_sum = 0;\n+  edge e1, e2;\n \n   /* Recompute the edge probabilities from the new merged edge count.\n      Use the sum of the new merged edge counts computed above instead\n@@ -1580,7 +1582,6 @@ replace_block_by (basic_block bb1, basic\n \tout_sum += e1->count ();\n       out_freq_sum += EDGE_FREQUENCY (e1);\n     }\n-\n   FOR_EACH_EDGE (e1, ei, bb1->succs)\n     {\n       e2 = find_edge (bb2, e1->dest);\n@@ -1589,9 +1590,9 @@ replace_block_by (basic_block bb1, basic\n \t{\n \t  e2->probability = e2->count ().probability_in (bb2->count);\n \t}\n-      else if (bb1->frequency && bb2->frequency)\n+      else if (bb1->count.to_frequency (cfun) && bb2->count.to_frequency (cfun))\n \te2->probability = e1->probability;\n-      else if (bb2->frequency && !bb1->frequency)\n+      else if (bb2->count.to_frequency (cfun) && !bb1->count.to_frequency (cfun))\n \t;\n       else if (out_freq_sum)\n \te2->probability = profile_probability::from_reg_br_prob_base\n@@ -1600,9 +1601,7 @@ replace_block_by (basic_block bb1, basic\n \t\t\t\t     out_freq_sum));\n       out_sum += e2->count ();\n     }\n-  bb2->frequency += bb1->frequency;\n-  if (bb2->frequency > BB_FREQ_MAX)\n-    bb2->frequency = BB_FREQ_MAX;\n+#endif\n \n   /* Move over any user labels from bb1 after the bb2 labels.  */\n   gimple_stmt_iterator gsi1 = gsi_start_bb (bb1);\nIndex: tree-ssa-threadupdate.c\n===================================================================\n--- tree-ssa-threadupdate.c\t(revision 254348)\n+++ tree-ssa-threadupdate.c\t(working copy)\n@@ -339,7 +339,6 @@ create_block_for_threading (basic_block\n     e->aux = NULL;\n \n   /* Zero out the profile, since the block is unreachable for now.  */\n-  rd->dup_blocks[count]->frequency = 0;\n   rd->dup_blocks[count]->count = profile_count::uninitialized ();\n   if (duplicate_blocks)\n     bitmap_set_bit (*duplicate_blocks, rd->dup_blocks[count]->index);\n@@ -590,7 +589,7 @@ any_remaining_duplicated_blocks (vec<jum\n }\n \n \n-/* Compute the amount of profile count/frequency coming into the jump threading\n+/* Compute the amount of profile count coming into the jump threading\n    path stored in RD that we are duplicating, returned in PATH_IN_COUNT_PTR and\n    PATH_IN_FREQ_PTR, as well as the amount of counts flowing out of the\n    duplicated path, returned in PATH_OUT_COUNT_PTR.  LOCAL_INFO is used to\n@@ -598,7 +597,7 @@ any_remaining_duplicated_blocks (vec<jum\n    edges that need to be ignored in the analysis.  Return true if path contains\n    a joiner, false otherwise.\n \n-   In the non-joiner case, this is straightforward - all the counts/frequency\n+   In the non-joiner case, this is straightforward - all the counts\n    flowing into the jump threading path should flow through the duplicated\n    block and out of the duplicated path.\n \n@@ -851,16 +850,14 @@ compute_path_counts (struct redirection_\n \n /* Update the counts and frequencies for both an original path\n    edge EPATH and its duplicate EDUP.  The duplicate source block\n-   will get a count/frequency of PATH_IN_COUNT and PATH_IN_FREQ,\n+   will get a count of PATH_IN_COUNT and PATH_IN_FREQ,\n    and the duplicate edge EDUP will have a count of PATH_OUT_COUNT.  */\n static void\n update_profile (edge epath, edge edup, profile_count path_in_count,\n-\t\tprofile_count path_out_count, int path_in_freq)\n+\t\tprofile_count path_out_count)\n {\n-  if (!(path_in_count > 0))\n-    return;\n \n-  /* First update the duplicated block's count / frequency.  */\n+  /* First update the duplicated block's count.  */\n   if (edup)\n     {\n       basic_block dup_block = edup->src;\n@@ -894,167 +891,54 @@ update_profile (edge epath, edge edup, p\n \t    if (esucc != edup)\n \t      esucc->probability *= scale;\n \t}\n-      edup->probability = edup_prob;\n+      if (edup_prob.initialized_p ())\n+        edup->probability = edup_prob;\n \n-      /* FIXME once freqs_to_counts is dropped re-enable this check.  */\n-      gcc_assert (!dup_block->count.initialized_p () || 1);\n-      gcc_assert (dup_block->frequency == 0);\n+      gcc_assert (!dup_block->count.initialized_p ());\n       dup_block->count = path_in_count;\n-      dup_block->frequency = path_in_freq;\n     }\n \n+  if (path_in_count == profile_count::zero ())\n+    return;\n+\n   profile_count final_count = epath->count () - path_out_count;\n \n-  /* Now update the original block's count and frequency in the\n+  /* Now update the original block's count in the\n      opposite manner - remove the counts/freq that will flow\n      into the duplicated block.  Handle underflow due to precision/\n      rounding issues.  */\n   epath->src->count -= path_in_count;\n-  epath->src->frequency -= path_in_freq;\n-  if (epath->src->frequency < 0)\n-    epath->src->frequency = 0;\n \n   /* Next update this path edge's original and duplicated counts.  We know\n      that the duplicated path will have path_out_count flowing\n      out of it (in the joiner case this is the count along the duplicated path\n      out of the duplicated joiner).  This count can then be removed from the\n      original path edge.  */\n-  if (epath->src->count > 0)\n-    {\n-      edge esucc;\n-      edge_iterator ei;\n-      profile_probability epath_prob = final_count.probability_in (epath->src->count);\n-\n-      if (epath->probability > epath_prob)\n-\t{\n-\t   profile_probability rev_scale\n-\t     = (profile_probability::always () - epath->probability)\n-\t       / (profile_probability::always () - epath_prob);\n-\t   FOR_EACH_EDGE (esucc, ei, epath->src->succs)\n-\t     if (esucc != epath)\n-\t       esucc->probability /= rev_scale;\n-\t}\n-      else if (epath->probability < epath_prob)\n-\t{\n-\t   profile_probability scale\n-\t     = (profile_probability::always () - epath_prob)\n-\t       / (profile_probability::always () - epath->probability);\n-\t  FOR_EACH_EDGE (esucc, ei, epath->src->succs)\n-\t    if (esucc != epath)\n-\t      esucc->probability *= scale;\n-\t}\n-      epath->probability = epath_prob;\n-    }\n-}\n-\n \n-/* Check if the paths through RD all have estimated frequencies but zero\n-   profile counts.  This is more accurate than checking the entry block\n-   for a zero profile count, since profile insanities sometimes creep in.  */\n-\n-static bool\n-estimated_freqs_path (struct redirection_data *rd)\n-{\n-  edge e = rd->incoming_edges->e;\n-  vec<jump_thread_edge *> *path = THREAD_PATH (e);\n-  edge ein;\n+  edge esucc;\n   edge_iterator ei;\n-  bool non_zero_freq = false;\n-  FOR_EACH_EDGE (ein, ei, e->dest->preds)\n-    {\n-      if (ein->count () > 0)\n-\treturn false;\n-      non_zero_freq |= ein->src->frequency != 0;\n-    }\n+  profile_probability epath_prob = final_count.probability_in (epath->src->count);\n \n-  for (unsigned int i = 1; i < path->length (); i++)\n+  if (epath->probability > epath_prob)\n     {\n-      edge epath = (*path)[i]->e;\n-      if (epath->src->count > 0)\n-\treturn false;\n-      non_zero_freq |= epath->src->frequency != 0;\n-      edge esucc;\n+       profile_probability rev_scale\n+\t = (profile_probability::always () - epath->probability)\n+\t   / (profile_probability::always () - epath_prob);\n+       FOR_EACH_EDGE (esucc, ei, epath->src->succs)\n+\t if (esucc != epath)\n+\t   esucc->probability /= rev_scale;\n+    }\n+  else if (epath->probability < epath_prob)\n+    {\n+       profile_probability scale\n+\t = (profile_probability::always () - epath_prob)\n+\t   / (profile_probability::always () - epath->probability);\n       FOR_EACH_EDGE (esucc, ei, epath->src->succs)\n-\t{\n-\t  if (esucc->count () > 0)\n-\t    return false;\n-\t  non_zero_freq |= esucc->src->frequency != 0;\n-\t}\n-    }\n-  return non_zero_freq;\n-}\n-\n-\n-/* Invoked for routines that have guessed frequencies and no profile\n-   counts to record the block and edge frequencies for paths through RD\n-   in the profile count fields of those blocks and edges.  This is because\n-   ssa_fix_duplicate_block_edges incrementally updates the block and\n-   edge counts as edges are redirected, and it is difficult to do that\n-   for edge frequencies which are computed on the fly from the source\n-   block frequency and probability.  When a block frequency is updated\n-   its outgoing edge frequencies are affected and become difficult to\n-   adjust.  */\n-\n-static void\n-freqs_to_counts_path (struct redirection_data *rd)\n-{\n-  edge e = rd->incoming_edges->e;\n-  vec<jump_thread_edge *> *path = THREAD_PATH (e);\n-  edge ein;\n-  edge_iterator ei;\n-\n-  FOR_EACH_EDGE (ein, ei, e->dest->preds)\n-    ein->src->count = profile_count::from_gcov_type\n-\t  (ein->src->frequency * REG_BR_PROB_BASE);\n-  for (unsigned int i = 1; i < path->length (); i++)\n-    {\n-      edge epath = (*path)[i]->e;\n-      /* Scale up the frequency by REG_BR_PROB_BASE, to avoid rounding\n-\t errors applying the edge probability when the frequencies are very\n-\t small.  */\n-      epath->src->count = \n-\tprofile_count::from_gcov_type\n-\t  (epath->src->frequency * REG_BR_PROB_BASE);\n-    }\n-}\n-\n-\n-/* For routines that have guessed frequencies and no profile counts, where we\n-   used freqs_to_counts_path to record block and edge frequencies for paths\n-   through RD, we clear the counts after completing all updates for RD.\n-   The updates in ssa_fix_duplicate_block_edges are based off the count fields,\n-   but the block frequencies and edge probabilities were updated as well,\n-   so we can simply clear the count fields.  */\n-\n-static void\n-clear_counts_path (struct redirection_data *rd)\n-{\n-  edge e = rd->incoming_edges->e;\n-  vec<jump_thread_edge *> *path = THREAD_PATH (e);\n-  profile_count val = profile_count::uninitialized ();\n-  if (profile_status_for_fn (cfun) == PROFILE_READ)\n-    val = profile_count::zero ();\n-\n-  edge ein;\n-  edge_iterator ei;\n-\n-  FOR_EACH_EDGE (ein, ei, e->dest->preds)\n-    ein->src->count = val;\n-\n-  /* First clear counts along original path.  */\n-  for (unsigned int i = 1; i < path->length (); i++)\n-    {\n-      edge epath = (*path)[i]->e;\n-      epath->src->count = val;\n-    }\n-  /* Also need to clear the counts along duplicated path.  */\n-  for (unsigned int i = 0; i < 2; i++)\n-    {\n-      basic_block dup = rd->dup_blocks[i];\n-      if (!dup)\n-\tcontinue;\n-      dup->count = val;\n+\tif (esucc != epath)\n+\t  esucc->probability *= scale;\n     }\n+  if (epath_prob.initialized_p ())\n+    epath->probability = epath_prob;\n }\n \n /* Wire up the outgoing edges from the duplicate blocks and\n@@ -1072,20 +956,6 @@ ssa_fix_duplicate_block_edges (struct re\n   profile_count path_out_count = profile_count::zero ();\n   int path_in_freq = 0;\n \n-  /* This routine updates profile counts, frequencies, and probabilities\n-     incrementally. Since it is difficult to do the incremental updates\n-     using frequencies/probabilities alone, for routines without profile\n-     data we first take a snapshot of the existing block and edge frequencies\n-     by copying them into the empty profile count fields.  These counts are\n-     then used to do the incremental updates, and cleared at the end of this\n-     routine.  If the function is marked as having a profile, we still check\n-     to see if the paths through RD are using estimated frequencies because\n-     the routine had zero profile counts.  */\n-  bool do_freqs_to_counts = (profile_status_for_fn (cfun) != PROFILE_READ\n-\t\t\t     || estimated_freqs_path (rd));\n-  if (do_freqs_to_counts)\n-    freqs_to_counts_path (rd);\n-\n   /* First determine how much profile count to move from original\n      path to the duplicate path.  This is tricky in the presence of\n      a joiner (see comments for compute_path_counts), where some portion\n@@ -1096,7 +966,6 @@ ssa_fix_duplicate_block_edges (struct re\n \t\t\t\t\t &path_in_count, &path_out_count,\n \t\t\t\t\t &path_in_freq);\n \n-  int cur_path_freq = path_in_freq;\n   for (unsigned int count = 0, i = 1; i < path->length (); i++)\n     {\n       edge epath = (*path)[i]->e;\n@@ -1162,19 +1031,14 @@ ssa_fix_duplicate_block_edges (struct re\n \t\t}\n \t    }\n \n-\t  /* Update the counts and frequency of both the original block\n+\t  /* Update the counts of both the original block\n \t     and path edge, and the duplicates.  The path duplicate's\n-\t     incoming count and frequency are the totals for all edges\n+\t     incoming count are the totals for all edges\n \t     incoming to this jump threading path computed earlier.\n \t     And we know that the duplicated path will have path_out_count\n \t     flowing out of it (i.e. along the duplicated path out of the\n \t     duplicated joiner).  */\n-\t  update_profile (epath, e2, path_in_count, path_out_count,\n-\t\t\t  path_in_freq);\n-\n-\t  /* Record the frequency flowing to the downstream duplicated\n-\t     path blocks.  */\n-\t  cur_path_freq = EDGE_FREQUENCY (e2);\n+\t  update_profile (epath, e2, path_in_count, path_out_count);\n \t}\n       else if ((*path)[i]->type == EDGE_COPY_SRC_BLOCK)\n \t{\n@@ -1184,7 +1048,7 @@ ssa_fix_duplicate_block_edges (struct re\n \t  if (count == 1)\n \t    single_succ_edge (rd->dup_blocks[1])->aux = NULL;\n \n-\t  /* Update the counts and frequency of both the original block\n+\t  /* Update the counts of both the original block\n \t     and path edge, and the duplicates.  Since we are now after\n \t     any joiner that may have existed on the path, the count\n \t     flowing along the duplicated threaded path is path_out_count.\n@@ -1194,7 +1058,7 @@ ssa_fix_duplicate_block_edges (struct re\n \t     been updated at the end of that handling to the edge frequency\n \t     along the duplicated joiner path edge.  */\n \t  update_profile (epath, EDGE_SUCC (rd->dup_blocks[count], 0),\n-\t\t\t  path_out_count, path_out_count, cur_path_freq);\n+\t\t\t  path_out_count, path_out_count);\n \t}\n       else\n \t{\n@@ -1211,8 +1075,7 @@ ssa_fix_duplicate_block_edges (struct re\n \t     thread path (path_in_freq).  If we had a joiner, it would have\n \t     been updated at the end of that handling to the edge frequency\n \t     along the duplicated joiner path edge.  */\n-\t   update_profile (epath, NULL, path_out_count, path_out_count,\n-\t\t\t   cur_path_freq);\n+\t   update_profile (epath, NULL, path_out_count, path_out_count);\n \t}\n \n       /* Increment the index into the duplicated path when we processed\n@@ -1223,11 +1086,6 @@ ssa_fix_duplicate_block_edges (struct re\n \t  count++;\n \t}\n     }\n-\n-  /* Done with all profile and frequency updates, clear counts if they\n-     were copied.  */\n-  if (do_freqs_to_counts)\n-    clear_counts_path (rd);\n }\n \n /* Hash table traversal callback routine to create duplicate blocks.  */\n@@ -2137,7 +1995,6 @@ duplicate_thread_path (edge entry, edge\n   struct loop *loop = entry->dest->loop_father;\n   edge exit_copy;\n   edge redirected;\n-  int curr_freq;\n   profile_count curr_count;\n \n   if (!can_copy_bbs_p (region, n_region))\n@@ -2170,7 +2027,6 @@ duplicate_thread_path (edge entry, edge\n      the jump-thread path in order.  */\n \n   curr_count = entry->count ();\n-  curr_freq = EDGE_FREQUENCY (entry);\n \n   for (i = 0; i < n_region; i++)\n     {\n@@ -2181,10 +2037,8 @@ duplicate_thread_path (edge entry, edge\n       /* Watch inconsistent profile.  */\n       if (curr_count > region[i]->count)\n \tcurr_count = region[i]->count;\n-      if (curr_freq > region[i]->frequency)\n-\tcurr_freq = region[i]->frequency;\n       /* Scale current BB.  */\n-      if (region[i]->count > 0 && curr_count.initialized_p ())\n+      if (region[i]->count.nonzero_p () && curr_count.initialized_p ())\n \t{\n \t  /* In the middle of the path we only scale the frequencies.\n \t     In last BB we need to update probabilities of outgoing edges\n@@ -2195,24 +2049,11 @@ duplicate_thread_path (edge entry, edge\n \t\t\t\t\t         region[i]->count);\n \t  else\n \t    update_bb_profile_for_threading (region[i],\n-\t\t\t\t\t     curr_freq, curr_count,\n+\t\t\t\t\t     curr_count,\n \t\t\t\t\t     exit);\n \t  scale_bbs_frequencies_profile_count (region_copy + i, 1, curr_count,\n \t\t\t\t\t       region_copy[i]->count);\n \t}\n-      else if (region[i]->frequency)\n-\t{\n-\t  if (i + 1 != n_region)\n-\t    scale_bbs_frequencies_int (region + i, 1,\n-\t\t\t\t       region[i]->frequency - curr_freq,\n-\t\t\t\t       region[i]->frequency);\n-\t  else\n-\t    update_bb_profile_for_threading (region[i],\n-\t\t\t\t\t     curr_freq, curr_count,\n-\t\t\t\t\t     exit);\n-\t  scale_bbs_frequencies_int (region_copy + i, 1, curr_freq,\n-\t\t\t\t     region_copy[i]->frequency);\n-\t}\n \n       if (single_succ_p (bb))\n \t{\n@@ -2221,7 +2062,6 @@ duplicate_thread_path (edge entry, edge\n \t\t      || region_copy[i + 1] == single_succ_edge (bb)->dest);\n \t  if (i + 1 != n_region)\n \t    {\n-\t      curr_freq = EDGE_FREQUENCY (single_succ_edge (bb));\n \t      curr_count = single_succ_edge (bb)->count ();\n \t    }\n \t  continue;\n@@ -2252,7 +2092,6 @@ duplicate_thread_path (edge entry, edge\n \t  }\n \telse\n \t  {\n-\t    curr_freq = EDGE_FREQUENCY (e);\n \t    curr_count = e->count ();\n \t  }\n     }\nIndex: tree-switch-conversion.c\n===================================================================\n--- tree-switch-conversion.c\t(revision 254348)\n+++ tree-switch-conversion.c\t(working copy)\n@@ -1443,10 +1443,10 @@ gen_inbound_check (gswitch *swtch, struc\n     }\n \n   /* frequencies of the new BBs */\n-  bb1->frequency = EDGE_FREQUENCY (e01);\n-  bb2->frequency = EDGE_FREQUENCY (e02);\n+  bb1->count = e01->count ();\n+  bb2->count = e02->count ();\n   if (!info->default_case_nonstandard)\n-    bbf->frequency = EDGE_FREQUENCY (e1f) + EDGE_FREQUENCY (e2f);\n+    bbf->count = e1f->count () + e2f->count ();\n \n   /* Tidy blocks that have become unreachable.  */\n   prune_bbs (bbd, info->final_bb,\nIndex: tree-tailcall.c\n===================================================================\n--- tree-tailcall.c\t(revision 254348)\n+++ tree-tailcall.c\t(working copy)\n@@ -805,12 +805,9 @@ adjust_return_value (basic_block bb, tre\n /* Subtract COUNT and FREQUENCY from the basic block and it's\n    outgoing edge.  */\n static void\n-decrease_profile (basic_block bb, profile_count count, int frequency)\n+decrease_profile (basic_block bb, profile_count count)\n {\n   bb->count = bb->count - count;\n-  bb->frequency -= frequency;\n-  if (bb->frequency < 0)\n-    bb->frequency = 0;\n   if (!single_succ_p (bb))\n     {\n       gcc_assert (!EDGE_COUNT (bb->succs));\n@@ -892,11 +889,10 @@ eliminate_tail_call (struct tailcall *t)\n \n   /* Number of executions of function has reduced by the tailcall.  */\n   e = single_succ_edge (gsi_bb (t->call_gsi));\n-  decrease_profile (EXIT_BLOCK_PTR_FOR_FN (cfun), e->count (), EDGE_FREQUENCY (e));\n-  decrease_profile (ENTRY_BLOCK_PTR_FOR_FN (cfun), e->count (),\n-\t\t    EDGE_FREQUENCY (e));\n+  decrease_profile (EXIT_BLOCK_PTR_FOR_FN (cfun), e->count ());\n+  decrease_profile (ENTRY_BLOCK_PTR_FOR_FN (cfun), e->count ());\n   if (e->dest != EXIT_BLOCK_PTR_FOR_FN (cfun))\n-    decrease_profile (e->dest, e->count (), EDGE_FREQUENCY (e));\n+    decrease_profile (e->dest, e->count ());\n \n   /* Replace the call by a jump to the start of function.  */\n   e = redirect_edge_and_branch (single_succ_edge (gsi_bb (t->call_gsi)),\nIndex: tree-vect-loop-manip.c\n===================================================================\n--- tree-vect-loop-manip.c\t(revision 254348)\n+++ tree-vect-loop-manip.c\t(working copy)\n@@ -1843,7 +1843,6 @@ vect_do_peeling (loop_vec_info loop_vinf\n \n \t  /* Simply propagate profile info from guard_bb to guard_to which is\n \t     a merge point of control flow.  */\n-\t  guard_to->frequency = guard_bb->frequency;\n \t  guard_to->count = guard_bb->count;\n \t  /* Scale probability of epilog loop back.\n \t     FIXME: We should avoid scaling down and back up.  Profile may\nIndex: tree-vect-loop.c\n===================================================================\n--- tree-vect-loop.c\t(revision 254348)\n+++ tree-vect-loop.c\t(working copy)\n@@ -7229,20 +7229,14 @@ scale_profile_for_vect_loop (struct loop\n   gcov_type new_est_niter = niter_for_unrolled_loop (loop, vf);\n   profile_count freq_h = loop->header->count, freq_e = preheader->count ();\n \n-  /* Use frequency only if counts are zero.  */\n-  if (!(freq_h > 0) && !(freq_e > 0))\n-    {\n-      freq_h = profile_count::from_gcov_type (loop->header->frequency);\n-      freq_e = profile_count::from_gcov_type (EDGE_FREQUENCY (preheader));\n-    }\n-  if (freq_h > 0)\n+  if (freq_h.nonzero_p ())\n     {\n       profile_probability p;\n \n       /* Avoid dropping loop body profile counter to 0 because of zero count\n \t in loop's preheader.  */\n-      if (!(freq_e > profile_count::from_gcov_type (1)))\n-       freq_e = profile_count::from_gcov_type (1);\n+      if (!(freq_e == profile_count::zero ()))\n+        freq_e = freq_e.force_nonzero ();\n       p = freq_e.apply_scale (new_est_niter + 1, 1).probability_in (freq_h);\n       scale_loop_frequencies (loop, p);\n     }\n@@ -7781,7 +7775,7 @@ optimize_mask_stores (struct loop *loop)\n       efalse = make_edge (bb, store_bb, EDGE_FALSE_VALUE);\n       /* Put STORE_BB to likely part.  */\n       efalse->probability = profile_probability::unlikely ();\n-      store_bb->frequency = PROB_ALWAYS - EDGE_FREQUENCY (efalse);\n+      store_bb->count = efalse->count ();\n       make_single_succ_edge (store_bb, join_bb, EDGE_FALLTHRU);\n       if (dom_info_available_p (CDI_DOMINATORS))\n \tset_immediate_dominator (CDI_DOMINATORS, store_bb, bb);\nIndex: tree-vect-stmts.c\n===================================================================\n--- tree-vect-stmts.c\t(revision 254348)\n+++ tree-vect-stmts.c\t(working copy)\n@@ -3221,7 +3221,7 @@ vectorizable_simd_clone_call (gimple *st\n   vec<tree> vargs = vNULL;\n   size_t i, nargs;\n   tree lhs, rtype, ratype;\n-  vec<constructor_elt, va_gc> *ret_ctor_elts;\n+  vec<constructor_elt, va_gc> *ret_ctor_elts = NULL;\n \n   /* Is STMT a vectorizable call?   */\n   if (!is_gimple_call (stmt))\nIndex: ubsan.c\n===================================================================\n--- ubsan.c\t(revision 254348)\n+++ ubsan.c\t(working copy)\n@@ -804,6 +804,7 @@ ubsan_expand_null_ifn (gimple_stmt_itera\n      this edge is unlikely taken, so set up the probability accordingly.  */\n   e = make_edge (cond_bb, then_bb, EDGE_TRUE_VALUE);\n   e->probability = profile_probability::very_unlikely ();\n+  then_bb->count = e->count ();\n \n   /* Connect 'then block' with the 'else block'.  This is needed\n      as the ubsan routines we call in the 'then block' are not noreturn.\n@@ -1085,6 +1086,7 @@ ubsan_expand_ptr_ifn (gimple_stmt_iterat\n \t accordingly.  */\n       e = make_edge (cond_bb, then_bb, EDGE_TRUE_VALUE);\n       e->probability = profile_probability::very_unlikely ();\n+      then_bb->count = e->count ();\n     }\n   else\n     {\n@@ -1098,12 +1100,14 @@ ubsan_expand_ptr_ifn (gimple_stmt_iterat\n \n       e = make_edge (cond_neg_bb, then_bb, EDGE_TRUE_VALUE);\n       e->probability = profile_probability::very_unlikely ();\n+      then_bb->count = e->count ();\n \n       cond_pos_bb = create_empty_bb (cond_bb);\n       add_bb_to_loop (cond_pos_bb, cond_bb->loop_father);\n \n       e = make_edge (cond_bb, cond_pos_bb, EDGE_TRUE_VALUE);\n       e->probability = profile_probability::even ();\n+      cond_pos_bb->count = e->count ();\n \n       e = make_edge (cond_pos_bb, then_bb, EDGE_TRUE_VALUE);\n       e->probability = profile_probability::very_unlikely ();\nIndex: value-prof.c\n===================================================================\n--- value-prof.c\t(revision 254348)\n+++ value-prof.c\t(working copy)\n@@ -1299,7 +1299,7 @@ check_ic_target (gcall *call_stmt, struc\n \n gcall *\n gimple_ic (gcall *icall_stmt, struct cgraph_node *direct_call,\n-\t   profile_probability prob, profile_count count, profile_count all)\n+\t   profile_probability prob)\n {\n   gcall *dcall_stmt;\n   gassign *load_stmt;\n@@ -1354,11 +1354,11 @@ gimple_ic (gcall *icall_stmt, struct cgr\n   /* Edge e_cd connects cond_bb to dcall_bb, etc; note the first letters. */\n   e_cd = split_block (cond_bb, cond_stmt);\n   dcall_bb = e_cd->dest;\n-  dcall_bb->count = count;\n+  dcall_bb->count = cond_bb->count.apply_probability (prob);\n \n   e_di = split_block (dcall_bb, dcall_stmt);\n   icall_bb = e_di->dest;\n-  icall_bb->count = all - count;\n+  icall_bb->count = cond_bb->count - dcall_bb->count;\n \n   /* Do not disturb existing EH edges from the indirect call.  */\n   if (!stmt_ends_bb_p (icall_stmt))\n@@ -1376,7 +1376,7 @@ gimple_ic (gcall *icall_stmt, struct cgr\n   if (e_ij != NULL)\n     {\n       join_bb = e_ij->dest;\n-      join_bb->count = all;\n+      join_bb->count = cond_bb->count;\n     }\n \n   e_cd->flags = (e_cd->flags & ~EDGE_FALLTHRU) | EDGE_TRUE_VALUE;\nIndex: value-prof.h\n===================================================================\n--- value-prof.h\t(revision 254348)\n+++ value-prof.h\t(working copy)\n@@ -90,8 +90,7 @@ void gimple_move_stmt_histograms (struct\n void verify_histograms (void);\n void free_histograms (function *);\n void stringop_block_profile (gimple *, unsigned int *, HOST_WIDE_INT *);\n-gcall *gimple_ic (gcall *, struct cgraph_node *, profile_probability,\n-\t\t  profile_count, profile_count);\n+gcall *gimple_ic (gcall *, struct cgraph_node *, profile_probability);\n bool check_ic_target (gcall *, struct cgraph_node *);","headers":{"Return-Path":"<gcc-patches-return-465779-incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list gcc-patches@gcc.gnu.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=gcc-patches-return-465779-incoming=patchwork.ozlabs.org@gcc.gnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tunprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org\n\theader.b=\"nbrIN3ST\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3ySZNG4tr8z9sNc\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri,  3 Nov 2017 06:07:34 +1100 (AEDT)","(qmail 478 invoked by alias); 2 Nov 2017 19:07:14 -0000","(qmail 130599 invoked by uid 89); 2 Nov 2017 19:07:13 -0000","from nikam.ms.mff.cuni.cz (HELO nikam.ms.mff.cuni.cz)\n\t(195.113.20.16) by sourceware.org\n\t(qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP;\n\tThu, 02 Nov 2017 19:06:55 +0000","by nikam.ms.mff.cuni.cz (Postfix, from userid 16202)\tid\n\t63650548EC5; Thu,  2 Nov 2017 20:06:52 +0100 (CET)"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:date\n\t:from:to:cc:subject:message-id:references:mime-version\n\t:content-type:in-reply-to; q=dns; s=default; b=UZTSuGgwViY/AmhA5\n\tStgB5NiJRPB6oNO+L3hzFmg4rxPl6jKB7yD/7NzNFOjXD68G+5C919lpJpCusXaA\n\tR9laPplJ8bAfDofMG8p7OiRYLqcprmlL7IFNHw/MBue1eQgsFN6p4VCkEFpn9LRb\n\t8XiuEI9MlKxHgYfFi7P75USdwU=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:date\n\t:from:to:cc:subject:message-id:references:mime-version\n\t:content-type:in-reply-to; s=default; bh=qvZCWaHkHIkguksA2R+1jVA\n\tNwz4=; b=nbrIN3ST8/v2QE1cHVECOPJOneYNt3Iyi3dT5hKXmDAl126vBxgeGMm\n\tm/zIlzyxDlA/YNb1TMwJQAedQ58LQdNnZCxCj1n4KN2OOR5uK3aCpWpEDp+4w8JM\n\ts5UnGbg0rO9ovtaGx18K9B2OfCVW7LmLO159G5OYh5H7ePSaI/Z0=","Mailing-List":"contact gcc-patches-help@gcc.gnu.org; run by ezmlm","Precedence":"bulk","List-Id":"<gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<mailto:gcc-patches-unsubscribe-incoming=patchwork.ozlabs.org@gcc.gnu.org>","List-Archive":"<http://gcc.gnu.org/ml/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-help@gcc.gnu.org>","Sender":"gcc-patches-owner@gcc.gnu.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-14.1 required=5.0 tests=AWL, BAYES_00,\n\tGIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS,\n\tKAM_LAZY_DOMAIN_SECURITY,\n\tRP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=","X-HELO":"nikam.ms.mff.cuni.cz","Date":"Thu, 2 Nov 2017 20:06:52 +0100","From":"Jan Hubicka <hubicka@ucw.cz>","To":"Martin =?iso-8859-2?q?Li=B9ka?= <mliska@suse.cz>","Cc":"gcc-patches@gcc.gnu.org","Subject":"Re: Drop frequencies from basic blocks","Message-ID":"<20171102190652.GB31407@kam.mff.cuni.cz>","References":"<20171102153225.GA53964@kam.mff.cuni.cz>\n\t<da7c915d-aa07-76d3-d79d-9e90419bbd79@suse.cz>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<da7c915d-aa07-76d3-d79d-9e90419bbd79@suse.cz>","User-Agent":"Mutt/1.5.23 (2014-03-12)"}},{"id":1798234,"web_url":"http://patchwork.ozlabs.org/comment/1798234/","msgid":"<89e2ec2f-12b7-af91-634e-82cc74f2183f@suse.cz>","list_archive_url":null,"date":"2017-11-02T20:26:21","subject":"Re: Drop frequencies from basic blocks","submitter":{"id":62010,"url":"http://patchwork.ozlabs.org/api/people/62010/","name":"Martin Liška","email":"mliska@suse.cz"},"content":"On 11/02/2017 08:06 PM, Jan Hubicka wrote:\n> Sorry, I must have used older diff file, because it is one of unfinished chnages I made today.\n> I am attaching correct diff.\n\n\nThank you. This one works for me, however I see various errors for postgres PGO:\n\ncd src/backend/replication/\nmarxin@marxinbox:~/Programming/postgres/src/backend/replication> gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -fprofile-use -I. -I. -I../../../src/include  -D_GNU_SOURCE   -c -o walsender.o walsender.c\n\nIn file included from walsender.c:56:0:\nwalsender.c: In function ‘XLogRead’:\n../../../src/include/access/xlog_internal.h:188:26: error: corrupted value profile: interval profile counter (0 out of 0) inconsistent with basic-block count (7531)\n      (uint32) ((logSegNo) % XLogSegmentsPerXLogId(wal_segsz_bytes)))\n               ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nwalsender.c:2367:4: note: in expansion of macro ‘XLogFilePath’\n     XLogFilePath(path, curFileTimeLine, sendSegNo, wal_segment_size);\n     ^~~~~~~~~~~~\n\n\nProblem is following:\n\nHere we estimate count:\n\nOld value = -1\nNew value = 7531\n0x0000000000aecb52 in estimate_bb_frequencies (force=force@entry=false) at ../../gcc/predict.c:3590\n3590\t\t    bb->count = count.guessed_local ();\n(gdb) bt\n#0  0x0000000000aecb52 in estimate_bb_frequencies (force=force@entry=false) at ../../gcc/predict.c:3590\n#1  0x0000000000af05a4 in tree_estimate_probability (dry_run=dry_run@entry=false) at ../../gcc/predict.c:2828\n#2  0x0000000000af0b9c in (anonymous namespace)::pass_profile::execute (this=<optimized out>, fun=0x7ffff5b9e790) at ../../gcc/predict.c:3722\n#3  0x0000000000ad23f1 in execute_one_pass (pass=pass@entry=0x210faf0) at ../../gcc/passes.c:2497\n#4  0x0000000000ad2cb1 in execute_pass_list_1 (pass=0x210faf0) at ../../gcc/passes.c:2586\n#5  0x0000000000ad2cc3 in execute_pass_list_1 (pass=0x210f470) at ../../gcc/passes.c:2587\n#6  0x0000000000ad2d05 in execute_pass_list (fn=<optimized out>, pass=<optimized out>) at ../../gcc/passes.c:2597\n#7  0x0000000000ad1631 in do_per_function_toporder (callback=callback@entry=0xad2cf0 <execute_pass_list(function*, opt_pass*)>, data=0x210f2f0) at ../../gcc/passes.c:1739\n#8  0x0000000000ad3387 in execute_ipa_pass_list (pass=0x210f290) at ../../gcc/passes.c:2937\n#9  0x000000000078fb42 in ipa_passes () at ../../gcc/cgraphunit.c:2423\n#10 symbol_table::compile (this=this@entry=0x7ffff6817100) at ../../gcc/cgraphunit.c:2558\n#11 0x00000000007923c7 in symbol_table::compile (this=0x7ffff6817100) at ../../gcc/cgraphunit.c:2719\n#12 symbol_table::finalize_compilation_unit (this=0x7ffff6817100) at ../../gcc/cgraphunit.c:2716\n#13 0x0000000000bb20d3 in compile_file () at ../../gcc/toplev.c:479\n#14 0x00000000005d7fc5 in do_compile () at ../../gcc/toplev.c:2059\n#15 toplev::main (this=this@entry=0x7fffffffd85e, argc=<optimized out>, argc@entry=38, argv=<optimized out>, argv@entry=0x7fffffffd958) at ../../gcc/toplev.c:2194\n#16 0x00000000005da46b in main (argc=38, argv=0x7fffffffd958) at ../../gcc/main.c:39\n\nAnd later on we check it with real value of an interval counter:\n\nBreakpoint 1, error_at (loc=2147497451, gmsgid=0x1605208 \"corrupted value profile: %s profile counter (%d out of %d) inconsistent with basic-block count (%d)\") at ../../gcc/diagnostic.c:1354\n1354\t{\n(gdb) bt\n#0  error_at (loc=2147497451, gmsgid=0x1605208 \"corrupted value profile: %s profile counter (%d out of %d) inconsistent with basic-block count (%d)\") at ../../gcc/diagnostic.c:1354\n#1  0x0000000000eae5b9 in check_counter (stmt=0x7ffff58359f8, name=0x16052fc \"interval\", count=0x7fffffffd5a8, all=0x7fffffffd5c0, bb_count_d=...) at ../../gcc/value-prof.c:607\n#2  0x0000000000eafe95 in gimple_mod_subtract_transform (si=0x7fffffffd640) at ../../gcc/value-prof.c:1133\n#3  0x0000000000eae709 in gimple_value_profile_transformations () at ../../gcc/value-prof.c:658\n#4  0x0000000000ca712c in tree_profiling () at ../../gcc/tree-profile.c:687\n#5  (anonymous namespace)::pass_ipa_tree_profile::execute (this=<optimized out>) at ../../gcc/tree-profile.c:780\n#6  0x0000000000ad23f1 in execute_one_pass (pass=pass@entry=0x2110350) at ../../gcc/passes.c:2497\n#7  0x0000000000ad33f2 in execute_ipa_pass_list (pass=0x2110350) at ../../gcc/passes.c:2932\n#8  0x000000000078fb42 in ipa_passes () at ../../gcc/cgraphunit.c:2423\n#9  symbol_table::compile (this=this@entry=0x7ffff6817100) at ../../gcc/cgraphunit.c:2558\n#10 0x00000000007923c7 in symbol_table::compile (this=0x7ffff6817100) at ../../gcc/cgraphunit.c:2719\n#11 symbol_table::finalize_compilation_unit (this=0x7ffff6817100) at ../../gcc/cgraphunit.c:2716\n#12 0x0000000000bb20d3 in compile_file () at ../../gcc/toplev.c:479\n#13 0x00000000005d7fc5 in do_compile () at ../../gcc/toplev.c:2059\n#14 toplev::main (this=this@entry=0x7fffffffd85e, argc=<optimized out>, argc@entry=38, argv=<optimized out>, argv@entry=0x7fffffffd958) at ../../gcc/toplev.c:2194\n#15 0x00000000005da46b in main (argc=38, argv=0x7fffffffd958) at ../../gcc/main.c:39\n\nCan you please take a look? Or will you need a reproducer?\n\nThank you,\nMartin","headers":{"Return-Path":"<gcc-patches-return-465789-incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list gcc-patches@gcc.gnu.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=gcc-patches-return-465789-incoming=patchwork.ozlabs.org@gcc.gnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tunprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org\n\theader.b=\"jWxWs9oK\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3ySc7K5SP8z9sBd\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri,  3 Nov 2017 07:26:35 +1100 (AEDT)","(qmail 61264 invoked by alias); 2 Nov 2017 20:26:28 -0000","(qmail 61254 invoked by uid 89); 2 Nov 2017 20:26:27 -0000","from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by\n\tsourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP;\n\tThu, 02 Nov 2017 20:26:26 +0000","from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254])\tby\n\tmx2.suse.de (Postfix) with ESMTP id A6766AE98;\n\tThu,  2 Nov 2017 20:26:23 +0000 (UTC)"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender\n\t:subject:to:cc:references:from:message-id:date:mime-version\n\t:in-reply-to:content-type:content-transfer-encoding; q=dns; s=\n\tdefault; b=SfKSa0+y78BZNoZWNnmjEHC1JADtVMrg6P2bh86z527AjniSQAf3J\n\tLnD+tiaF2jf6TsCts9JLYoYsvZ0azbMmw/7vjkFyaqI48kc7RiSt/7UOD7UcFu3Q\n\tNZJptIMPoM8a7adbou0VPfPAjBmZljx3LQMmhjoCYdKDqoi4MSfv7w=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender\n\t:subject:to:cc:references:from:message-id:date:mime-version\n\t:in-reply-to:content-type:content-transfer-encoding; s=default;\n\tbh=iOQ0Q7z4TFL4TAgSKTrKkJOMmXY=; b=jWxWs9oK3tkzokoE0QT2athTSg0o\n\t2KF3Ib8MTV7fEkTMdLcTEBl2XnEs19qeYB/QAbPQYAhWh1xjMvhWLojHqtMfjW2W\n\t3Kk8xtP2JkhsowbbATcyEaG+zBPjWHWo31dGVnrCzZHeEyTeeJJuso4ct0lza212\n\tGnkBedS/xLV4GnU=","Mailing-List":"contact gcc-patches-help@gcc.gnu.org; run by ezmlm","Precedence":"bulk","List-Id":"<gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<mailto:gcc-patches-unsubscribe-incoming=patchwork.ozlabs.org@gcc.gnu.org>","List-Archive":"<http://gcc.gnu.org/ml/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-help@gcc.gnu.org>","Sender":"gcc-patches-owner@gcc.gnu.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-1.9 required=5.0 tests=BAYES_00,\n\tSPF_PASS autolearn=ham version=3.3.2 spammy=","X-HELO":"mx2.suse.de","Subject":"Re: Drop frequencies from basic blocks","To":"Jan Hubicka <hubicka@ucw.cz>","Cc":"gcc-patches@gcc.gnu.org","References":"<20171102153225.GA53964@kam.mff.cuni.cz>\n\t<da7c915d-aa07-76d3-d79d-9e90419bbd79@suse.cz>\n\t<20171102190652.GB31407@kam.mff.cuni.cz>","From":"=?utf-8?q?Martin_Li=C5=A1ka?= <mliska@suse.cz>","Message-ID":"<89e2ec2f-12b7-af91-634e-82cc74f2183f@suse.cz>","Date":"Thu, 2 Nov 2017 21:26:21 +0100","User-Agent":"Mozilla/5.0 (X11; Linux x86_64;\n\trv:52.0) Gecko/20100101 Thunderbird/52.4.0","MIME-Version":"1.0","In-Reply-To":"<20171102190652.GB31407@kam.mff.cuni.cz>","Content-Type":"text/plain; charset=utf-8; format=flowed","Content-Transfer-Encoding":"8bit","X-IsSubscribed":"yes"}},{"id":1798263,"web_url":"http://patchwork.ozlabs.org/comment/1798263/","msgid":"<7ab9b7b2-1c71-3700-82be-0f1de795ec51@suse.cz>","list_archive_url":null,"date":"2017-11-02T21:03:23","subject":"Re: Drop frequencies from basic blocks","submitter":{"id":62010,"url":"http://patchwork.ozlabs.org/api/people/62010/","name":"Martin Liška","email":"mliska@suse.cz"},"content":"Can be also seen in GCC PGO:\n\nchecking for ssize_t... ../../libdecnumber/decNumber.c: In function ‘decDecap’:\n../../libdecnumber/decNumber.c:7640:25: error: corrupted value profile: interval profile counter (0 out of 0) inconsistent with basic-block count (4356)\n    if (cut!=DECDPUN) *msu%=powers[cut]; /* clear left digits */\n                          ^~\nno\nchecking unwind.h usability... ../../libdecnumber/decNumber.c: In function ‘decNumberRotate’:\n../../libdecnumber/decNumber.c:2526:9: error: corrupted value profile: interval profile counter (0 out of 0) inconsistent with basic-block count (8)\n     uInt save=res->lsu[0]%powers[shift];   /* save low digit(s) */\n          ^~~~\n../../libdecnumber/decNumber.c:2529:11: error: corrupted value profile: interval profile counter (0 out of 0) inconsistent with basic-block count (4)\n       uInt rem=save%powers[shift-msudigits];/* split save */\n            ^~~\n../../libdecnumber/decNumber.c:2546:11: error: corrupted value profile: interval profile counter (0 out of 0) inconsistent with basic-block count (2)\n       uInt save=res->lsu[0]%powers[shift];  /* save low digit(s) */\n            ^~~~","headers":{"Return-Path":"<gcc-patches-return-465792-incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list gcc-patches@gcc.gnu.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=gcc-patches-return-465792-incoming=patchwork.ozlabs.org@gcc.gnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tunprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org\n\theader.b=\"LAm7W0RL\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3yScxz6Hq7z9s03\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri,  3 Nov 2017 08:03:34 +1100 (AEDT)","(qmail 12121 invoked by alias); 2 Nov 2017 21:03:28 -0000","(qmail 12109 invoked by uid 89); 2 Nov 2017 21:03:27 -0000","from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by\n\tsourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP;\n\tThu, 02 Nov 2017 21:03:26 +0000","from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254])\tby\n\tmx2.suse.de (Postfix) with ESMTP id ADD10AAC3;\n\tThu,  2 Nov 2017 21:03:24 +0000 (UTC)"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender\n\t:subject:from:to:cc:references:message-id:date:mime-version\n\t:in-reply-to:content-type:content-transfer-encoding; q=dns; s=\n\tdefault; b=FSkpSHgpIr8AiYV42jE+0otIDmMJQLwKjj6wrTMpyNL8FWhZyrSL7\n\tqWmBigxryoWk8MkrCoruRZ4Ae6nZoij8daZCXFiXHLHBvYAQuxiEIvWL4Jk8fYdo\n\tBjixPyFdbfDPdSkxT77yqMXgkGnMRoJrs/6tnwFYKZKwmjtgw+JBeY=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender\n\t:subject:from:to:cc:references:message-id:date:mime-version\n\t:in-reply-to:content-type:content-transfer-encoding; s=default;\n\tbh=C6YfmOHFxRrOes0SanlkV+VNI7E=; b=LAm7W0RLFeoDmZ2LD3NChX7hPr+f\n\t/TUeQ07duQEofNGwRed+EFJTw/XjM9llPcGZBoFT/t82X7yBRn4KBXx1ozeZ/L5r\n\taeRlmaauYGuuk2y7uEUb1SXOSjYC0VUDYRC+t3Jn33KNTZQtqTo44UHG66DVDOci\n\t/sAojA01ryto564=","Mailing-List":"contact gcc-patches-help@gcc.gnu.org; run by ezmlm","Precedence":"bulk","List-Id":"<gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<mailto:gcc-patches-unsubscribe-incoming=patchwork.ozlabs.org@gcc.gnu.org>","List-Archive":"<http://gcc.gnu.org/ml/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-help@gcc.gnu.org>","Sender":"gcc-patches-owner@gcc.gnu.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-1.9 required=5.0 tests=BAYES_00,\n\tSPF_PASS autolearn=ham version=3.3.2 spammy=powers, usability,\n\tHContent-Transfer-Encoding:8bit","X-HELO":"mx2.suse.de","Subject":"Re: Drop frequencies from basic blocks","From":"=?utf-8?q?Martin_Li=C5=A1ka?= <mliska@suse.cz>","To":"Jan Hubicka <hubicka@ucw.cz>","Cc":"gcc-patches@gcc.gnu.org","References":"<20171102153225.GA53964@kam.mff.cuni.cz>\n\t<da7c915d-aa07-76d3-d79d-9e90419bbd79@suse.cz>\n\t<20171102190652.GB31407@kam.mff.cuni.cz>\n\t<89e2ec2f-12b7-af91-634e-82cc74f2183f@suse.cz>","Message-ID":"<7ab9b7b2-1c71-3700-82be-0f1de795ec51@suse.cz>","Date":"Thu, 2 Nov 2017 22:03:23 +0100","User-Agent":"Mozilla/5.0 (X11; Linux x86_64;\n\trv:52.0) Gecko/20100101 Thunderbird/52.4.0","MIME-Version":"1.0","In-Reply-To":"<89e2ec2f-12b7-af91-634e-82cc74f2183f@suse.cz>","Content-Type":"text/plain; charset=utf-8; format=flowed","Content-Transfer-Encoding":"8bit","X-IsSubscribed":"yes"}},{"id":1798266,"web_url":"http://patchwork.ozlabs.org/comment/1798266/","msgid":"<8b1ca935-223d-29b7-aecf-d4850efaf7a7@suse.cz>","list_archive_url":null,"date":"2017-11-02T21:06:48","subject":"Re: Drop frequencies from basic blocks","submitter":{"id":62010,"url":"http://patchwork.ozlabs.org/api/people/62010/","name":"Martin Liška","email":"mliska@suse.cz"},"content":"Apart from that I also see this GCC PGO:\n\n../../libiberty/pex-unix.c:789:1: warning: Missing counts for called function pex_child_error.isra.1/69\n  }\n  ^\nduring IPA pass: inline\n../../libiberty/pex-unix.c: In function ‘pex_child_error.isra.1’:\n../../libiberty/pex-unix.c:373:1: internal compiler error: in operator>, at profile-count.h:821\n  pex_child_error (struct pex_obj *obj, const char *executable,\n  ^~~~~~~~~~~~~~~\n0x13b2e53 profile_count::operator>(long) const\n\t../../gcc/profile-count.h:821\n0x13b2e53 inline_transform(cgraph_node*)\n\t../../gcc/ipa-inline-transform.c:680\n0x5d8dae execute_one_ipa_transform_pass\n\t../../gcc/passes.c:2239\n0x5d8dae execute_all_ipa_transforms()\n\t../../gcc/passes.c:2281\n0x894e4f cgraph_node::expand()\n\t../../gcc/cgraphunit.c:2132\n0x8961e0 expand_all_functions\n\t../../gcc/cgraphunit.c:2275\n0x8961e0 symbol_table::compile()\n\t../../gcc/cgraphunit.c:2623\n0x898ac6 symbol_table::compile()\n\t../../gcc/cgraphunit.c:2719\n0x898ac6 symbol_table::finalize_compilation_unit()\n\t../../gcc/cgraphunit.c:2716\n\nFeel free to ask me about details if necessary.\n\nMartin","headers":{"Return-Path":"<gcc-patches-return-465793-incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list gcc-patches@gcc.gnu.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=gcc-patches-return-465793-incoming=patchwork.ozlabs.org@gcc.gnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tunprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org\n\theader.b=\"QMjG9yEu\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3ySd21351nz9sQl\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri,  3 Nov 2017 08:07:04 +1100 (AEDT)","(qmail 74102 invoked by alias); 2 Nov 2017 21:06:53 -0000","(qmail 73688 invoked by uid 89); 2 Nov 2017 21:06:53 -0000","from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by\n\tsourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP;\n\tThu, 02 Nov 2017 21:06:52 +0000","from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254])\tby\n\tmx2.suse.de (Postfix) with ESMTP id 89F92AD49;\n\tThu,  2 Nov 2017 21:06:48 +0000 (UTC)"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender\n\t:subject:from:to:cc:references:message-id:date:mime-version\n\t:in-reply-to:content-type:content-transfer-encoding; q=dns; s=\n\tdefault; b=L4mzuuJe64LvYxvYbPlvNnNBo+ujC6djCi+8Z0hZBR1PCBfzmm4MQ\n\tn9+2slf0w/t+CQVAOu7lEdj9oI3WioMQsyvk0gQli6y0/K0pnCY4+eeY6vaDro68\n\tvddl3SUvrnsTlUNh8LTggwVpen+HmBNRQ7fVWkGVfscrHvGIWCTOuM=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender\n\t:subject:from:to:cc:references:message-id:date:mime-version\n\t:in-reply-to:content-type:content-transfer-encoding; s=default;\n\tbh=WMYs7hz9dLqPrbyf7uPHA/ulEjg=; b=QMjG9yEuParHupKMHQvV0O+iQCBL\n\tVA6OoofczseA9HU3T+n3eobtS8yFIo89sZxASb/RzwvOdfHzbS1eZO9nIdGJ4AlU\n\trM52IvNI+5byN0HYxTgHCxQ4v++JRtFvFOpysdZL1tkap20/c0dcSzfI3QKEOffw\n\t3GfLwqEnAisBWyY=","Mailing-List":"contact gcc-patches-help@gcc.gnu.org; run by ezmlm","Precedence":"bulk","List-Id":"<gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<mailto:gcc-patches-unsubscribe-incoming=patchwork.ozlabs.org@gcc.gnu.org>","List-Archive":"<http://gcc.gnu.org/ml/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-help@gcc.gnu.org>","Sender":"gcc-patches-owner@gcc.gnu.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-1.9 required=5.0 tests=BAYES_00,\n\tSPF_PASS autolearn=ham version=3.3.2 spammy=821,\n\tHContent-Transfer-Encoding:8bit","X-HELO":"mx2.suse.de","Subject":"Re: Drop frequencies from basic blocks","From":"=?utf-8?q?Martin_Li=C5=A1ka?= <mliska@suse.cz>","To":"Jan Hubicka <hubicka@ucw.cz>","Cc":"gcc-patches@gcc.gnu.org","References":"<20171102153225.GA53964@kam.mff.cuni.cz>\n\t<da7c915d-aa07-76d3-d79d-9e90419bbd79@suse.cz>\n\t<20171102190652.GB31407@kam.mff.cuni.cz>\n\t<89e2ec2f-12b7-af91-634e-82cc74f2183f@suse.cz>\n\t<7ab9b7b2-1c71-3700-82be-0f1de795ec51@suse.cz>","Message-ID":"<8b1ca935-223d-29b7-aecf-d4850efaf7a7@suse.cz>","Date":"Thu, 2 Nov 2017 22:06:48 +0100","User-Agent":"Mozilla/5.0 (X11; Linux x86_64;\n\trv:52.0) Gecko/20100101 Thunderbird/52.4.0","MIME-Version":"1.0","In-Reply-To":"<7ab9b7b2-1c71-3700-82be-0f1de795ec51@suse.cz>","Content-Type":"text/plain; charset=utf-8; format=flowed","Content-Transfer-Encoding":"8bit","X-IsSubscribed":"yes"}},{"id":1798335,"web_url":"http://patchwork.ozlabs.org/comment/1798335/","msgid":"<20171102232729.GC31407@kam.mff.cuni.cz>","list_archive_url":null,"date":"2017-11-02T23:27:29","subject":"Re: Drop frequencies from basic blocks","submitter":{"id":4327,"url":"http://patchwork.ozlabs.org/api/people/4327/","name":"Jan Hubicka","email":"hubicka@ucw.cz"},"content":"> Can be also seen in GCC PGO:\n> \n> checking for ssize_t... ../../libdecnumber/decNumber.c: In function ‘decDecap’:\n> ../../libdecnumber/decNumber.c:7640:25: error: corrupted value profile: interval profile counter (0 out of 0) inconsistent with basic-block count (4356)\n>    if (cut!=DECDPUN) *msu%=powers[cut]; /* clear left digits */\n\nHmm, I have restarted profiledbootstrap and it also reproduces to me.\nIt is odd that those counters are 0 in basic block that is executed. Having small\nreproducer would be cool, but I will try to debug it from libdecnumber.\n\nThat other ICE is another issue with Theresa's code for dropping profiles that\nare mismatched (it is only place we mismatch profile in GCC).  I will take a look\nwhat went wrong here.\n\nThanks,\nHonza\n>                          ^~\n> no\n> checking unwind.h usability... ../../libdecnumber/decNumber.c: In function ‘decNumberRotate’:\n> ../../libdecnumber/decNumber.c:2526:9: error: corrupted value profile: interval profile counter (0 out of 0) inconsistent with basic-block count (8)\n>     uInt save=res->lsu[0]%powers[shift];   /* save low digit(s) */\n>          ^~~~\n> ../../libdecnumber/decNumber.c:2529:11: error: corrupted value profile: interval profile counter (0 out of 0) inconsistent with basic-block count (4)\n>       uInt rem=save%powers[shift-msudigits];/* split save */\n>            ^~~\n> ../../libdecnumber/decNumber.c:2546:11: error: corrupted value profile: interval profile counter (0 out of 0) inconsistent with basic-block count (2)\n>       uInt save=res->lsu[0]%powers[shift];  /* save low digit(s) */\n>            ^~~~","headers":{"Return-Path":"<gcc-patches-return-465800-incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list gcc-patches@gcc.gnu.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=gcc-patches-return-465800-incoming=patchwork.ozlabs.org@gcc.gnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tunprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org\n\theader.b=\"a2kb7t1e\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3ySh8J3M9Pz9sPm\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri,  3 Nov 2017 10:27:43 +1100 (AEDT)","(qmail 66003 invoked by alias); 2 Nov 2017 23:27:34 -0000","(qmail 65994 invoked by uid 89); 2 Nov 2017 23:27:34 -0000","from nikam.ms.mff.cuni.cz (HELO nikam.ms.mff.cuni.cz)\n\t(195.113.20.16) by sourceware.org\n\t(qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP;\n\tThu, 02 Nov 2017 23:27:32 +0000","by nikam.ms.mff.cuni.cz (Postfix, from userid 16202)\tid\n\tCA211548FEE; Fri,  3 Nov 2017 00:27:29 +0100 (CET)"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:date\n\t:from:to:cc:subject:message-id:references:mime-version\n\t:content-type:content-transfer-encoding:in-reply-to; q=dns; s=\n\tdefault; b=d9s0/lSZKKPdPlonrpqEw4Wj5lpTOj0jY3s8Te6fEvsVigh6Wf8If\n\tkNgv4BStmVE6yM5FjA0ysV13a3ad95ZhVgDLJFzzArymPQgvYnpyeBUqbpDog9WM\n\tWKJxb/qRnQ4FyD3wxj7g3oJzQAg3zDWlnh/iIPz9EBnQCzcXQM2ZKQ=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:date\n\t:from:to:cc:subject:message-id:references:mime-version\n\t:content-type:content-transfer-encoding:in-reply-to; s=default;\n\tbh=cOVHrFtLMZ+IgJkiRyaHNG8eozI=; b=a2kb7t1eRGQYJppFPQV6OIxoM4+o\n\tyA2q2eEYD5xoGfc0A+0OMdPAfskbZDev5uPYUkpy4wzuEN6ccvvs6hE04jZA2xkN\n\t+unqZxBEcjxV+bGjr9ncimSS7H7KbDQr9ILDRb5JUP9ZRRclNlDQI0IPqPzna9aH\n\tv8xJ13ozaFJrWG4=","Mailing-List":"contact gcc-patches-help@gcc.gnu.org; run by ezmlm","Precedence":"bulk","List-Id":"<gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<mailto:gcc-patches-unsubscribe-incoming=patchwork.ozlabs.org@gcc.gnu.org>","List-Archive":"<http://gcc.gnu.org/ml/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-help@gcc.gnu.org>","Sender":"gcc-patches-owner@gcc.gnu.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-1.3 required=5.0 tests=AWL, BAYES_00,\n\tKAM_LAZY_DOMAIN_SECURITY,\n\tRP_MATCHES_RCVD autolearn=no version=3.3.2\n\tspammy=HContent-Transfer-Encoding:8bit","X-HELO":"nikam.ms.mff.cuni.cz","Date":"Fri, 3 Nov 2017 00:27:29 +0100","From":"Jan Hubicka <hubicka@ucw.cz>","To":"Martin =?iso-8859-2?q?Li=B9ka?= <mliska@suse.cz>","Cc":"gcc-patches@gcc.gnu.org","Subject":"Re: Drop frequencies from basic blocks","Message-ID":"<20171102232729.GC31407@kam.mff.cuni.cz>","References":"<20171102153225.GA53964@kam.mff.cuni.cz>\n\t<da7c915d-aa07-76d3-d79d-9e90419bbd79@suse.cz>\n\t<20171102190652.GB31407@kam.mff.cuni.cz>\n\t<89e2ec2f-12b7-af91-634e-82cc74f2183f@suse.cz>\n\t<7ab9b7b2-1c71-3700-82be-0f1de795ec51@suse.cz>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<7ab9b7b2-1c71-3700-82be-0f1de795ec51@suse.cz>","User-Agent":"Mutt/1.5.23 (2014-03-12)"}},{"id":1798695,"web_url":"http://patchwork.ozlabs.org/comment/1798695/","msgid":"<20171103154845.GA3108@kam.mff.cuni.cz>","list_archive_url":null,"date":"2017-11-03T15:48:45","subject":"Re: Drop frequencies from basic blocks","submitter":{"id":4327,"url":"http://patchwork.ozlabs.org/api/people/4327/","name":"Jan Hubicka","email":"hubicka@ucw.cz"},"content":"Hello,\nthis is updated patch which I have comitted after profiledbootstrapping x86-64\n\n\n2017-11-02  Jan Hubicka  <hubicka@ucw.cz>\n\n\t* asan.c (create_cond_insert_point): Maintain profile.\n\t* ipa-utils.c (ipa_merge_profiles): Be sure only IPA profiles are\n\tmerged.\n\t* basic-block.h (struct basic_block_def): Remove frequency.\n\t(EDGE_FREQUENCY): Use to_frequency\n\t* bb-reorder.c (push_to_next_round_p): Use only IPA counts for global\n\theuristics.\n\t(find_traces): Update to use to_frequency.\n\t(find_traces_1_round): Likewise; use only IPA counts.\n\t(bb_to_key): Likewise.\n\t(connect_traces): Use IPA counts only.\n\t(copy_bb_p): Update to use to_frequency.\n\t(fix_up_crossing_landing_pad): Likewise.\n\t(sanitize_hot_paths): Likewise.\n\t* bt-load.c (basic_block_freq): Likewise.\n\t* cfg.c (init_flow): Set count_max to uninitialized.\n\t(check_bb_profile): Remove frequencies; check counts.\n\t(dump_bb_info): Do not dump frequencies.\n\t(update_bb_profile_for_threading): Update counts only.\n\t(scale_bbs_frequencies_int): Likewise.\n\t(MAX_SAFE_MULTIPLIER): Remove.\n\t(scale_bbs_frequencies_gcov_type): Update counts only.\n\t(scale_bbs_frequencies_profile_count): Update counts only.\n\t(scale_bbs_frequencies): Update counts only.\n\t* cfg.h (struct control_flow_graph): Add count-max.\n\t(update_bb_profile_for_threading): Update prototype.\n\t* cfgbuild.c (find_bb_boundaries): Do not update frequencies.\n\t(find_many_sub_basic_blocks): Likewise.\n\t* cfgcleanup.c (try_forward_edges): Likewise.\n\t(try_crossjump_to_edge): Likewise.\n\t* cfgexpand.c (expand_gimple_cond): Likewise.\n\t(expand_gimple_tailcall): Likewise.\n\t(construct_init_block): Likewise.\n\t(construct_exit_block): Likewise.\n\t* cfghooks.c (verify_flow_info): Check consistency of counts.\n\t(dump_bb_for_graph): Do not dump frequencies.\n\t(split_block_1): Do not update frequencies.\n\t(split_edge): Do not update frequencies.\n\t(make_forwarder_block): Do not update frequencies.\n\t(duplicate_block): Do not update frequencies.\n\t(account_profile_record): Do not update frequencies.\n\t* cfgloop.c (find_subloop_latch_edge_by_profile): Use IPA counts\n\tfor global heuristics.\n\t* cfgloopanal.c (average_num_loop_insns): Update to use to_frequency.\n\t(expected_loop_iterations_unbounded): Use counts only.\n\t* cfgloopmanip.c (scale_loop_profile): Simplify.\n\t(create_empty_loop_on_edge): Simplify\n\t(loopify): Simplify\n\t(duplicate_loop_to_header_edge): Simplify\n\t* cfgrtl.c (force_nonfallthru_and_redirect): Update profile.\n\t(update_br_prob_note): Take care of removing note when profile\n\tbecomes undefined.\n\t(relink_block_chain): Do not dump frequency.\n\t(rtl_account_profile_record): Use to_frequency.\n\t* cgraph.c (symbol_table::create_edge): Convert count to ipa count.\n\t(cgraph_edge::redirect_call_stmt_to_calle): Conver tcount to ipa count.\n\t(cgraph_update_edges_for_call_stmt_node): Likewise.\n\t(cgraph_edge::verify_count_and_frequency): Update.\n\t(cgraph_node::verify_node): Temporarily disable frequency verification.\n\t* cgraphbuild.c (compute_call_stmt_bb_frequency): Use\n\tto_cgraph_frequency.\n\t(cgraph_edge::rebuild_edges): Convert to ipa counts.\n\t* cgraphunit.c (init_lowered_empty_function): Do not initialize\n\tfrequencies.\n\t(cgraph_node::expand_thunk): Update profile.\n\t* except.c (dw2_build_landing_pads): Do not update frequency.\n\t* final.c (compute_alignments): Use to_frequency.\n\t(dump_basic_block_info): Do not dump frequency.\n\t* gimple-pretty-print.c (dump_profile): Do not dump frequency.\n\t(dump_gimple_bb_header): Do not dump frequency.\n\t* gimple-ssa-isolate-paths.c (isolate_path): Do not update frequency;\n\tdo update count.\n\t* gimple-streamer-in.c (input_bb): Do not stream frequency.\n\t* gimple-streamer-out.c (output_bb): Do not stream frequency.\n\t* haifa-sched.c (sched_pressure_start_bb): Use to_freuqency.\n\t(init_before_recovery): Do not update frequency.\n\t(sched_create_recovery_edges): Do not update frequency.\n\t* hsa-gen.c (convert_switch_statements): Do not update frequency.\n\t* ipa-cp.c (ipcp_propagate_stage): Update search for max_count.\n\t(ipa_cp_c_finalize): Set max_count to uninitialized.\n\t* ipa-fnsummary.c (get_minimal_bb): Use counts.\n\t(param_change_prob): Use counts.\n\t* ipa-profile.c (ipa_profile_generate_summary): Do not summarize\n\tlocal profiles.\n\t* ipa-split.c (consider_split): Use to_frequency.\n\t(split_function): Use to_frequency.\n\t* ira-build.c (loop_compare_func): Likewise.\n\t(mark_loops_for_removal): Likewise.\n\t(mark_all_loops_for_removal): Likewise.\n\t* loop-doloop.c (doloop_modify): Do not update frequency.\n\t* loop-unroll.c (unroll_loop_runtime_iterations): Do not update\n\tfrequency.\n\t* lto-streamer-in.c (input_function): Update count_max.\n\t* omp-expand.c (expand_omp_taskreg): Update count_max.\n\t* omp-simd-clone.c (simd_clone_adjust): Update profile.\n\t* predict.c (maybe_hot_frequency_p): Use to_frequency.\n\t(maybe_hot_count_p): Use ipa counts only.\n\t(maybe_hot_bb_p): Simplify.\n\t(maybe_hot_edge_p): Simplify.\n\t(probably_never_executed): Do not take frequency argument.\n\t(probably_never_executed_bb_p): Do not pass frequency.\n\t(probably_never_executed_edge_p): Likewise.\n\t(combine_predictions_for_bb): Check that profile is nonzero.\n\t(propagate_freq): Do not set frequency.\n\t(drop_profile): Simplify.\n\t(counts_to_freqs): Simplify.\n\t(expensive_function_p): Use to_frequency.\n\t(propagate_unlikely_bbs_forward): Simplify.\n\t(determine_unlikely_bbs): Simplify.\n\t(estimate_bb_frequencies): Add hack to silence graphite issues.\n\t(compute_function_frequency): Use ipa counts.\n\t(pass_profile::execute): Update.\n\t(rebuild_frequencies): Use counts only.\n\t(force_edge_cold): Use counts only.\n\t* profile-count.c (profile_count::dump): Dump new count types.\n\t(profile_count::differs_from_p): Check compatiblity.\n\t(profile_count::to_frequency): New function.\n\t(profile_count::to_cgraph_frequency): New function.\n\t* profile-count.h (struct function): Declare.\n\t(enum profile_quality): Add profile_guessed_local and\n\tprofile_guessed_global0.\n\t(class profile_proability): Decrease number of bits to 29;\n\tupdate from_reg_br_prob_note and to_reg_br_prob_note.\n\t(class profile_count: Update comment; decrease number of bits\n\tto 61. Check compatibility.\n\t(profile_count::compatible_p): New private member function.\n\t(profile_count::ipa_p): New member function.\n\t(profile_count::operator<): Handle global zero correctly.\n\t(profile_count::operator>): Handle global zero correctly.\n\t(profile_count::operator<=): Handle global zero correctly.\n\t(profile_count::operator>=): Handle global zero correctly.\n\t(profile_count::nonzero_p): New member function.\n\t(profile_count::force_nonzero): New member function.\n\t(profile_count::max): New member function.\n\t(profile_count::apply_scale): Handle IPA scalling.\n\t(profile_count::guessed_local): New member function.\n\t(profile_count::global0): New member function.\n\t(profile_count::ipa): New member function.\n\t(profile_count::to_frequency): Declare.\n\t(profile_count::to_cgraph_frequency): Declare.\n\t* profile.c (OVERLAP_BASE): Delete.\n\t(compute_frequency_overlap): Delete.\n\t(compute_branch_probabilities): Do not use compute_frequency_overlap.\n\t* regs.h (REG_FREQ_FROM_BB): Use to_frequency.\n\t* sched-ebb.c (rank): Use counts only.\n\t* shrink-wrap.c (handle_simple_exit): Use counts only.\n\t(try_shrink_wrapping): Use counts only.\n\t(place_prologue_for_one_component): Use counts only.\n\t* tracer.c (find_best_predecessor): Use to_frequency.\n\t(find_trace): Use to_frequency.\n\t(tail_duplicate): Use to_frequency.\n\t* trans-mem.c (expand_transaction): Do not update frequency.\n\t* tree-call-cdce.c: Do not update frequency. \n\t* tree-cfg.c (gimple_find_sub_bbs): Likewise.\n\t(gimple_merge_blocks): Likewise.\n\t(gimple_split_edge): Likewise.\n\t(gimple_duplicate_sese_region): Likewise.\n\t(gimple_duplicate_sese_tail): Likewise.\n\t(move_sese_region_to_fn): Likewise.\n\t(gimple_account_profile_record): Likewise.\n\t(insert_cond_bb): Likewise.\n\t* tree-complex.c (expand_complex_div_wide): Likewise.\n\t* tree-eh.c (lower_resx): Update profile.\n\t* tree-inline.c (copy_bb): Simplify count scaling; do not scale\n\tfrequencies.\n\t(initialize_cfun): Do not initialize frequencies\n\t(freqs_to_counts): Delete.\n\t(copy_cfg_body): Ignore count parameter.\n\t(copy_body): Update.\n\t(expand_call_inline): Update count_max.\n\t(optimize_inline_calls): Update count_max.\n\t(tree_function_versioning): Update count_max.\n\t* tree-ssa-coalesce.c (coalesce_cost_bb): Use to_frequency.\n\t* tree-ssa-ifcombine.c (update_profile_after_ifcombine): Do not update\n\tfrequency.\n\t* tree-ssa-loop-im.c (execute_sm_if_changed): Use counts only.\n\t* tree-ssa-loop-ivcanon.c (unloop_loops): Do not update freuqency.\n\t(try_peel_loop): Likewise.\n\t* tree-ssa-loop-ivopts.c (get_scaled_computation_cost_at): Use\n\tto_frequency.\n\t* tree-ssa-loop-manip.c (niter_for_unrolled_loop): Pass -1.\n\t(tree_transform_and_unroll_loop): Do not use frequencies\n\t* tree-ssa-loop-niter.c (estimate_numbers_of_iterations):\n\tUse reliable prediction only.\n\t* tree-ssa-loop-unswitch.c (hoist_guard): Do not use frequencies.\n\t* tree-ssa-sink.c (select_best_block): Use to_frequency.\n\t* tree-ssa-tail-merge.c (replace_block_by): Temporarily disable\n\tprobability scaling.\n\t* tree-ssa-threadupdate.c (create_block_for_threading): Do\n\tnot update frequency\n\t(any_remaining_duplicated_blocks): Likewise.\n\t(update_profile): Likewise.\n\t(estimated_freqs_path): Delete.\n\t(freqs_to_counts_path): Delete.\n\t(clear_counts_path): Delete.\n\t(ssa_fix_duplicate_block_edges): Likewise.\n\t(duplicate_thread_path): Likewise.\n\t* tree-switch-conversion.c (gen_inbound_check): Use counts.\n\t* tree-tailcall.c (decrease_profile): Do not update frequency.\n\t(eliminate_tail_call): Likewise.\n\t* tree-vect-loop-manip.c (vect_do_peeling): Likewise.\n\t* tree-vect-loop.c (scale_profile_for_vect_loop): Likewise.\n\t(optimize_mask_stores): Likewise.\n\t* tree-vect-stmts.c (vectorizable_simd_clone_call): Likewise.\n\t* ubsan.c (ubsan_expand_null_ifn): Update profile.\n\t(ubsan_expand_ptr_ifn): Update profile.\n\t* value-prof.c (gimple_ic): Simplify.\n\t* value-prof.h (gimple_ic): Update prototype.\n\t* ipa-inline-transform.c (inline_transform): Fix scaling conditoins.\n\t* ipa-inline.c (compute_uninlined_call_time): Be sure that\n\tcounts are nonzero.\n\t(want_inline_self_recursive_call_p): Likewise.\n\t(resolve_noninline_speculation): Only cummulate defined counts.\n\t(inline_small_functions): Use nonzero_p.\n\t(ipa_inline): Do not access freed node.\n\nUnknown ChangeLog:\n\n2017-11-02  Jan Hubicka  <hubicka@ucw.cz>\n\n\t* testsuite/gcc.dg/no-strict-overflow-3.c (foo): Update magic\n\tvalue to not clash with frequency.\n\t* testsuite/gcc.dg/strict-overflow-3.c (foo): Likewise.\n\t* testsuite/gcc.dg/tree-ssa/builtin-sprintf-2.c: Update template.\n\t* testsuite/gcc.dg/tree-ssa/dump-2.c: Update template.\n\t* testsuite/gcc.dg/tree-ssa/ifc-10.c: Update template.\n\t* testsuite/gcc.dg/tree-ssa/ifc-11.c: Update template.\n\t* testsuite/gcc.dg/tree-ssa/ifc-12.c: Update template.\n\t* testsuite/gcc.dg/tree-ssa/ifc-20040816-1.c: Update template.\n\t* testsuite/gcc.dg/tree-ssa/ifc-20040816-2.c: Update template.\n\t* testsuite/gcc.dg/tree-ssa/ifc-5.c: Update template.\n\t* testsuite/gcc.dg/tree-ssa/ifc-8.c: Update template.\n\t* testsuite/gcc.dg/tree-ssa/ifc-9.c: Update template.\n\t* testsuite/gcc.dg/tree-ssa/ifc-cd.c: Update template.\n\t* testsuite/gcc.dg/tree-ssa/ifc-pr56541.c: Update template.\n\t* testsuite/gcc.dg/tree-ssa/ifc-pr68583.c: Update template.\n\t* testsuite/gcc.dg/tree-ssa/ifc-pr69489-1.c: Update template.\n\t* testsuite/gcc.dg/tree-ssa/ifc-pr69489-2.c: Update template.\n\t* testsuite/gcc.target/i386/pr61403.c: Update template.\n\nIndex: asan.c\n===================================================================\n--- asan.c\t(revision 254348)\n+++ asan.c\t(working copy)\n@@ -1801,6 +1801,7 @@ create_cond_insert_point (gimple_stmt_it\n     ? profile_probability::very_unlikely ()\n     : profile_probability::very_likely ();\n   e->probability = fallthrough_probability.invert ();\n+  then_bb->count = e->count ();\n   if (create_then_fallthru_edge)\n     make_single_succ_edge (then_bb, fallthru_bb, EDGE_FALLTHRU);\n \nIndex: basic-block.h\n===================================================================\n--- basic-block.h\t(revision 254348)\n+++ basic-block.h\t(working copy)\n@@ -148,9 +148,6 @@ struct GTY((chain_next (\"%h.next_bb\"), c\n   /* Expected number of executions: calculated in profile.c.  */\n   profile_count count;\n \n-  /* Expected frequency.  Normalized to be in range 0 to BB_FREQ_MAX.  */\n-  int frequency;\n-\n   /* The discriminator for this block.  The discriminator distinguishes\n      among several basic blocks that share a common locus, allowing for\n      more accurate sample-based profiling.  */\n@@ -301,7 +298,7 @@ enum cfg_bb_flags\n \t\t\t\t\t ? EDGE_SUCC ((bb), 1) : EDGE_SUCC ((bb), 0))\n \n /* Return expected execution frequency of the edge E.  */\n-#define EDGE_FREQUENCY(e)\t\te->probability.apply (e->src->frequency)\n+#define EDGE_FREQUENCY(e)\t\te->count ().to_frequency (cfun)\n \n /* Compute a scale factor (or probability) suitable for scaling of\n    gcov_type values via apply_probability() and apply_scale().  */\nIndex: bb-reorder.c\n===================================================================\n--- bb-reorder.c\t(revision 254348)\n+++ bb-reorder.c\t(working copy)\n@@ -256,8 +256,8 @@ push_to_next_round_p (const_basic_block\n \n   there_exists_another_round = round < number_of_rounds - 1;\n \n-  block_not_hot_enough = (bb->frequency < exec_th\n-\t\t\t  || bb->count < count_th\n+  block_not_hot_enough = (bb->count.to_frequency (cfun) < exec_th\n+\t\t\t  || bb->count.ipa () < count_th\n \t\t\t  || probably_never_executed_bb_p (cfun, bb));\n \n   if (there_exists_another_round\n@@ -293,9 +293,9 @@ find_traces (int *n_traces, struct trace\n     {\n       bbd[e->dest->index].heap = heap;\n       bbd[e->dest->index].node = heap->insert (bb_to_key (e->dest), e->dest);\n-      if (e->dest->frequency > max_entry_frequency)\n-\tmax_entry_frequency = e->dest->frequency;\n-      if (e->dest->count.initialized_p () && e->dest->count > max_entry_count)\n+      if (e->dest->count.to_frequency (cfun) > max_entry_frequency)\n+\tmax_entry_frequency = e->dest->count.to_frequency (cfun);\n+      if (e->dest->count.ipa_p () && e->dest->count > max_entry_count)\n \tmax_entry_count = e->dest->count;\n     }\n \n@@ -329,8 +329,10 @@ find_traces (int *n_traces, struct trace\n \t  for (bb = traces[i].first;\n \t       bb != traces[i].last;\n \t       bb = (basic_block) bb->aux)\n-\t    fprintf (dump_file, \"%d [%d] \", bb->index, bb->frequency);\n-\t  fprintf (dump_file, \"%d [%d]\\n\", bb->index, bb->frequency);\n+\t    fprintf (dump_file, \"%d [%d] \", bb->index,\n+\t\t     bb->count.to_frequency (cfun));\n+\t  fprintf (dump_file, \"%d [%d]\\n\", bb->index,\n+\t\t   bb->count.to_frequency (cfun));\n \t}\n       fflush (dump_file);\n     }\n@@ -551,7 +553,7 @@ find_traces_1_round (int branch_th, int\n \t\tcontinue;\n \n \t      prob = e->probability;\n-\t      freq = e->dest->frequency;\n+\t      freq = e->dest->count.to_frequency (cfun);\n \n \t      /* The only sensible preference for a call instruction is the\n \t\t fallthru edge.  Don't bother selecting anything else.  */\n@@ -573,7 +575,7 @@ find_traces_1_round (int branch_th, int\n \t\t  || !prob.initialized_p ()\n \t\t  || ((prob.to_reg_br_prob_base () < branch_th\n \t\t       || EDGE_FREQUENCY (e) < exec_th\n-\t\t      || e->count () < count_th) && (!for_size)))\n+\t\t      || e->count ().ipa () < count_th) && (!for_size)))\n \t\tcontinue;\n \n \t      if (better_edge_p (bb, e, prob, freq, best_prob, best_freq,\n@@ -671,7 +673,7 @@ find_traces_1_round (int branch_th, int\n \t\t      || !prob.initialized_p ()\n \t\t      || prob.to_reg_br_prob_base () < branch_th\n \t\t      || freq < exec_th\n-\t\t      || e->count () < count_th)\n+\t\t      || e->count ().ipa () < count_th)\n \t\t    {\n \t\t      /* When partitioning hot/cold basic blocks, make sure\n \t\t\t the cold blocks (and only the cold blocks) all get\n@@ -706,7 +708,7 @@ find_traces_1_round (int branch_th, int\n \t\t  if (best_edge->dest != bb)\n \t\t    {\n \t\t      if (EDGE_FREQUENCY (best_edge)\n-\t\t\t  > 4 * best_edge->dest->frequency / 5)\n+\t\t\t  > 4 * best_edge->dest->count.to_frequency (cfun) / 5)\n \t\t\t{\n \t\t\t  /* The loop has at least 4 iterations.  If the loop\n \t\t\t     header is not the first block of the function\n@@ -783,8 +785,8 @@ find_traces_1_round (int branch_th, int\n \t\t\t    & EDGE_CAN_FALLTHRU)\n \t\t\t&& !(single_succ_edge (e->dest)->flags & EDGE_COMPLEX)\n \t\t\t&& single_succ (e->dest) == best_edge->dest\n-\t\t\t&& (2 * e->dest->frequency >= EDGE_FREQUENCY (best_edge)\n-\t\t\t    || for_size))\n+\t\t\t&& (2 * e->dest->count.to_frequency (cfun)\n+\t\t\t    >= EDGE_FREQUENCY (best_edge) || for_size))\n \t\t      {\n \t\t\tbest_edge = e;\n \t\t\tif (dump_file)\n@@ -945,9 +947,9 @@ bb_to_key (basic_block bb)\n \n   if (priority)\n     /* The block with priority should have significantly lower key.  */\n-    return -(100 * BB_FREQ_MAX + 100 * priority + bb->frequency);\n+    return -(100 * BB_FREQ_MAX + 100 * priority + bb->count.to_frequency (cfun));\n \n-  return -bb->frequency;\n+  return -bb->count.to_frequency (cfun);\n }\n \n /* Return true when the edge E from basic block BB is better than the temporary\n@@ -1290,7 +1292,7 @@ connect_traces (int n_traces, struct tra\n \t\t\t\t&& !connected[bbd[di].start_of_trace]\n \t\t\t\t&& BB_PARTITION (e2->dest) == current_partition\n \t\t\t\t&& EDGE_FREQUENCY (e2) >= freq_threshold\n-\t\t\t\t&& e2->count () >= count_threshold\n+\t\t\t\t&& e2->count ().ipa () >= count_threshold\n \t\t\t\t&& (!best2\n \t\t\t\t    || e2->probability > best2->probability\n \t\t\t\t    || (e2->probability == best2->probability\n@@ -1317,7 +1319,7 @@ connect_traces (int n_traces, struct tra\n \t\t\t\toptimize_edge_for_speed_p (best)\n \t\t\t\t&& EDGE_FREQUENCY (best) >= freq_threshold\n \t\t\t\t&& (!best->count ().initialized_p ()\n-\t\t\t\t    || best->count () >= count_threshold)))\n+\t\t\t\t    || best->count ().ipa () >= count_threshold)))\n \t\t{\n \t\t  basic_block new_bb;\n \n@@ -1375,7 +1377,7 @@ copy_bb_p (const_basic_block bb, int cod\n   int max_size = uncond_jump_length;\n   rtx_insn *insn;\n \n-  if (!bb->frequency)\n+  if (!bb->count.to_frequency (cfun))\n     return false;\n   if (EDGE_COUNT (bb->preds) < 2)\n     return false;\n@@ -1459,7 +1461,6 @@ fix_up_crossing_landing_pad (eh_landing_\n   last_bb = EXIT_BLOCK_PTR_FOR_FN (cfun)->prev_bb;\n   new_bb = create_basic_block (new_label, jump, last_bb);\n   new_bb->aux = last_bb->aux;\n-  new_bb->frequency = post_bb->frequency;\n   new_bb->count = post_bb->count;\n   last_bb->aux = new_bb;\n \n@@ -1517,7 +1518,6 @@ sanitize_hot_paths (bool walk_up, unsign\n       edge_iterator ei;\n       profile_probability highest_probability\n \t\t\t\t = profile_probability::uninitialized ();\n-      int highest_freq = 0;\n       profile_count highest_count = profile_count::uninitialized ();\n       bool found = false;\n \n@@ -1544,11 +1544,8 @@ sanitize_hot_paths (bool walk_up, unsign\n           /* The following loop will look for the hottest edge via\n              the edge count, if it is non-zero, then fallback to the edge\n              frequency and finally the edge probability.  */\n-          if (!highest_count.initialized_p () || e->count () > highest_count)\n+          if (!(e->count () > highest_count))\n             highest_count = e->count ();\n-          int edge_freq = EDGE_FREQUENCY (e);\n-          if (edge_freq > highest_freq)\n-            highest_freq = edge_freq;\n           if (!highest_probability.initialized_p ()\n \t      || e->probability > highest_probability)\n             highest_probability = e->probability;\n@@ -1573,17 +1570,12 @@ sanitize_hot_paths (bool walk_up, unsign\n           /* Select the hottest edge using the edge count, if it is non-zero,\n              then fallback to the edge frequency and finally the edge\n              probability.  */\n-          if (highest_count > 0)\n+          if (highest_count.initialized_p ())\n             {\n-              if (e->count () < highest_count)\n+              if (!(e->count () >= highest_count))\n                 continue;\n             }\n-          else if (highest_freq)\n-            {\n-              if (EDGE_FREQUENCY (e) < highest_freq)\n-                continue;\n-            }\n-          else if (e->probability < highest_probability)\n+          else if (!(e->probability >= highest_probability))\n             continue;\n \n           basic_block reach_bb = walk_up ? e->src : e->dest;\nIndex: bt-load.c\n===================================================================\n--- bt-load.c\t(revision 254348)\n+++ bt-load.c\t(working copy)\n@@ -185,7 +185,7 @@ static int first_btr, last_btr;\n static int\n basic_block_freq (const_basic_block bb)\n {\n-  return bb->frequency;\n+  return bb->count.to_frequency (cfun);\n }\n \n /* If the rtx at *XP references (sets or reads) any branch target\nIndex: cfg.c\n===================================================================\n--- cfg.c\t(revision 254348)\n+++ cfg.c\t(working copy)\n@@ -68,6 +68,7 @@ init_flow (struct function *the_fun)\n   if (!the_fun->cfg)\n     the_fun->cfg = ggc_cleared_alloc<control_flow_graph> ();\n   n_edges_for_fn (the_fun) = 0;\n+  the_fun->cfg->count_max = profile_count::uninitialized ();\n   ENTRY_BLOCK_PTR_FOR_FN (the_fun)\n     = alloc_block ();\n   ENTRY_BLOCK_PTR_FOR_FN (the_fun)->index = ENTRY_BLOCK;\n@@ -447,13 +448,18 @@ check_bb_profile (basic_block bb, FILE *\n     }\n   if (bb != ENTRY_BLOCK_PTR_FOR_FN (fun))\n     {\n-      int sum = 0;\n+      profile_count sum = profile_count::zero ();\n       FOR_EACH_EDGE (e, ei, bb->preds)\n-\tsum += EDGE_FREQUENCY (e);\n-      if (abs (sum - bb->frequency) > 100)\n-\tfprintf (file,\n-\t\t \";; %sInvalid sum of incoming frequencies %i, should be %i\\n\",\n-\t\t s_indent, sum, bb->frequency);\n+\tsum += e->count ();\n+      if (sum.differs_from_p (bb->count))\n+\t{\n+\t  fprintf (file, \";; %sInvalid sum of incoming counts \",\n+\t\t   s_indent);\n+\t  sum.dump (file);\n+\t  fprintf (file, \", should be \");\n+\t  bb->count.dump (file);\n+\t  fprintf (file, \"\\n\");\n+\t}\n     }\n   if (BB_PARTITION (bb) == BB_COLD_PARTITION)\n     {\n@@ -751,7 +757,6 @@ dump_bb_info (FILE *outf, basic_block bb\n \t      fputs (\", count \", outf);\n \t      bb->count.dump (outf);\n \t    }\n-\t  fprintf (outf, \", freq %i\", bb->frequency);\n \t  if (maybe_hot_bb_p (fun, bb))\n \t    fputs (\", maybe hot\", outf);\n \t  if (probably_never_executed_bb_p (fun, bb))\n@@ -843,15 +848,15 @@ brief_dump_cfg (FILE *file, dump_flags_t\n     }\n }\n \n-/* An edge originally destinating BB of FREQUENCY and COUNT has been proved to\n+/* An edge originally destinating BB of COUNT has been proved to\n    leave the block by TAKEN_EDGE.  Update profile of BB such that edge E can be\n    redirected to destination of TAKEN_EDGE.\n \n    This function may leave the profile inconsistent in the case TAKEN_EDGE\n-   frequency or count is believed to be lower than FREQUENCY or COUNT\n+   frequency or count is believed to be lower than COUNT\n    respectively.  */\n void\n-update_bb_profile_for_threading (basic_block bb, int edge_frequency,\n+update_bb_profile_for_threading (basic_block bb, \n \t\t\t\t profile_count count, edge taken_edge)\n {\n   edge c;\n@@ -866,16 +871,10 @@ update_bb_profile_for_threading (basic_b\n     }\n   bb->count -= count;\n \n-  bb->frequency -= edge_frequency;\n-  if (bb->frequency < 0)\n-    bb->frequency = 0;\n-\n   /* Compute the probability of TAKEN_EDGE being reached via threaded edge.\n      Watch for overflows.  */\n-  if (bb->frequency)\n-    /* FIXME: We should get edge frequency as count.  */\n-    prob = profile_probability::probability_in_gcov_type\n-\t\t (edge_frequency, bb->frequency);\n+  if (bb->count.nonzero_p ())\n+    prob = count.probability_in (bb->count);\n   else\n     prob = profile_probability::never ();\n   if (prob > taken_edge->probability)\n@@ -899,9 +898,9 @@ update_bb_profile_for_threading (basic_b\n   if (prob == profile_probability::never ())\n     {\n       if (dump_file)\n-\tfprintf (dump_file, \"Edge frequencies of bb %i has been reset, \"\n-\t\t \"frequency of block should end up being 0, it is %i\\n\",\n-\t\t bb->index, bb->frequency);\n+\tfprintf (dump_file, \"Edge probabilities of bb %i has been reset, \"\n+\t\t \"count of block should end up being 0, it is non-zero\\n\",\n+\t\t bb->index);\n       EDGE_SUCC (bb, 0)->probability = profile_probability::guessed_always ();\n       ei = ei_start (bb->succs);\n       ei_next (&ei);\n@@ -942,18 +941,10 @@ scale_bbs_frequencies_int (basic_block *\n \n   for (i = 0; i < nbbs; i++)\n     {\n-      bbs[i]->frequency = RDIV (bbs[i]->frequency * num, den);\n-      /* Make sure the frequencies do not grow over BB_FREQ_MAX.  */\n-      if (bbs[i]->frequency > BB_FREQ_MAX)\n-\tbbs[i]->frequency = BB_FREQ_MAX;\n       bbs[i]->count = bbs[i]->count.apply_scale (num, den);\n     }\n }\n \n-/* numbers smaller than this value are safe to multiply without getting\n-   64bit overflow.  */\n-#define MAX_SAFE_MULTIPLIER (1 << (sizeof (int64_t) * 4 - 1))\n-\n /* Multiply all frequencies of basic blocks in array BBS of length NBBS\n    by NUM/DEN, in gcov_type arithmetic.  More accurate than previous\n    function but considerably slower.  */\n@@ -962,28 +953,9 @@ scale_bbs_frequencies_gcov_type (basic_b\n \t\t\t\t gcov_type den)\n {\n   int i;\n-  gcov_type fraction = RDIV (num * 65536, den);\n-\n-  gcc_assert (fraction >= 0);\n \n-  if (num < MAX_SAFE_MULTIPLIER)\n-    for (i = 0; i < nbbs; i++)\n-      {\n-\tbbs[i]->frequency = RDIV (bbs[i]->frequency * num, den);\n-\tif (bbs[i]->count <= MAX_SAFE_MULTIPLIER)\n-\t  bbs[i]->count = bbs[i]->count.apply_scale (num, den);\n-\telse\n-\t  bbs[i]->count = bbs[i]->count.apply_scale (fraction, 65536);\n-      }\n-   else\n-    for (i = 0; i < nbbs; i++)\n-      {\n-\tif (sizeof (gcov_type) > sizeof (int))\n-\t  bbs[i]->frequency = RDIV (bbs[i]->frequency * num, den);\n-\telse\n-\t  bbs[i]->frequency = RDIV (bbs[i]->frequency * fraction, 65536);\n-\tbbs[i]->count = bbs[i]->count.apply_scale (fraction, 65536);\n-      }\n+  for (i = 0; i < nbbs; i++)\n+    bbs[i]->count = bbs[i]->count.apply_scale (num, den);\n }\n \n /* Multiply all frequencies of basic blocks in array BBS of length NBBS\n@@ -994,13 +966,9 @@ scale_bbs_frequencies_profile_count (bas\n \t\t\t\t     profile_count num, profile_count den)\n {\n   int i;\n-\n-  for (i = 0; i < nbbs; i++)\n-    {\n-      bbs[i]->frequency = RDIV (bbs[i]->frequency * num.to_gcov_type (),\n-\t\t\t\tden.to_gcov_type ());\n+  if (num == profile_count::zero () || den.nonzero_p ())\n+    for (i = 0; i < nbbs; i++)\n       bbs[i]->count = bbs[i]->count.apply_scale (num, den);\n-    }\n }\n \n /* Multiply all frequencies of basic blocks in array BBS of length NBBS\n@@ -1013,10 +981,7 @@ scale_bbs_frequencies (basic_block *bbs,\n   int i;\n \n   for (i = 0; i < nbbs; i++)\n-    {\n-      bbs[i]->frequency = p.apply (bbs[i]->frequency);\n-      bbs[i]->count = bbs[i]->count.apply_probability (p);\n-    }\n+    bbs[i]->count = bbs[i]->count.apply_probability (p);\n }\n \n /* Helper types for hash tables.  */\nIndex: cfg.h\n===================================================================\n--- cfg.h\t(revision 254348)\n+++ cfg.h\t(working copy)\n@@ -71,6 +71,9 @@ struct GTY(()) control_flow_graph {\n   /* Maximal number of entities in the single jumptable.  Used to estimate\n      final flowgraph size.  */\n   int max_jumptable_ents;\n+\n+  /* Maximal count of BB in function.  */\n+  profile_count count_max;\n };\n \n \n@@ -103,7 +106,7 @@ extern void debug_bb (basic_block);\n extern basic_block debug_bb_n (int);\n extern void dump_bb_info (FILE *, basic_block, int, dump_flags_t, bool, bool);\n extern void brief_dump_cfg (FILE *, dump_flags_t);\n-extern void update_bb_profile_for_threading (basic_block, int, profile_count, edge);\n+extern void update_bb_profile_for_threading (basic_block, profile_count, edge);\n extern void scale_bbs_frequencies_int (basic_block *, int, int, int);\n extern void scale_bbs_frequencies_gcov_type (basic_block *, int, gcov_type,\n \t\t\t\t\t     gcov_type);\nIndex: cfgbuild.c\n===================================================================\n--- cfgbuild.c\t(revision 254348)\n+++ cfgbuild.c\t(working copy)\n@@ -499,7 +499,6 @@ find_bb_boundaries (basic_block bb)\n \t  remove_edge (fallthru);\n \t  /* BB is unreachable at this point - we need to determine its profile\n \t     once edges are built.  */\n-\t  bb->frequency = 0;\n \t  bb->count = profile_count::uninitialized ();\n \t  flow_transfer_insn = NULL;\n \t  debug_insn = NULL;\n@@ -669,7 +668,6 @@ find_many_sub_basic_blocks (sbitmap bloc\n \t  {\n \t    bool initialized_src = false, uninitialized_src = false;\n \t    bb->count = profile_count::zero ();\n-\t    bb->frequency = 0;\n \t    FOR_EACH_EDGE (e, ei, bb->preds)\n \t      {\n \t\tif (e->count ().initialized_p ())\n@@ -679,8 +677,6 @@ find_many_sub_basic_blocks (sbitmap bloc\n \t\t  }\n \t\telse\n \t\t  uninitialized_src = true;\n-\t\tif (e->probability.initialized_p ())\n-\t\t  bb->frequency += EDGE_FREQUENCY (e);\n \t      }\n \t    /* When some edges are missing with read profile, this is\n \t       most likely because RTL expansion introduced loop.\n@@ -692,7 +688,7 @@ find_many_sub_basic_blocks (sbitmap bloc\n \t       precisely once.  */\n \t    if (!initialized_src\n \t\t|| (uninitialized_src\n-\t\t     && profile_status_for_fn (cfun) != PROFILE_READ))\n+\t\t     && profile_status_for_fn (cfun) < PROFILE_GUESSED))\n \t      bb->count = profile_count::uninitialized ();\n \t  }\n  \t/* If nothing changed, there is no need to create new BBs.  */\nIndex: cfgcleanup.c\n===================================================================\n--- cfgcleanup.c\t(revision 254348)\n+++ cfgcleanup.c\t(working copy)\n@@ -559,8 +559,6 @@ try_forward_edges (int mode, basic_block\n \t{\n \t  /* Save the values now, as the edge may get removed.  */\n \t  profile_count edge_count = e->count ();\n-\t  profile_probability edge_probability = e->probability;\n-\t  int edge_frequency;\n \t  int n = 0;\n \n \t  e->goto_locus = goto_locus;\n@@ -585,8 +583,6 @@ try_forward_edges (int mode, basic_block\n \t  /* We successfully forwarded the edge.  Now update profile\n \t     data: for each edge we traversed in the chain, remove\n \t     the original edge's execution count.  */\n-\t  edge_frequency = edge_probability.apply (b->frequency);\n-\n \t  do\n \t    {\n \t      edge t;\n@@ -596,16 +592,12 @@ try_forward_edges (int mode, basic_block\n \t\t  gcc_assert (n < nthreaded_edges);\n \t\t  t = threaded_edges [n++];\n \t\t  gcc_assert (t->src == first);\n-\t\t  update_bb_profile_for_threading (first, edge_frequency,\n-\t\t\t\t\t\t   edge_count, t);\n+\t\t  update_bb_profile_for_threading (first, edge_count, t);\n \t\t  update_br_prob_note (first);\n \t\t}\n \t      else\n \t\t{\n \t\t  first->count -= edge_count;\n-\t\t  first->frequency -= edge_frequency;\n-\t\t  if (first->frequency < 0)\n-\t\t    first->frequency = 0;\n \t\t  /* It is possible that as the result of\n \t\t     threading we've removed edge as it is\n \t\t     threaded to the fallthru edge.  Avoid\n@@ -2109,7 +2101,7 @@ try_crossjump_to_edge (int mode, edge e1\n   else\n     redirect_edges_to = osrc2;\n \n-  /* Recompute the frequencies and counts of outgoing edges.  */\n+  /* Recompute the counts of destinations of outgoing edges.  */\n   FOR_EACH_EDGE (s, ei, redirect_edges_to->succs)\n     {\n       edge s2;\n@@ -2132,24 +2124,19 @@ try_crossjump_to_edge (int mode, edge e1\n \t that there is no more than one in the chain, so we can't run\n \t into infinite loop.  */\n       if (FORWARDER_BLOCK_P (s->dest))\n-\t{\n-\t  s->dest->frequency += EDGE_FREQUENCY (s);\n-\t}\n+\ts->dest->count += s->count ();\n \n       if (FORWARDER_BLOCK_P (s2->dest))\n-\t{\n-\t  s2->dest->frequency -= EDGE_FREQUENCY (s);\n-\t  if (s2->dest->frequency < 0)\n-\t    s2->dest->frequency = 0;\n-\t}\n+\ts2->dest->count -= s->count ();\n \n-      if (!redirect_edges_to->frequency && !src1->frequency)\n+      /* FIXME: Is this correct? Should be rewritten to count API.  */\n+      if (redirect_edges_to->count.nonzero_p () && src1->count.nonzero_p ())\n \ts->probability = s->probability.combine_with_freq\n-\t\t\t   (redirect_edges_to->frequency,\n-\t\t\t    s2->probability, src1->frequency);\n+\t\t\t   (redirect_edges_to->count.to_frequency (cfun),\n+\t\t\t    s2->probability, src1->count.to_frequency (cfun));\n     }\n \n-  /* Adjust count and frequency for the block.  An earlier jump\n+  /* Adjust count for the block.  An earlier jump\n      threading pass may have left the profile in an inconsistent\n      state (see update_bb_profile_for_threading) so we must be\n      prepared for overflows.  */\n@@ -2157,9 +2144,6 @@ try_crossjump_to_edge (int mode, edge e1\n   do\n     {\n       tmp->count += src1->count;\n-      tmp->frequency += src1->frequency;\n-      if (tmp->frequency > BB_FREQ_MAX)\n-        tmp->frequency = BB_FREQ_MAX;\n       if (tmp == redirect_edges_to)\n         break;\n       tmp = find_fallthru_edge (tmp->succs)->dest;\nIndex: cfgexpand.c\n===================================================================\n--- cfgexpand.c\t(revision 254348)\n+++ cfgexpand.c\t(working copy)\n@@ -2516,7 +2516,6 @@ expand_gimple_cond (basic_block bb, gcon\n   redirect_edge_succ (false_edge, new_bb);\n   false_edge->flags |= EDGE_FALLTHRU;\n   new_bb->count = false_edge->count ();\n-  new_bb->frequency = EDGE_FREQUENCY (false_edge);\n   loop_p loop = find_common_loop (bb->loop_father, dest->loop_father);\n   add_bb_to_loop (new_bb, loop);\n   if (loop->latch == bb\n@@ -3847,11 +3846,7 @@ expand_gimple_tailcall (basic_block bb,\n       if (!(e->flags & (EDGE_ABNORMAL | EDGE_EH)))\n \t{\n \t  if (e->dest != EXIT_BLOCK_PTR_FOR_FN (cfun))\n-\t    {\n-\t      e->dest->frequency -= EDGE_FREQUENCY (e);\n-\t      if (e->dest->frequency < 0)\n-\t\te->dest->frequency = 0;\n-\t    }\n+\t    e->dest->count -= e->count ();\n \t  probability += e->probability;\n \t  remove_edge (e);\n \t}\n@@ -5860,7 +5855,6 @@ construct_init_block (void)\n   init_block = create_basic_block (NEXT_INSN (get_insns ()),\n \t\t\t\t   get_last_insn (),\n \t\t\t\t   ENTRY_BLOCK_PTR_FOR_FN (cfun));\n-  init_block->frequency = ENTRY_BLOCK_PTR_FOR_FN (cfun)->frequency;\n   init_block->count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;\n   add_bb_to_loop (init_block, ENTRY_BLOCK_PTR_FOR_FN (cfun)->loop_father);\n   if (e)\n@@ -5924,7 +5918,7 @@ construct_exit_block (void)\n   while (NEXT_INSN (head) && NOTE_P (NEXT_INSN (head)))\n     head = NEXT_INSN (head);\n   /* But make sure exit_block starts with RETURN_LABEL, otherwise the\n-     bb frequency counting will be confused.  Any instructions before that\n+     bb count counting will be confused.  Any instructions before that\n      label are emitted for the case where PREV_BB falls through into the\n      exit block, so append those instructions to prev_bb in that case.  */\n   if (NEXT_INSN (head) != return_label)\n@@ -5937,7 +5931,6 @@ construct_exit_block (void)\n \t}\n     }\n   exit_block = create_basic_block (NEXT_INSN (head), end, prev_bb);\n-  exit_block->frequency = EXIT_BLOCK_PTR_FOR_FN (cfun)->frequency;\n   exit_block->count = EXIT_BLOCK_PTR_FOR_FN (cfun)->count;\n   add_bb_to_loop (exit_block, EXIT_BLOCK_PTR_FOR_FN (cfun)->loop_father);\n \n@@ -5957,10 +5950,7 @@ construct_exit_block (void)\n     if (e2 != e)\n       {\n \texit_block->count -= e2->count ();\n-\texit_block->frequency -= EDGE_FREQUENCY (e2);\n       }\n-  if (exit_block->frequency < 0)\n-    exit_block->frequency = 0;\n   update_bb_for_insn (exit_block);\n }\n \nIndex: cfghooks.c\n===================================================================\n--- cfghooks.c\t(revision 254348)\n+++ cfghooks.c\t(working copy)\n@@ -146,10 +146,12 @@ verify_flow_info (void)\n \t  error (\"verify_flow_info: Wrong count of block %i\", bb->index);\n \t  err = 1;\n \t}\n-      if (bb->frequency < 0)\n+      /* FIXME: Graphite and SLJL and target code still tends to produce\n+\t edges with no probablity.  */\n+      if (profile_status_for_fn (cfun) >= PROFILE_GUESSED\n+          && !bb->count.initialized_p () && !flag_graphite && 0)\n \t{\n-\t  error (\"verify_flow_info: Wrong frequency of block %i %i\",\n-\t\t bb->index, bb->frequency);\n+\t  error (\"verify_flow_info: Missing count of block %i\", bb->index);\n \t  err = 1;\n \t}\n \n@@ -164,7 +166,7 @@ verify_flow_info (void)\n \t  /* FIXME: Graphite and SLJL and target code still tends to produce\n \t     edges with no probablity.  */\n \t  if (profile_status_for_fn (cfun) >= PROFILE_GUESSED\n-\t      && !e->probability.initialized_p () && 0)\n+\t      && !e->probability.initialized_p () && !flag_graphite && 0)\n \t    {\n \t      error (\"Uninitialized probability of edge %i->%i\", e->src->index,\n \t\t     e->dest->index);\n@@ -315,7 +317,6 @@ dump_bb_for_graph (pretty_printer *pp, b\n   /* TODO: Add pretty printer for counter.  */\n   if (bb->count.initialized_p ())\n     pp_printf (pp, \"COUNT:\" \"%\" PRId64, bb->count.to_gcov_type ());\n-  pp_printf (pp, \" FREQ:%i |\", bb->frequency);\n   pp_write_text_to_stream (pp);\n   if (!(dump_flags & TDF_SLIM))\n     cfg_hooks->dump_bb_for_graph (pp, bb);\n@@ -513,7 +514,6 @@ split_block_1 (basic_block bb, void *i)\n     return NULL;\n \n   new_bb->count = bb->count;\n-  new_bb->frequency = bb->frequency;\n   new_bb->discriminator = bb->discriminator;\n \n   if (dom_info_available_p (CDI_DOMINATORS))\n@@ -626,7 +626,6 @@ split_edge (edge e)\n {\n   basic_block ret;\n   profile_count count = e->count ();\n-  int freq = EDGE_FREQUENCY (e);\n   edge f;\n   bool irr = (e->flags & EDGE_IRREDUCIBLE_LOOP) != 0;\n   struct loop *loop;\n@@ -640,7 +639,6 @@ split_edge (edge e)\n \n   ret = cfg_hooks->split_edge (e);\n   ret->count = count;\n-  ret->frequency = freq;\n   single_succ_edge (ret)->probability = profile_probability::always ();\n \n   if (irr)\n@@ -869,7 +867,6 @@ make_forwarder_block (basic_block bb, bo\n   fallthru = split_block_after_labels (bb);\n   dummy = fallthru->src;\n   dummy->count = profile_count::zero ();\n-  dummy->frequency = 0;\n   bb = fallthru->dest;\n \n   /* Redirect back edges we want to keep.  */\n@@ -879,10 +876,6 @@ make_forwarder_block (basic_block bb, bo\n \n       if (redirect_edge_p (e))\n \t{\n-\t  dummy->frequency += EDGE_FREQUENCY (e);\n-\t  if (dummy->frequency > BB_FREQ_MAX)\n-\t    dummy->frequency = BB_FREQ_MAX;\n-\n \t  dummy->count += e->count ();\n \t  ei_next (&ei);\n \t  continue;\n@@ -1101,19 +1094,10 @@ duplicate_block (basic_block bb, edge e,\n       new_bb->count = new_count;\n       bb->count -= new_count;\n \n-      new_bb->frequency = EDGE_FREQUENCY (e);\n-      bb->frequency -= EDGE_FREQUENCY (e);\n-\n       redirect_edge_and_branch_force (e, new_bb);\n-\n-      if (bb->frequency < 0)\n-\tbb->frequency = 0;\n     }\n   else\n-    {\n-      new_bb->count = bb->count;\n-      new_bb->frequency = bb->frequency;\n-    }\n+    new_bb->count = bb->count;\n \n   set_bb_original (new_bb, bb);\n   set_bb_copy (bb, new_bb);\n@@ -1463,13 +1447,6 @@ account_profile_record (struct profile_r\n       if (bb != ENTRY_BLOCK_PTR_FOR_FN (cfun)\n \t  && profile_status_for_fn (cfun) != PROFILE_ABSENT)\n \t{\n-\t  int sum = 0;\n-\t  FOR_EACH_EDGE (e, ei, bb->preds)\n-\t    sum += EDGE_FREQUENCY (e);\n-\t  if (abs (sum - bb->frequency) > 100\n-\t      || (MAX (sum, bb->frequency) > 10\n-\t\t  && abs ((sum - bb->frequency) * 100 / (MAX (sum, bb->frequency) + 1)) > 10))\n-\t    record->num_mismatched_freq_in[after_pass]++;\n \t  profile_count lsum = profile_count::zero ();\n \t  FOR_EACH_EDGE (e, ei, bb->preds)\n \t    lsum += e->count ();\nIndex: cfgloop.c\n===================================================================\n--- cfgloop.c\t(revision 254348)\n+++ cfgloop.c\t(working copy)\n@@ -607,7 +607,7 @@ find_subloop_latch_edge_by_profile (vec<\n       tcount += e->count();\n     }\n \n-  if (!tcount.initialized_p () || tcount < HEAVY_EDGE_MIN_SAMPLES\n+  if (!tcount.initialized_p () || !(tcount.ipa () > HEAVY_EDGE_MIN_SAMPLES)\n       || (tcount - mcount).apply_scale (HEAVY_EDGE_RATIO, 1) > tcount)\n     return NULL;\n \nIndex: cfgloopanal.c\n===================================================================\n--- cfgloopanal.c\t(revision 254348)\n+++ cfgloopanal.c\t(working copy)\n@@ -213,9 +213,10 @@ average_num_loop_insns (const struct loo\n \tif (NONDEBUG_INSN_P (insn))\n \t  binsns++;\n \n-      ratio = loop->header->frequency == 0\n+      ratio = loop->header->count.to_frequency (cfun) == 0\n \t      ? BB_FREQ_MAX\n-\t      : (bb->frequency * BB_FREQ_MAX) / loop->header->frequency;\n+\t      : (bb->count.to_frequency (cfun) * BB_FREQ_MAX)\n+\t\t / loop->header->count.to_frequency (cfun);\n       ninsns += binsns * ratio;\n     }\n   free (bbs);\n@@ -245,8 +246,8 @@ expected_loop_iterations_unbounded (cons\n   /* If we have no profile at all, use AVG_LOOP_NITER.  */\n   if (profile_status_for_fn (cfun) == PROFILE_ABSENT)\n     expected = PARAM_VALUE (PARAM_AVG_LOOP_NITER);\n-  else if (loop->latch && (loop->latch->count.reliable_p ()\n-\t\t\t   || loop->header->count.reliable_p ()))\n+  else if (loop->latch && (loop->latch->count.initialized_p ()\n+\t\t\t   || loop->header->count.initialized_p ()))\n     {\n       profile_count count_in = profile_count::zero (),\n \t\t    count_latch = profile_count::zero ();\n@@ -258,45 +259,25 @@ expected_loop_iterations_unbounded (cons\n \t  count_in += e->count ();\n \n       if (!count_latch.initialized_p ())\n-\t;\n-      else if (!(count_in > profile_count::zero ()))\n+\texpected = PARAM_VALUE (PARAM_AVG_LOOP_NITER);\n+      else if (!count_in.nonzero_p ())\n \texpected = count_latch.to_gcov_type () * 2;\n       else\n \t{\n \t  expected = (count_latch.to_gcov_type () + count_in.to_gcov_type ()\n \t\t      - 1) / count_in.to_gcov_type ();\n-\t  if (read_profile_p)\n+\t  if (read_profile_p\n+\t      && count_latch.reliable_p () && count_in.reliable_p ())\n \t    *read_profile_p = true;\n \t}\n     }\n-  if (expected == -1)\n-    {\n-      int freq_in, freq_latch;\n-\n-      freq_in = 0;\n-      freq_latch = 0;\n-\n-      FOR_EACH_EDGE (e, ei, loop->header->preds)\n-\tif (flow_bb_inside_loop_p (loop, e->src))\n-\t  freq_latch += EDGE_FREQUENCY (e);\n-\telse\n-\t  freq_in += EDGE_FREQUENCY (e);\n-\n-      if (freq_in == 0)\n-\t{\n-\t  /* If we have no profile at all, use AVG_LOOP_NITER iterations.  */\n-\t  if (!freq_latch)\n-\t    expected = PARAM_VALUE (PARAM_AVG_LOOP_NITER);\n-\t  else\n-\t    expected = freq_latch * 2;\n-\t}\n-      else\n-        expected = (freq_latch + freq_in - 1) / freq_in;\n-    }\n+  else\n+    expected = PARAM_VALUE (PARAM_AVG_LOOP_NITER);\n \n   HOST_WIDE_INT max = get_max_loop_iterations_int (loop);\n   if (max != -1 && max < expected)\n     return max;\n+ \n   return expected;\n }\n \nIndex: cfgloopmanip.c\n===================================================================\n--- cfgloopmanip.c\t(revision 254348)\n+++ cfgloopmanip.c\t(working copy)\n@@ -536,7 +536,6 @@ scale_loop_profile (struct loop *loop, p\n       if (e)\n \t{\n \t  edge other_e;\n-\t  int freq_delta;\n \t  profile_count count_delta;\n \n           FOR_EACH_EDGE (other_e, ei, e->src->succs)\n@@ -545,23 +544,18 @@ scale_loop_profile (struct loop *loop, p\n \t      break;\n \n \t  /* Probability of exit must be 1/iterations.  */\n-\t  freq_delta = EDGE_FREQUENCY (e);\n \t  count_delta = e->count ();\n \t  e->probability = profile_probability::always ()\n \t\t\t\t.apply_scale (1, iteration_bound);\n \t  other_e->probability = e->probability.invert ();\n-\t  freq_delta -= EDGE_FREQUENCY (e);\n \t  count_delta -= e->count ();\n \n-\t  /* If latch exists, change its frequency and count, since we changed\n+\t  /* If latch exists, change its count, since we changed\n \t     probability of exit.  Theoretically we should update everything from\n \t     source of exit edge to latch, but for vectorizer this is enough.  */\n \t  if (loop->latch\n \t      && loop->latch != e->src)\n \t    {\n-\t      loop->latch->frequency += freq_delta;\n-\t      if (loop->latch->frequency < 0)\n-\t\tloop->latch->frequency = 0;\n \t      loop->latch->count += count_delta;\n \t    }\n \t}\n@@ -571,7 +565,6 @@ scale_loop_profile (struct loop *loop, p\n \t we look at the actual profile, if it is available.  */\n       p = p.apply_scale (iteration_bound, iterations);\n \n-      bool determined = false;\n       if (loop->header->count.initialized_p ())\n \t{\n \t  profile_count count_in = profile_count::zero ();\n@@ -584,21 +577,8 @@ scale_loop_profile (struct loop *loop, p\n \t    {\n \t      p = count_in.probability_in (loop->header->count.apply_scale\n \t\t\t\t\t\t (iteration_bound, 1));\n-\t      determined = true;\n \t    }\n \t}\n-      if (!determined && loop->header->frequency)\n-\t{\n-\t  int freq_in = 0;\n-\n-\t  FOR_EACH_EDGE (e, ei, loop->header->preds)\n-\t    if (e->src != loop->latch)\n-\t      freq_in += EDGE_FREQUENCY (e);\n-\n-\t  if (freq_in != 0)\n-\t    p = profile_probability::probability_in_gcov_type\n-\t\t\t (freq_in * iteration_bound, loop->header->frequency);\n-\t}\n       if (!(p > profile_probability::never ()))\n \tp = profile_probability::very_unlikely ();\n     }\n@@ -800,7 +780,7 @@ create_empty_loop_on_edge (edge entry_ed\n   loop->latch = loop_latch;\n   add_loop (loop, outer);\n \n-  /* TODO: Fix frequencies and counts.  */\n+  /* TODO: Fix counts.  */\n   scale_loop_frequencies (loop, profile_probability::even ());\n \n   /* Update dominators.  */\n@@ -866,13 +846,11 @@ loopify (edge latch_edge, edge header_ed\n   basic_block pred_bb = header_edge->src;\n   struct loop *loop = alloc_loop ();\n   struct loop *outer = loop_outer (succ_bb->loop_father);\n-  int freq;\n   profile_count cnt;\n \n   loop->header = header_edge->dest;\n   loop->latch = latch_edge->src;\n \n-  freq = EDGE_FREQUENCY (header_edge);\n   cnt = header_edge->count ();\n \n   /* Redirect edges.  */\n@@ -901,10 +879,9 @@ loopify (edge latch_edge, edge header_ed\n     remove_bb_from_loops (switch_bb);\n   add_bb_to_loop (switch_bb, outer);\n \n-  /* Fix frequencies.  */\n+  /* Fix counts.  */\n   if (redirect_all_edges)\n     {\n-      switch_bb->frequency = freq;\n       switch_bb->count = cnt;\n     }\n   scale_loop_frequencies (loop, false_scale);\n@@ -1167,7 +1144,7 @@ duplicate_loop_to_header_edge (struct lo\n     {\n       /* Calculate coefficients by that we have to scale frequencies\n \t of duplicated loop bodies.  */\n-      freq_in = header->frequency;\n+      freq_in = header->count.to_frequency (cfun);\n       freq_le = EDGE_FREQUENCY (latch_edge);\n       if (freq_in == 0)\n \tfreq_in = 1;\nIndex: cfgrtl.c\n===================================================================\n--- cfgrtl.c\t(revision 254348)\n+++ cfgrtl.c\t(working copy)\n@@ -1533,6 +1533,7 @@ force_nonfallthru_and_redirect (edge e,\n \n \t  basic_block bb = create_basic_block (BB_HEAD (e->dest), NULL,\n \t\t\t\t\t       ENTRY_BLOCK_PTR_FOR_FN (cfun));\n+\t  bb->count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;\n \n \t  /* Change the existing edge's source to be the new block, and add\n \t     a new edge from the entry block to the new block.  */\n@@ -1628,7 +1629,6 @@ force_nonfallthru_and_redirect (edge e,\n \n       jump_block = create_basic_block (new_head, NULL, e->src);\n       jump_block->count = count;\n-      jump_block->frequency = EDGE_FREQUENCY (e);\n \n       /* Make sure new block ends up in correct hot/cold section.  */\n \n@@ -1652,7 +1652,6 @@ force_nonfallthru_and_redirect (edge e,\n \t{\n \t  new_edge->probability = new_edge->probability.apply_scale (1, 2);\n \t  jump_block->count = jump_block->count.apply_scale (1, 2);\n-\t  jump_block->frequency /= 2;\n \t  edge new_edge2 = make_edge (new_edge->src, target,\n \t\t\t\t      e->flags & ~EDGE_FALLTHRU);\n \t  new_edge2->probability = probability - new_edge->probability;\n@@ -2245,9 +2244,23 @@ void\n update_br_prob_note (basic_block bb)\n {\n   rtx note;\n-  if (!JUMP_P (BB_END (bb)) || !BRANCH_EDGE (bb)->probability.initialized_p ())\n-    return;\n   note = find_reg_note (BB_END (bb), REG_BR_PROB, NULL_RTX);\n+  if (!JUMP_P (BB_END (bb)) || !BRANCH_EDGE (bb)->probability.initialized_p ())\n+    {\n+      if (note)\n+\t{\n+\t  rtx *note_link, this_rtx;\n+\n+\t  note_link = &REG_NOTES (BB_END (bb));\n+\t  for (this_rtx = *note_link; this_rtx; this_rtx = XEXP (this_rtx, 1))\n+\t    if (this_rtx == note)\n+\t      {\n+\t\t*note_link = XEXP (this_rtx, 1);\n+\t\tbreak;\n+\t      }\n+\t}\n+      return;\n+    }\n   if (!note\n       || XINT (note, 0) == BRANCH_EDGE (bb)->probability.to_reg_br_prob_note ())\n     return;\n@@ -3623,7 +3636,6 @@ relink_block_chain (bool stay_in_cfglayo\n \t    fprintf (dump_file, \"compensation \");\n \t  else\n \t    fprintf (dump_file, \"bb %i \", bb->index);\n-\t  fprintf (dump_file, \" [%i]\\n\", bb->frequency);\n \t}\n     }\n \n@@ -5034,7 +5046,7 @@ rtl_account_profile_record (basic_block\n \t    += insn_cost (insn, true) * bb->count.to_gcov_type ();\n \telse if (profile_status_for_fn (cfun) == PROFILE_GUESSED)\n \t  record->time[after_pass]\n-\t    += insn_cost (insn, true) * bb->frequency;\n+\t    += insn_cost (insn, true) * bb->count.to_frequency (cfun);\n       }\n }\n \nIndex: cgraph.c\n===================================================================\n--- cgraph.c\t(revision 254348)\n+++ cgraph.c\t(working copy)\n@@ -862,7 +862,7 @@ symbol_table::create_edge (cgraph_node *\n   edge->next_callee = NULL;\n   edge->lto_stmt_uid = 0;\n \n-  edge->count = count;\n+  edge->count = count.ipa ();\n   edge->frequency = freq;\n   gcc_checking_assert (freq >= 0);\n   gcc_checking_assert (freq <= CGRAPH_FREQ_MAX);\n@@ -1308,7 +1308,7 @@ cgraph_edge::redirect_call_stmt_to_calle\n \t  /* We are producing the final function body and will throw away the\n \t     callgraph edges really soon.  Reset the counts/frequencies to\n \t     keep verifier happy in the case of roundoff errors.  */\n-\t  e->count = gimple_bb (e->call_stmt)->count;\n+\t  e->count = gimple_bb (e->call_stmt)->count.ipa ();\n \t  e->frequency = compute_call_stmt_bb_frequency\n \t\t\t  (e->caller->decl, gimple_bb (e->call_stmt));\n \t}\n@@ -1338,7 +1338,7 @@ cgraph_edge::redirect_call_stmt_to_calle\n \t    prob = profile_probability::even ();\n \t  new_stmt = gimple_ic (e->call_stmt,\n \t\t\t\tdyn_cast<cgraph_node *> (ref->referred),\n-\t\t\t\tprob, e->count, e->count + e2->count);\n+\t\t\t\tprob);\n \t  e->speculative = false;\n \t  e->caller->set_call_stmt_including_clones (e->call_stmt, new_stmt,\n \t\t\t\t\t\t     false);\n@@ -1644,7 +1644,7 @@ cgraph_update_edges_for_call_stmt_node (\n \t  /* Otherwise remove edge and create new one; we can't simply redirect\n \t     since function has changed, so inline plan and other information\n \t     attached to edge is invalid.  */\n-\t  count = e->count;\n+\t  count = e->count.ipa ();\n \t  frequency = e->frequency;\n  \t  if (e->indirect_unknown_callee || e->inline_failed)\n \t    e->remove ();\n@@ -1655,7 +1655,7 @@ cgraph_update_edges_for_call_stmt_node (\n \t{\n \t  /* We are seeing new direct call; compute profile info based on BB.  */\n \t  basic_block bb = gimple_bb (new_stmt);\n-\t  count = bb->count;\n+\t  count = bb->count.ipa ();\n \t  frequency = compute_call_stmt_bb_frequency (current_function_decl,\n \t\t\t\t\t\t      bb);\n \t}\n@@ -3082,9 +3082,14 @@ bool\n cgraph_edge::verify_count_and_frequency ()\n {\n   bool error_found = false;\n-  if (count < 0)\n+  if (!count.verify ())\n     {\n-      error (\"caller edge count is negative\");\n+      error (\"caller edge count invalid\");\n+      error_found = true;\n+    }\n+  if (count.initialized_p () && !(count.ipa () == count))\n+    {\n+      error (\"caller edge count is local\");\n       error_found = true;\n     }\n   if (frequency < 0)\n@@ -3183,9 +3188,14 @@ cgraph_node::verify_node (void)\n \t       identifier_to_locale (e->callee->name ()));\n \terror_found = true;\n       }\n-  if (count < 0)\n+  if (!count.verify ())\n+    {\n+      error (\"cgraph count invalid\");\n+      error_found = true;\n+    }\n+  if (count.initialized_p () && !(count.ipa () == count))\n     {\n-      error (\"execution count is negative\");\n+      error (\"cgraph count is local\");\n       error_found = true;\n     }\n   if (global.inlined_to && same_comdat_group)\n@@ -3269,7 +3279,9 @@ cgraph_node::verify_node (void)\n     {\n       if (e->verify_count_and_frequency ())\n \terror_found = true;\n+      /* FIXME: re-enable once cgraph is converted to counts.  */\n       if (gimple_has_body_p (e->caller->decl)\n+\t  && 0\n \t  && !e->caller->global.inlined_to\n \t  && !e->speculative\n \t  /* Optimized out calls are redirected to __builtin_unreachable.  */\n@@ -3292,9 +3304,11 @@ cgraph_node::verify_node (void)\n     {\n       if (e->verify_count_and_frequency ())\n \terror_found = true;\n+      /* FIXME: re-enable once cgraph is converted to counts.  */\n       if (gimple_has_body_p (e->caller->decl)\n \t  && !e->caller->global.inlined_to\n \t  && !e->speculative\n+\t  && 0\n \t  && (e->frequency\n \t      != compute_call_stmt_bb_frequency (e->caller->decl,\n \t\t\t\t\t\t gimple_bb (e->call_stmt))))\nIndex: cgraphbuild.c\n===================================================================\n--- cgraphbuild.c\t(revision 254348)\n+++ cgraphbuild.c\t(working copy)\n@@ -190,21 +190,8 @@ record_eh_tables (cgraph_node *node, fun\n int\n compute_call_stmt_bb_frequency (tree decl, basic_block bb)\n {\n-  int entry_freq = ENTRY_BLOCK_PTR_FOR_FN\n-  \t\t     (DECL_STRUCT_FUNCTION (decl))->frequency;\n-  int freq = bb->frequency;\n-\n-  if (profile_status_for_fn (DECL_STRUCT_FUNCTION (decl)) == PROFILE_ABSENT)\n-    return CGRAPH_FREQ_BASE;\n-\n-  if (!entry_freq)\n-    entry_freq = 1, freq++;\n-\n-  freq = freq * CGRAPH_FREQ_BASE / entry_freq;\n-  if (freq > CGRAPH_FREQ_MAX)\n-    freq = CGRAPH_FREQ_MAX;\n-\n-  return freq;\n+  return bb->count.to_cgraph_frequency\n+      (ENTRY_BLOCK_PTR_FOR_FN (DECL_STRUCT_FUNCTION (decl))->count);\n }\n \n /* Mark address taken in STMT.  */\n@@ -415,7 +402,7 @@ cgraph_edge::rebuild_edges (void)\n   node->remove_callees ();\n   node->remove_all_references ();\n \n-  node->count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;\n+  node->count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.ipa ();\n \n   FOR_EACH_BB_FN (bb, cfun)\n     {\nIndex: cgraphunit.c\n===================================================================\n--- cgraphunit.c\t(revision 254348)\n+++ cgraphunit.c\t(working copy)\n@@ -1601,12 +1601,9 @@ init_lowered_empty_function (tree decl,\n \n   /* Create BB for body of the function and connect it properly.  */\n   ENTRY_BLOCK_PTR_FOR_FN (cfun)->count = count;\n-  ENTRY_BLOCK_PTR_FOR_FN (cfun)->frequency = BB_FREQ_MAX;\n   EXIT_BLOCK_PTR_FOR_FN (cfun)->count = count;\n-  EXIT_BLOCK_PTR_FOR_FN (cfun)->frequency = BB_FREQ_MAX;\n   bb = create_basic_block (NULL, ENTRY_BLOCK_PTR_FOR_FN (cfun));\n   bb->count = count;\n-  bb->frequency = BB_FREQ_MAX;\n   e = make_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun), bb, EDGE_FALLTHRU);\n   e->probability = profile_probability::always ();\n   e = make_edge (bb, EXIT_BLOCK_PTR_FOR_FN (cfun), 0);\n@@ -1852,8 +1849,12 @@ cgraph_node::expand_thunk (bool output_a\n       else\n \tresdecl = DECL_RESULT (thunk_fndecl);\n \n+      profile_count cfg_count = count;\n+      if (!cfg_count.initialized_p ())\n+\tcfg_count = profile_count::from_gcov_type (BB_FREQ_MAX).guessed_local ();\n+\n       bb = then_bb = else_bb = return_bb\n-\t= init_lowered_empty_function (thunk_fndecl, true, count);\n+\t= init_lowered_empty_function (thunk_fndecl, true, cfg_count);\n \n       bsi = gsi_start_bb (bb);\n \n@@ -1966,14 +1967,11 @@ cgraph_node::expand_thunk (bool output_a\n \t\t     adjustment, because that's why we're emitting a\n \t\t     thunk.  */\n \t\t  then_bb = create_basic_block (NULL, bb);\n-\t\t  then_bb->count = count - count.apply_scale (1, 16);\n-\t\t  then_bb->frequency = BB_FREQ_MAX - BB_FREQ_MAX / 16;\n+\t\t  then_bb->count = cfg_count - cfg_count.apply_scale (1, 16);\n \t\t  return_bb = create_basic_block (NULL, then_bb);\n-\t\t  return_bb->count = count;\n-\t\t  return_bb->frequency = BB_FREQ_MAX;\n+\t\t  return_bb->count = cfg_count;\n \t\t  else_bb = create_basic_block (NULL, else_bb);\n-\t\t  then_bb->count = count.apply_scale (1, 16);\n-\t\t  then_bb->frequency = BB_FREQ_MAX / 16;\n+\t\t  else_bb->count = cfg_count.apply_scale (1, 16);\n \t\t  add_bb_to_loop (then_bb, bb->loop_father);\n \t\t  add_bb_to_loop (return_bb, bb->loop_father);\n \t\t  add_bb_to_loop (else_bb, bb->loop_father);\n@@ -2028,8 +2026,10 @@ cgraph_node::expand_thunk (bool output_a\n \t}\n \n       cfun->gimple_df->in_ssa_p = true;\n+      counts_to_freqs ();\n       profile_status_for_fn (cfun)\n-        = count.initialized_p () ? PROFILE_READ : PROFILE_GUESSED;\n+        = cfg_count.initialized_p () && cfg_count.ipa_p ()\n+\t  ? PROFILE_READ : PROFILE_GUESSED;\n       /* FIXME: C++ FE should stop setting TREE_ASM_WRITTEN on thunks.  */\n       TREE_ASM_WRITTEN (thunk_fndecl) = false;\n       delete_unreachable_blocks ();\nIndex: except.c\n===================================================================\n--- except.c\t(revision 254348)\n+++ except.c\t(working copy)\n@@ -1003,7 +1003,6 @@ dw2_build_landing_pads (void)\n \n       bb = emit_to_new_bb_before (seq, label_rtx (lp->post_landing_pad));\n       bb->count = bb->next_bb->count;\n-      bb->frequency = bb->next_bb->frequency;\n       make_single_succ_edge (bb, bb->next_bb, e_flags);\n       if (current_loops)\n \t{\nIndex: final.c\n===================================================================\n--- final.c\t(revision 254348)\n+++ final.c\t(working copy)\n@@ -694,8 +694,8 @@ compute_alignments (void)\n     }\n   loop_optimizer_init (AVOID_CFG_MODIFICATIONS);\n   FOR_EACH_BB_FN (bb, cfun)\n-    if (bb->frequency > freq_max)\n-      freq_max = bb->frequency;\n+    if (bb->count.to_frequency (cfun) > freq_max)\n+      freq_max = bb->count.to_frequency (cfun);\n   freq_threshold = freq_max / PARAM_VALUE (PARAM_ALIGN_THRESHOLD);\n \n   if (dump_file)\n@@ -713,7 +713,8 @@ compute_alignments (void)\n \t  if (dump_file)\n \t    fprintf (dump_file,\n \t\t     \"BB %4i freq %4i loop %2i loop_depth %2i skipped.\\n\",\n-\t\t     bb->index, bb->frequency, bb->loop_father->num,\n+\t\t     bb->index, bb->count.to_frequency (cfun),\n+\t\t     bb->loop_father->num,\n \t\t     bb_loop_depth (bb));\n \t  continue;\n \t}\n@@ -731,7 +732,7 @@ compute_alignments (void)\n \t{\n \t  fprintf (dump_file, \"BB %4i freq %4i loop %2i loop_depth\"\n \t\t   \" %2i fall %4i branch %4i\",\n-\t\t   bb->index, bb->frequency, bb->loop_father->num,\n+\t\t   bb->index, bb->count.to_frequency (cfun), bb->loop_father->num,\n \t\t   bb_loop_depth (bb),\n \t\t   fallthru_frequency, branch_frequency);\n \t  if (!bb->loop_father->inner && bb->loop_father->num)\n@@ -753,9 +754,10 @@ compute_alignments (void)\n \n       if (!has_fallthru\n \t  && (branch_frequency > freq_threshold\n-\t      || (bb->frequency > bb->prev_bb->frequency * 10\n-\t\t  && (bb->prev_bb->frequency\n-\t\t      <= ENTRY_BLOCK_PTR_FOR_FN (cfun)->frequency / 2))))\n+\t      || (bb->count.to_frequency (cfun) \n+\t\t\t> bb->prev_bb->count.to_frequency (cfun) * 10\n+\t\t  && (bb->prev_bb->count.to_frequency (cfun)\n+\t\t      <= ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.to_frequency (cfun) / 2))))\n \t{\n \t  log = JUMP_ALIGN (label);\n \t  if (dump_file)\n@@ -1942,8 +1944,6 @@ dump_basic_block_info (FILE *file, rtx_i\n       edge_iterator ei;\n \n       fprintf (file, \"%s BLOCK %d\", ASM_COMMENT_START, bb->index);\n-      if (bb->frequency)\n-        fprintf (file, \" freq:%d\", bb->frequency);\n       if (bb->count.initialized_p ())\n \t{\n           fprintf (file, \", count:\");\nIndex: gimple-pretty-print.c\n===================================================================\n--- gimple-pretty-print.c\t(revision 254348)\n+++ gimple-pretty-print.c\t(working copy)\n@@ -82,21 +82,17 @@ debug_gimple_stmt (gimple *gs)\n    by xstrdup_for_dump.  */\n \n static const char *\n-dump_profile (int frequency, profile_count &count)\n+dump_profile (profile_count &count)\n {\n-  float minimum = 0.01f;\n-\n-  gcc_assert (0 <= frequency && frequency <= REG_BR_PROB_BASE);\n-  float fvalue = frequency * 100.0f / REG_BR_PROB_BASE;\n-  if (fvalue < minimum && frequency > 0)\n-    return \"[0.01%]\";\n-\n   char *buf;\n-  if (count.initialized_p ())\n-    buf = xasprintf (\"[%.2f%%] [count: %\" PRId64 \"]\", fvalue,\n+  if (!count.initialized_p ())\n+    return NULL;\n+  if (count.ipa_p ())\n+    buf = xasprintf (\"[count: %\" PRId64 \"]\",\n+\t\t     count.to_gcov_type ());\n+  else if (count.initialized_p ())\n+    buf = xasprintf (\"[local count: %\" PRId64 \"]\",\n \t\t     count.to_gcov_type ());\n-  else\n-    buf = xasprintf (\"[%.2f%%] [count: INV]\", fvalue);\n \n   const char *ret = xstrdup_for_dump (buf);\n   free (buf);\n@@ -2695,8 +2691,7 @@ dump_gimple_bb_header (FILE *outf, basic\n \tfprintf (outf, \"%*sbb_%d:\\n\", indent, \"\", bb->index);\n       else\n \tfprintf (outf, \"%*s<bb %d> %s:\\n\",\n-\t\t indent, \"\", bb->index, dump_profile (bb->frequency,\n-\t\t\t\t\t\t      bb->count));\n+\t\t indent, \"\", bb->index, dump_profile (bb->count));\n     }\n }\n \nIndex: gimple-ssa-isolate-paths.c\n===================================================================\n--- gimple-ssa-isolate-paths.c\t(revision 254348)\n+++ gimple-ssa-isolate-paths.c\t(working copy)\n@@ -154,7 +154,6 @@ isolate_path (basic_block bb, basic_bloc\n   if (!duplicate)\n     {\n       duplicate = duplicate_block (bb, NULL, NULL);\n-      bb->frequency = 0;\n       bb->count = profile_count::zero ();\n       if (!ret_zero)\n \tfor (ei = ei_start (duplicate->succs); (e2 = ei_safe_edge (ei)); )\n@@ -168,7 +167,7 @@ isolate_path (basic_block bb, basic_bloc\n       flush_pending_stmts (e2);\n \n       /* Update profile only when redirection is really processed.  */\n-      bb->frequency += EDGE_FREQUENCY (e);\n+      bb->count += e->count ();\n     }\n \n   /* There may be more than one statement in DUPLICATE which exhibits\nIndex: gimple-streamer-in.c\n===================================================================\n--- gimple-streamer-in.c\t(revision 254348)\n+++ gimple-streamer-in.c\t(working copy)\n@@ -266,7 +266,6 @@ input_bb (struct lto_input_block *ib, en\n \n   bb->count = profile_count::stream_in (ib).apply_scale\n \t\t (count_materialization_scale, REG_BR_PROB_BASE);\n-  bb->frequency = streamer_read_hwi (ib);\n   bb->flags = streamer_read_hwi (ib);\n \n   /* LTO_bb1 has statements.  LTO_bb0 does not.  */\nIndex: gimple-streamer-out.c\n===================================================================\n--- gimple-streamer-out.c\t(revision 254348)\n+++ gimple-streamer-out.c\t(working copy)\n@@ -210,7 +210,6 @@ output_bb (struct output_block *ob, basi\n \n   streamer_write_uhwi (ob, bb->index);\n   bb->count.stream_out (ob);\n-  streamer_write_hwi (ob, bb->frequency);\n   streamer_write_hwi (ob, bb->flags);\n \n   if (!gsi_end_p (bsi) || phi_nodes (bb))\nIndex: haifa-sched.c\n===================================================================\n--- haifa-sched.c\t(revision 254348)\n+++ haifa-sched.c\t(working copy)\n@@ -3917,8 +3917,8 @@ sched_pressure_start_bb (basic_block bb)\n       - call_saved_regs_num[cl]).  */\n   {\n     int i;\n-    int entry_freq = ENTRY_BLOCK_PTR_FOR_FN (cfun)->frequency;\n-    int bb_freq = bb->frequency;\n+    int entry_freq = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.to_frequency (cfun);\n+    int bb_freq = bb->count.to_frequency (cfun);\n \n     if (bb_freq == 0)\n       {\n@@ -8141,8 +8141,6 @@ init_before_recovery (basic_block *befor\n \n       single->count = last->count;\n       empty->count = last->count;\n-      single->frequency = last->frequency;\n-      empty->frequency = last->frequency;\n       BB_COPY_PARTITION (single, last);\n       BB_COPY_PARTITION (empty, last);\n \n@@ -8236,7 +8234,6 @@ sched_create_recovery_edges (basic_block\n      in sel-sched.c `check_ds' in create_speculation_check.  */\n   e->probability = profile_probability::very_unlikely ();\n   rec->count = e->count ();\n-  rec->frequency = EDGE_FREQUENCY (e);\n   e2->probability = e->probability.invert ();\n \n   rtx_code_label *label = block_label (second_bb);\nIndex: hsa-gen.c\n===================================================================\n--- hsa-gen.c\t(revision 254348)\n+++ hsa-gen.c\t(working copy)\n@@ -6374,7 +6374,7 @@ convert_switch_statements (void)\n \n \t\tedge next_edge = make_edge (cur_bb, next_bb, EDGE_FALSE_VALUE);\n \t\tnext_edge->probability = new_edge->probability.invert ();\n-\t\tnext_bb->frequency = EDGE_FREQUENCY (next_edge);\n+\t\tnext_bb->count = next_edge->count ();\n \t\tcur_bb = next_bb;\n \t      }\n \t    else /* Link last IF statement and default label\nIndex: ipa-cp.c\n===================================================================\n--- ipa-cp.c\t(revision 254348)\n+++ ipa-cp.c\t(working copy)\n@@ -3257,6 +3257,8 @@ ipcp_propagate_stage (struct ipa_topo_in\n   if (dump_file)\n     fprintf (dump_file, \"\\n Propagating constants:\\n\\n\");\n \n+  max_count = profile_count::uninitialized ();\n+\n   FOR_EACH_DEFINED_FUNCTION (node)\n   {\n     struct ipa_node_params *info = IPA_NODE_REF (node);\n@@ -3270,8 +3272,7 @@ ipcp_propagate_stage (struct ipa_topo_in\n       }\n     if (node->definition && !node->alias)\n       overall_size += ipa_fn_summaries->get (node)->self_size;\n-    if (node->count > max_count)\n-      max_count = node->count;\n+    max_count = max_count.max (node->count);\n   }\n \n   max_new_size = overall_size;\n@@ -5125,7 +5126,7 @@ make_pass_ipa_cp (gcc::context *ctxt)\n void\n ipa_cp_c_finalize (void)\n {\n-  max_count = profile_count::zero ();\n+  max_count = profile_count::uninitialized ();\n   overall_size = 0;\n   max_new_size = 0;\n }\nIndex: ipa-fnsummary.c\n===================================================================\n--- ipa-fnsummary.c\t(revision 254348)\n+++ ipa-fnsummary.c\t(working copy)\n@@ -1608,7 +1608,7 @@ static basic_block\n get_minimal_bb (basic_block init_bb, basic_block use_bb)\n {\n   struct loop *l = find_common_loop (init_bb->loop_father, use_bb->loop_father);\n-  if (l && l->header->frequency < init_bb->frequency)\n+  if (l && l->header->count < init_bb->count)\n     return l->header;\n   return init_bb;\n }\n@@ -1664,20 +1664,21 @@ param_change_prob (gimple *stmt, int i)\n     {\n       int init_freq;\n \n-      if (!bb->frequency)\n+      if (!bb->count.to_frequency (cfun))\n \treturn REG_BR_PROB_BASE;\n \n       if (SSA_NAME_IS_DEFAULT_DEF (base))\n-\tinit_freq = ENTRY_BLOCK_PTR_FOR_FN (cfun)->frequency;\n+\tinit_freq = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.to_frequency (cfun);\n       else\n \tinit_freq = get_minimal_bb\n \t\t      (gimple_bb (SSA_NAME_DEF_STMT (base)),\n-\t\t       gimple_bb (stmt))->frequency;\n+\t\t       gimple_bb (stmt))->count.to_frequency (cfun);\n \n       if (!init_freq)\n \tinit_freq = 1;\n-      if (init_freq < bb->frequency)\n-\treturn MAX (GCOV_COMPUTE_SCALE (init_freq, bb->frequency), 1);\n+      if (init_freq < bb->count.to_frequency (cfun))\n+\treturn MAX (GCOV_COMPUTE_SCALE (init_freq,\n+\t\t\t\t\tbb->count.to_frequency (cfun)), 1);\n       else\n \treturn REG_BR_PROB_BASE;\n     }\n@@ -1692,7 +1693,7 @@ param_change_prob (gimple *stmt, int i)\n \n       if (init != error_mark_node)\n \treturn 0;\n-      if (!bb->frequency)\n+      if (!bb->count.to_frequency (cfun))\n \treturn REG_BR_PROB_BASE;\n       ao_ref_init (&refd, op);\n       info.stmt = stmt;\n@@ -1708,17 +1709,17 @@ param_change_prob (gimple *stmt, int i)\n       /* Assume that every memory is initialized at entry.\n          TODO: Can we easilly determine if value is always defined\n          and thus we may skip entry block?  */\n-      if (ENTRY_BLOCK_PTR_FOR_FN (cfun)->frequency)\n-\tmax = ENTRY_BLOCK_PTR_FOR_FN (cfun)->frequency;\n+      if (ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.to_frequency (cfun))\n+\tmax = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.to_frequency (cfun);\n       else\n \tmax = 1;\n \n       EXECUTE_IF_SET_IN_BITMAP (info.bb_set, 0, index, bi)\n-\tmax = MIN (max, BASIC_BLOCK_FOR_FN (cfun, index)->frequency);\n+\tmax = MIN (max, BASIC_BLOCK_FOR_FN (cfun, index)->count.to_frequency (cfun));\n \n       BITMAP_FREE (info.bb_set);\n-      if (max < bb->frequency)\n-\treturn MAX (GCOV_COMPUTE_SCALE (max, bb->frequency), 1);\n+      if (max < bb->count.to_frequency (cfun))\n+\treturn MAX (GCOV_COMPUTE_SCALE (max, bb->count.to_frequency (cfun)), 1);\n       else\n \treturn REG_BR_PROB_BASE;\n     }\nIndex: ipa-inline-transform.c\n===================================================================\n--- ipa-inline-transform.c\t(revision 254348)\n+++ ipa-inline-transform.c\t(working copy)\n@@ -676,9 +676,9 @@ inline_transform (struct cgraph_node *no\n     {\n       profile_count num = node->count;\n       profile_count den = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;\n-      bool scale = num.initialized_p ()\n-\t\t   && (den > 0 || num == profile_count::zero ())\n-\t\t   && !(num == den);\n+      bool scale = num.initialized_p () && den.ipa_p ()\n+\t\t   && (den.nonzero_p () || num == profile_count::zero ())\n+\t\t   && !(num == den.ipa ());\n       if (scale)\n \t{\n \t  if (dump_file)\nIndex: ipa-inline.c\n===================================================================\n--- ipa-inline.c\t(revision 254348)\n+++ ipa-inline.c\t(working copy)\n@@ -640,8 +640,8 @@ compute_uninlined_call_time (struct cgra\n \t\t\t ? edge->caller->global.inlined_to\n \t\t\t : edge->caller);\n \n-  if (edge->count > profile_count::zero ()\n-      && caller->count > profile_count::zero ())\n+  if (edge->count.nonzero_p ()\n+      && caller->count.nonzero_p ())\n     uninlined_call_time *= (sreal)edge->count.to_gcov_type ()\n \t\t\t   / caller->count.to_gcov_type ();\n   if (edge->frequency)\n@@ -665,8 +665,8 @@ compute_inlined_call_time (struct cgraph\n \t\t\t : edge->caller);\n   sreal caller_time = ipa_fn_summaries->get (caller)->time;\n \n-  if (edge->count > profile_count::zero ()\n-      && caller->count > profile_count::zero ())\n+  if (edge->count.nonzero_p ()\n+      && caller->count.nonzero_p ())\n     time *= (sreal)edge->count.to_gcov_type () / caller->count.to_gcov_type ();\n   if (edge->frequency)\n     time *= cgraph_freq_base_rec * edge->frequency;\n@@ -733,7 +733,7 @@ want_inline_small_function_p (struct cgr\n       want_inline = false;\n     }\n   else if ((DECL_DECLARED_INLINE_P (callee->decl)\n-\t    || e->count > profile_count::zero ())\n+\t    || e->count.nonzero_p ())\n \t   && ipa_fn_summaries->get (callee)->min_size\n \t\t- ipa_call_summaries->get (e)->call_stmt_size\n \t      > 16 * MAX_INLINE_INSNS_SINGLE)\n@@ -843,7 +843,7 @@ want_inline_self_recursive_call_p (struc\n       reason = \"recursive call is cold\";\n       want_inline = false;\n     }\n-  else if (outer_node->count == profile_count::zero ())\n+  else if (!outer_node->count.nonzero_p ())\n     {\n       reason = \"not executed in profile\";\n       want_inline = false;\n@@ -881,7 +881,7 @@ want_inline_self_recursive_call_p (struc\n       int i;\n       for (i = 1; i < depth; i++)\n \tmax_prob = max_prob * max_prob / CGRAPH_FREQ_BASE;\n-      if (max_count > profile_count::zero () && edge->count > profile_count::zero ()\n+      if (max_count.nonzero_p () && edge->count.nonzero_p () \n \t  && (edge->count.to_gcov_type () * CGRAPH_FREQ_BASE\n \t      / outer_node->count.to_gcov_type ()\n \t      >= max_prob))\n@@ -889,7 +889,7 @@ want_inline_self_recursive_call_p (struc\n \t  reason = \"profile of recursive call is too large\";\n \t  want_inline = false;\n \t}\n-      if (max_count == profile_count::zero ()\n+      if (!max_count.nonzero_p ()\n \t  && (edge->frequency * CGRAPH_FREQ_BASE / caller_freq\n \t      >= max_prob))\n \t{\n@@ -915,7 +915,7 @@ want_inline_self_recursive_call_p (struc\n      methods.  */\n   else\n     {\n-      if (max_count > profile_count::zero () && edge->count.initialized_p ()\n+      if (max_count.nonzero_p () && edge->count.initialized_p ()\n \t  && (edge->count.to_gcov_type () * 100\n \t      / outer_node->count.to_gcov_type ()\n \t      <= PARAM_VALUE (PARAM_MIN_INLINE_RECURSIVE_PROBABILITY)))\n@@ -923,7 +923,7 @@ want_inline_self_recursive_call_p (struc\n \t  reason = \"profile of recursive call is too small\";\n \t  want_inline = false;\n \t}\n-      else if ((max_count == profile_count::zero ()\n+      else if ((!max_count.nonzero_p ()\n \t        || !edge->count.initialized_p ())\n \t       && (edge->frequency * 100 / caller_freq\n \t           <= PARAM_VALUE (PARAM_MIN_INLINE_RECURSIVE_PROBABILITY)))\n@@ -1070,7 +1070,7 @@ edge_badness (struct cgraph_edge *edge,\n      then calls without.\n   */\n   else if (opt_for_fn (caller->decl, flag_guess_branch_prob)\n-\t   || caller->count > profile_count::zero ())\n+\t   || caller->count.nonzero_p ())\n     {\n       sreal numerator, denominator;\n       int overall_growth;\n@@ -1080,7 +1080,7 @@ edge_badness (struct cgraph_edge *edge,\n \t\t   - inlined_time);\n       if (numerator == 0)\n \tnumerator = ((sreal) 1 >> 8);\n-      if (caller->count > profile_count::zero ())\n+      if (caller->count.nonzero_p ())\n \tnumerator *= caller->count.to_gcov_type ();\n       else if (caller->count.initialized_p ())\n \tnumerator = numerator >> 11;\n@@ -1521,7 +1521,7 @@ recursive_inlining (struct cgraph_edge *\n \t{\n \t  fprintf (dump_file,\n \t\t   \"   Inlining call of depth %i\", depth);\n-\t  if (node->count > profile_count::zero ())\n+\t  if (node->count.nonzero_p ())\n \t    {\n \t      fprintf (dump_file, \" called approx. %.2f times per call\",\n \t\t       (double)curr->count.to_gcov_type ()\n@@ -1684,7 +1684,8 @@ resolve_noninline_speculation (edge_heap\n \t\t\t\t  ? node->global.inlined_to : node;\n       auto_bitmap updated_nodes;\n \n-      spec_rem += edge->count;\n+      if (edge->count.initialized_p ())\n+        spec_rem += edge->count;\n       edge->resolve_speculation ();\n       reset_edge_caches (where);\n       ipa_update_overall_fn_summary (where);\n@@ -1789,8 +1790,7 @@ inline_small_functions (void)\n \t  }\n \n \tfor (edge = node->callers; edge; edge = edge->next_caller)\n-\t  if (!(max_count >= edge->count))\n-\t    max_count = edge->count;\n+\t  max_count = max_count.max (edge->count);\n       }\n   ipa_free_postorder_info ();\n   initialize_growth_caches ();\n@@ -2049,7 +2049,7 @@ inline_small_functions (void)\n       update_caller_keys (&edge_heap, where, updated_nodes, NULL);\n       /* Offline copy count has possibly changed, recompute if profile is\n \t available.  */\n-      if (max_count > profile_count::zero ())\n+      if (max_count.nonzero_p ())\n         {\n \t  struct cgraph_node *n = cgraph_node::get (edge->callee->decl);\n \t  if (n != edge->callee && n->analyzed)\n@@ -2392,6 +2392,7 @@ ipa_inline (void)\n     ipa_dump_fn_summaries (dump_file);\n \n   nnodes = ipa_reverse_postorder (order);\n+  spec_rem = profile_count::zero ();\n \n   FOR_EACH_FUNCTION (node)\n     {\n@@ -2487,8 +2488,9 @@ ipa_inline (void)\n \t      next = edge->next_callee;\n \t      if (edge->speculative && !speculation_useful_p (edge, false))\n \t\t{\n+\t\t  if (edge->count.initialized_p ())\n+\t\t    spec_rem += edge->count;\n \t\t  edge->resolve_speculation ();\n-\t\t  spec_rem += edge->count;\n \t\t  update = true;\n \t\t  remove_functions = true;\n \t\t}\nIndex: ipa-profile.c\n===================================================================\n--- ipa-profile.c\t(revision 254348)\n+++ ipa-profile.c\t(working copy)\n@@ -179,53 +179,54 @@ ipa_profile_generate_summary (void)\n   hash_table<histogram_hash> hashtable (10);\n   \n   FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node)\n-    FOR_EACH_BB_FN (bb, DECL_STRUCT_FUNCTION (node->decl))\n-      {\n-\tint time = 0;\n-\tint size = 0;\n-        for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))\n-\t  {\n-\t    gimple *stmt = gsi_stmt (gsi);\n-\t    if (gimple_code (stmt) == GIMPLE_CALL\n-\t\t&& !gimple_call_fndecl (stmt))\n-\t      {\n-\t\thistogram_value h;\n-\t\th = gimple_histogram_value_of_type\n-\t\t      (DECL_STRUCT_FUNCTION (node->decl),\n-\t\t       stmt, HIST_TYPE_INDIR_CALL);\n-\t\t/* No need to do sanity check: gimple_ic_transform already\n-\t\t   takes away bad histograms.  */\n-\t\tif (h)\n-\t\t  {\n-\t\t    /* counter 0 is target, counter 1 is number of execution we called target,\n-\t\t       counter 2 is total number of executions.  */\n-\t\t    if (h->hvalue.counters[2])\n-\t\t      {\n-\t\t\tstruct cgraph_edge * e = node->get_edge (stmt);\n-\t\t\tif (e && !e->indirect_unknown_callee)\n-\t\t\t  continue;\n-\t\t\te->indirect_info->common_target_id\n-\t\t\t  = h->hvalue.counters [0];\n-\t\t\te->indirect_info->common_target_probability\n-\t\t\t  = GCOV_COMPUTE_SCALE (h->hvalue.counters [1], h->hvalue.counters [2]);\n-\t\t\tif (e->indirect_info->common_target_probability > REG_BR_PROB_BASE)\n-\t\t\t  {\n-\t\t\t    if (dump_file)\n-\t\t\t      fprintf (dump_file, \"Probability capped to 1\\n\");\n-\t\t\t    e->indirect_info->common_target_probability = REG_BR_PROB_BASE;\n-\t\t\t  }\n-\t\t      }\n-\t\t    gimple_remove_histogram_value (DECL_STRUCT_FUNCTION (node->decl),\n-\t\t\t\t\t\t    stmt, h);\n-\t\t  }\n-\t      }\n-\t    time += estimate_num_insns (stmt, &eni_time_weights);\n-\t    size += estimate_num_insns (stmt, &eni_size_weights);\n-\t  }\n-\tif (bb->count.initialized_p ())\n-\t  account_time_size (&hashtable, histogram, bb->count.to_gcov_type (),\n-\t\t\t     time, size);\n-      }\n+    if (ENTRY_BLOCK_PTR_FOR_FN (DECL_STRUCT_FUNCTION (node->decl))->count.ipa_p ())\n+      FOR_EACH_BB_FN (bb, DECL_STRUCT_FUNCTION (node->decl))\n+\t{\n+\t  int time = 0;\n+\t  int size = 0;\n+\t  for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))\n+\t    {\n+\t      gimple *stmt = gsi_stmt (gsi);\n+\t      if (gimple_code (stmt) == GIMPLE_CALL\n+\t\t  && !gimple_call_fndecl (stmt))\n+\t\t{\n+\t\t  histogram_value h;\n+\t\t  h = gimple_histogram_value_of_type\n+\t\t\t(DECL_STRUCT_FUNCTION (node->decl),\n+\t\t\t stmt, HIST_TYPE_INDIR_CALL);\n+\t\t  /* No need to do sanity check: gimple_ic_transform already\n+\t\t     takes away bad histograms.  */\n+\t\t  if (h)\n+\t\t    {\n+\t\t      /* counter 0 is target, counter 1 is number of execution we called target,\n+\t\t\t counter 2 is total number of executions.  */\n+\t\t      if (h->hvalue.counters[2])\n+\t\t\t{\n+\t\t\t  struct cgraph_edge * e = node->get_edge (stmt);\n+\t\t\t  if (e && !e->indirect_unknown_callee)\n+\t\t\t    continue;\n+\t\t\t  e->indirect_info->common_target_id\n+\t\t\t    = h->hvalue.counters [0];\n+\t\t\t  e->indirect_info->common_target_probability\n+\t\t\t    = GCOV_COMPUTE_SCALE (h->hvalue.counters [1], h->hvalue.counters [2]);\n+\t\t\t  if (e->indirect_info->common_target_probability > REG_BR_PROB_BASE)\n+\t\t\t    {\n+\t\t\t      if (dump_file)\n+\t\t\t\tfprintf (dump_file, \"Probability capped to 1\\n\");\n+\t\t\t      e->indirect_info->common_target_probability = REG_BR_PROB_BASE;\n+\t\t\t    }\n+\t\t\t}\n+\t\t      gimple_remove_histogram_value (DECL_STRUCT_FUNCTION (node->decl),\n+\t\t\t\t\t\t      stmt, h);\n+\t\t    }\n+\t\t}\n+\t      time += estimate_num_insns (stmt, &eni_time_weights);\n+\t      size += estimate_num_insns (stmt, &eni_size_weights);\n+\t    }\n+\t  if (bb->count.ipa_p () && bb->count.initialized_p ())\n+\t    account_time_size (&hashtable, histogram, bb->count.ipa ().to_gcov_type (),\n+\t\t\t       time, size);\n+\t}\n   histogram.qsort (cmp_counts);\n }\n \nIndex: ipa-split.c\n===================================================================\n--- ipa-split.c\t(revision 254348)\n+++ ipa-split.c\t(working copy)\n@@ -444,7 +444,7 @@ consider_split (struct split_point *curr\n \n   /* Do not split when we would end up calling function anyway.  */\n   if (incoming_freq\n-      >= (ENTRY_BLOCK_PTR_FOR_FN (cfun)->frequency\n+      >= (ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.to_frequency (cfun)\n \t  * PARAM_VALUE (PARAM_PARTIAL_INLINING_ENTRY_PROBABILITY) / 100))\n     {\n       /* When profile is guessed, we can not expect it to give us\n@@ -454,13 +454,14 @@ consider_split (struct split_point *curr\n \t is likely noticeable win.  */\n       if (back_edge\n \t  && profile_status_for_fn (cfun) != PROFILE_READ\n-\t  && incoming_freq < ENTRY_BLOCK_PTR_FOR_FN (cfun)->frequency)\n+\t  && incoming_freq\n+\t\t < ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.to_frequency (cfun))\n \t{\n \t  if (dump_file && (dump_flags & TDF_DETAILS))\n \t    fprintf (dump_file,\n \t\t     \"  Split before loop, accepting despite low frequencies %i %i.\\n\",\n \t\t     incoming_freq,\n-\t\t     ENTRY_BLOCK_PTR_FOR_FN (cfun)->frequency);\n+\t\t     ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.to_frequency (cfun));\n \t}\n       else\n \t{\n@@ -714,8 +715,10 @@ consider_split (struct split_point *curr\n      out smallest size of header.\n      In future we might re-consider this heuristics.  */\n   if (!best_split_point.split_bbs\n-      || best_split_point.entry_bb->frequency > current->entry_bb->frequency\n-      || (best_split_point.entry_bb->frequency == current->entry_bb->frequency\n+      || best_split_point.entry_bb->count.to_frequency (cfun)\n+\t > current->entry_bb->count.to_frequency (cfun)\n+      || (best_split_point.entry_bb->count.to_frequency (cfun)\n+\t  == current->entry_bb->count.to_frequency (cfun)\n \t  && best_split_point.split_size < current->split_size))\n \t\n     {\n@@ -1285,7 +1288,7 @@ split_function (basic_block return_bb, s\n \t  FOR_EACH_EDGE (e, ei, return_bb->preds)\n \t    if (bitmap_bit_p (split_point->split_bbs, e->src->index))\n \t      {\n-\t\tnew_return_bb->frequency += EDGE_FREQUENCY (e);\n+\t\tnew_return_bb->count += e->count ();\n \t\tredirect_edge_and_branch (e, new_return_bb);\n \t\tredirected = true;\n \t\tbreak;\nIndex: ipa-utils.c\n===================================================================\n--- ipa-utils.c\t(revision 254348)\n+++ ipa-utils.c\t(working copy)\n@@ -524,7 +524,14 @@ ipa_merge_profiles (struct cgraph_node *\n \t  unsigned int i;\n \n \t  dstbb = BASIC_BLOCK_FOR_FN (dstcfun, srcbb->index);\n-\t  if (!dstbb->count.initialized_p ())\n+\n+\t  /* Either sum the profiles if both are IPA and not global0, or\n+\t     pick more informative one (that is nonzero IPA if other is\n+\t     uninitialized, guessed or global0).   */\n+\t  if (!dstbb->count.ipa ().initialized_p ()\n+\t      || (dstbb->count.ipa () == profile_count::zero ()\n+\t\t  && (srcbb->count.ipa ().initialized_p ()\n+\t\t      && !(srcbb->count.ipa () == profile_count::zero ()))))\n \t    {\n \t      dstbb->count = srcbb->count;\n \t      for (i = 0; i < EDGE_COUNT (srcbb->succs); i++)\n@@ -535,7 +542,8 @@ ipa_merge_profiles (struct cgraph_node *\n \t\t    dste->probability = srce->probability;\n \t\t}\n \t    }\t\n-\t  else if (srcbb->count.initialized_p ())\n+\t  else if (srcbb->count.ipa ().initialized_p ()\n+\t\t   && !(srcbb->count.ipa () == profile_count::zero ()))\n \t    {\n \t      for (i = 0; i < EDGE_COUNT (srcbb->succs); i++)\n \t\t{\n@@ -556,7 +564,7 @@ ipa_merge_profiles (struct cgraph_node *\n \t{\n \t  if (e->speculative)\n \t    continue;\n-\t  e->count = gimple_bb (e->call_stmt)->count;\n+\t  e->count = gimple_bb (e->call_stmt)->count.ipa ();\n \t  e->frequency = compute_call_stmt_bb_frequency\n \t\t\t     (dst->decl,\n \t\t\t      gimple_bb (e->call_stmt));\n@@ -634,7 +642,7 @@ ipa_merge_profiles (struct cgraph_node *\n \t      ipa_ref *ref;\n \n \t      e2->speculative_call_info (direct, indirect, ref);\n-\t      e->count = count;\n+\t      e->count = count.ipa ();\n \t      e->frequency = freq;\n \t      int prob = direct->count.probability_in (e->count)\n \t\t\t .to_reg_br_prob_base ();\n@@ -643,7 +651,7 @@ ipa_merge_profiles (struct cgraph_node *\n \t    }\n \t  else\n \t    {\n-\t      e->count = count;\n+\t      e->count = count.ipa ();\n \t      e->frequency = freq;\n \t    }\n \t}\nIndex: ira-build.c\n===================================================================\n--- ira-build.c\t(revision 254348)\n+++ ira-build.c\t(working copy)\n@@ -2202,7 +2202,8 @@ loop_compare_func (const void *v1p, cons\n     return -1;\n   if (! l1->to_remove_p && l2->to_remove_p)\n     return 1;\n-  if ((diff = l1->loop->header->frequency - l2->loop->header->frequency) != 0)\n+  if ((diff = l1->loop->header->count.to_frequency (cfun)\n+\t      - l2->loop->header->count.to_frequency (cfun)) != 0)\n     return diff;\n   if ((diff = (int) loop_depth (l1->loop) - (int) loop_depth (l2->loop)) != 0)\n     return diff;\n@@ -2260,7 +2261,7 @@ mark_loops_for_removal (void)\n \t  (ira_dump_file,\n \t   \"  Mark loop %d (header %d, freq %d, depth %d) for removal (%s)\\n\",\n \t   sorted_loops[i]->loop_num, sorted_loops[i]->loop->header->index,\n-\t   sorted_loops[i]->loop->header->frequency,\n+\t   sorted_loops[i]->loop->header->count.to_frequency (cfun),\n \t   loop_depth (sorted_loops[i]->loop),\n \t   low_pressure_loop_node_p (sorted_loops[i]->parent)\n \t   && low_pressure_loop_node_p (sorted_loops[i])\n@@ -2293,7 +2294,7 @@ mark_all_loops_for_removal (void)\n \t     \"  Mark loop %d (header %d, freq %d, depth %d) for removal\\n\",\n \t     ira_loop_nodes[i].loop_num,\n \t     ira_loop_nodes[i].loop->header->index,\n-\t     ira_loop_nodes[i].loop->header->frequency,\n+\t     ira_loop_nodes[i].loop->header->count.to_frequency (cfun),\n \t     loop_depth (ira_loop_nodes[i].loop));\n       }\n }\nIndex: loop-doloop.c\n===================================================================\n--- loop-doloop.c\t(revision 254348)\n+++ loop-doloop.c\t(working copy)\n@@ -506,7 +506,6 @@ doloop_modify (struct loop *loop, struct\n       set_immediate_dominator (CDI_DOMINATORS, new_preheader, preheader);\n \n       set_zero->count = profile_count::uninitialized ();\n-      set_zero->frequency = 0;\n \n       te = single_succ_edge (preheader);\n       for (; ass; ass = XEXP (ass, 1))\n@@ -522,7 +521,6 @@ doloop_modify (struct loop *loop, struct\n \t     also be very hard to show that it is impossible, so we must\n \t     handle this case.  */\n \t  set_zero->count = preheader->count;\n-\t  set_zero->frequency = preheader->frequency;\n \t}\n \n       if (EDGE_COUNT (set_zero->preds) == 0)\nIndex: loop-unroll.c\n===================================================================\n--- loop-unroll.c\t(revision 254348)\n+++ loop-unroll.c\t(working copy)\n@@ -863,7 +863,7 @@ unroll_loop_runtime_iterations (struct l\n   unsigned i, j;\n   profile_probability p;\n   basic_block preheader, *body, swtch, ezc_swtch = NULL;\n-  int may_exit_copy, iter_freq, new_freq;\n+  int may_exit_copy;\n   profile_count iter_count, new_count;\n   unsigned n_peel;\n   edge e;\n@@ -970,12 +970,10 @@ unroll_loop_runtime_iterations (struct l\n   /* Record the place where switch will be built for preconditioning.  */\n   swtch = split_edge (loop_preheader_edge (loop));\n \n-  /* Compute frequency/count increments for each switch block and initialize\n+  /* Compute count increments for each switch block and initialize\n      innermost switch block.  Switch blocks and peeled loop copies are built\n      from innermost outward.  */\n-  iter_freq = new_freq = swtch->frequency / (max_unroll + 1);\n   iter_count = new_count = swtch->count.apply_scale (1, max_unroll + 1);\n-  swtch->frequency = new_freq;\n   swtch->count = new_count;\n \n   for (i = 0; i < n_peel; i++)\n@@ -995,8 +993,7 @@ unroll_loop_runtime_iterations (struct l\n       p = profile_probability::always ().apply_scale (1, i + 2);\n \n       preheader = split_edge (loop_preheader_edge (loop));\n-      /* Add in frequency/count of edge from switch block.  */\n-      preheader->frequency += iter_freq;\n+      /* Add in count of edge from switch block.  */\n       preheader->count += iter_count;\n       branch_code = compare_and_jump_seq (copy_rtx (niter), GEN_INT (j), EQ,\n \t\t\t\t\t  block_label (preheader), p,\n@@ -1009,9 +1006,7 @@ unroll_loop_runtime_iterations (struct l\n       swtch = split_edge_and_insert (single_pred_edge (swtch), branch_code);\n       set_immediate_dominator (CDI_DOMINATORS, preheader, swtch);\n       single_succ_edge (swtch)->probability = p.invert ();\n-      new_freq += iter_freq;\n       new_count += iter_count;\n-      swtch->frequency = new_freq;\n       swtch->count = new_count;\n       e = make_edge (swtch, preheader,\n \t\t     single_succ_edge (swtch)->flags & EDGE_IRREDUCIBLE_LOOP);\n@@ -1024,12 +1019,10 @@ unroll_loop_runtime_iterations (struct l\n       p = profile_probability::always ().apply_scale (1, max_unroll + 1);\n       swtch = ezc_swtch;\n       preheader = split_edge (loop_preheader_edge (loop));\n-      /* Recompute frequency/count adjustments since initial peel copy may\n+      /* Recompute count adjustments since initial peel copy may\n \t have exited and reduced those values that were computed above.  */\n-      iter_freq = swtch->frequency / (max_unroll + 1);\n       iter_count = swtch->count.apply_scale (1, max_unroll + 1);\n-      /* Add in frequency/count of edge from switch block.  */\n-      preheader->frequency += iter_freq;\n+      /* Add in count of edge from switch block.  */\n       preheader->count += iter_count;\n       branch_code = compare_and_jump_seq (copy_rtx (niter), const0_rtx, EQ,\n \t\t\t\t\t  block_label (preheader), p,\nIndex: lto-streamer-in.c\n===================================================================\n--- lto-streamer-in.c\t(revision 254348)\n+++ lto-streamer-in.c\t(working copy)\n@@ -1192,6 +1192,7 @@ input_function (tree fn_decl, struct dat\n     gimple_set_body (fn_decl, bb_seq (ei_edge (ei)->dest));\n   }\n \n+  counts_to_freqs ();\n   fixup_call_stmt_edges (node, stmts);\n   execute_all_ipa_stmt_fixups (node, stmts);\n \nIndex: omp-expand.c\n===================================================================\n--- omp-expand.c\t(revision 254348)\n+++ omp-expand.c\t(working copy)\n@@ -1399,6 +1399,7 @@ expand_omp_taskreg (struct omp_region *r\n \n       if (optimize)\n \toptimize_omp_library_calls (entry_stmt);\n+      counts_to_freqs ();\n       cgraph_edge::rebuild_edges ();\n \n       /* Some EH regions might become dead, see PR34608.  If\nIndex: omp-simd-clone.c\n===================================================================\n--- omp-simd-clone.c\t(revision 254348)\n+++ omp-simd-clone.c\t(working copy)\n@@ -1132,6 +1132,7 @@ simd_clone_adjust (struct cgraph_node *n\n     {\n       basic_block orig_exit = EDGE_PRED (EXIT_BLOCK_PTR_FOR_FN (cfun), 0)->src;\n       incr_bb = create_empty_bb (orig_exit);\n+      incr_bb->count = profile_count::zero ();\n       add_bb_to_loop (incr_bb, body_bb->loop_father);\n       /* The succ of orig_exit was EXIT_BLOCK_PTR_FOR_FN (cfun), with an empty\n \t flag.  Set it now to be a FALLTHRU_EDGE.  */\n@@ -1142,11 +1143,13 @@ simd_clone_adjust (struct cgraph_node *n\n \t{\n \t  edge e = EDGE_PRED (EXIT_BLOCK_PTR_FOR_FN (cfun), i);\n \t  redirect_edge_succ (e, incr_bb);\n+\t  incr_bb->count += e->count ();\n \t}\n     }\n   else if (node->simdclone->inbranch)\n     {\n       incr_bb = create_empty_bb (entry_bb);\n+      incr_bb->count = profile_count::zero ();\n       add_bb_to_loop (incr_bb, body_bb->loop_father);\n     }\n \n@@ -1243,6 +1246,7 @@ simd_clone_adjust (struct cgraph_node *n\n       gsi_insert_after (&gsi, g, GSI_CONTINUE_LINKING);\n       edge e = make_edge (loop->header, incr_bb, EDGE_TRUE_VALUE);\n       e->probability = profile_probability::unlikely ().guessed ();\n+      incr_bb->count += e->count ();\n       edge fallthru = FALLTHRU_EDGE (loop->header);\n       fallthru->flags = EDGE_FALSE_VALUE;\n       fallthru->probability = profile_probability::likely ().guessed ();\nIndex: predict.c\n===================================================================\n--- predict.c\t(revision 254348)\n+++ predict.c\t(working copy)\n@@ -137,12 +137,12 @@ maybe_hot_frequency_p (struct function *\n   if (profile_status_for_fn (fun) == PROFILE_ABSENT)\n     return true;\n   if (node->frequency == NODE_FREQUENCY_EXECUTED_ONCE\n-      && freq < (ENTRY_BLOCK_PTR_FOR_FN (fun)->frequency * 2 / 3))\n+      && freq < (ENTRY_BLOCK_PTR_FOR_FN (fun)->count.to_frequency (cfun) * 2 / 3))\n     return false;\n   if (PARAM_VALUE (HOT_BB_FREQUENCY_FRACTION) == 0)\n     return false;\n   if (freq * PARAM_VALUE (HOT_BB_FREQUENCY_FRACTION)\n-      < ENTRY_BLOCK_PTR_FOR_FN (fun)->frequency)\n+      < ENTRY_BLOCK_PTR_FOR_FN (fun)->count.to_frequency (cfun))\n     return false;\n   return true;\n }\n@@ -175,10 +175,14 @@ set_hot_bb_threshold (gcov_type min)\n /* Return TRUE if frequency FREQ is considered to be hot.  */\n \n bool\n-maybe_hot_count_p (struct function *, profile_count count)\n+maybe_hot_count_p (struct function *fun, profile_count count)\n {\n   if (!count.initialized_p ())\n     return true;\n+  if (!count.ipa_p ())\n+    return maybe_hot_frequency_p (fun, count.to_frequency (fun));\n+  if (count.ipa () == profile_count::zero ())\n+    return false;\n   /* Code executed at most once is not hot.  */\n   if (count <= MAX (profile_info ? profile_info->runs : 1, 1))\n     return false;\n@@ -192,9 +196,7 @@ bool\n maybe_hot_bb_p (struct function *fun, const_basic_block bb)\n {\n   gcc_checking_assert (fun);\n-  if (!maybe_hot_count_p (fun, bb->count))\n-    return false;\n-  return maybe_hot_frequency_p (fun, bb->frequency);\n+  return maybe_hot_count_p (fun, bb->count);\n }\n \n /* Return true in case BB can be CPU intensive and should be optimized\n@@ -203,9 +205,7 @@ maybe_hot_bb_p (struct function *fun, co\n bool\n maybe_hot_edge_p (edge e)\n {\n-  if (!maybe_hot_count_p (cfun, e->count ()))\n-    return false;\n-  return maybe_hot_frequency_p (cfun, EDGE_FREQUENCY (e));\n+  return maybe_hot_count_p (cfun, e->count ());\n }\n \n /* Return true if profile COUNT and FREQUENCY, or function FUN static\n@@ -213,7 +213,7 @@ maybe_hot_edge_p (edge e)\n    \n static bool\n probably_never_executed (struct function *fun,\n-                         profile_count count, int)\n+                         profile_count count)\n {\n   gcc_checking_assert (fun);\n   if (count == profile_count::zero ())\n@@ -238,7 +238,7 @@ probably_never_executed (struct function\n bool\n probably_never_executed_bb_p (struct function *fun, const_basic_block bb)\n {\n-  return probably_never_executed (fun, bb->count, bb->frequency);\n+  return probably_never_executed (fun, bb->count);\n }\n \n \n@@ -259,7 +259,7 @@ probably_never_executed_edge_p (struct f\n {\n   if (unlikely_executed_edge_p (e))\n     return true;\n-  return probably_never_executed (fun, e->count (), EDGE_FREQUENCY (e));\n+  return probably_never_executed (fun, e->count ());\n }\n \n /* Return true when current function should always be optimized for size.  */\n@@ -1289,7 +1289,8 @@ combine_predictions_for_bb (basic_block\n     }\n   clear_bb_predictions (bb);\n \n-  if (!bb->count.initialized_p () && !dry_run)\n+  if ((!bb->count.nonzero_p () || !first->probability.initialized_p ())\n+      && !dry_run)\n     {\n       first->probability\n \t = profile_probability::from_reg_br_prob_base (combined_probability);\n@@ -3014,10 +3015,7 @@ propagate_freq (basic_block head, bitmap\n       BLOCK_INFO (bb)->npredecessors = count;\n       /* When function never returns, we will never process exit block.  */\n       if (!count && bb == EXIT_BLOCK_PTR_FOR_FN (cfun))\n-\t{\n-\t  bb->count = profile_count::zero ();\n-\t  bb->frequency = 0;\n-\t}\n+\tbb->count = profile_count::zero ();\n     }\n \n   BLOCK_INFO (head)->frequency = 1;\n@@ -3050,7 +3048,10 @@ propagate_freq (basic_block head, bitmap\n \t\t\t\t  * BLOCK_INFO (e->src)->frequency /\n \t\t\t\t  REG_BR_PROB_BASE);  */\n \n-\t\tsreal tmp = e->probability.to_reg_br_prob_base ();\n+\t\t/* FIXME: Graphite is producing edges with no profile. Once\n+\t\t   this is fixed, drop this.  */\n+\t\tsreal tmp = e->probability.initialized_p () ?\n+\t\t\t    e->probability.to_reg_br_prob_base () : 0;\n \t\ttmp *= BLOCK_INFO (e->src)->frequency;\n \t\ttmp *= real_inv_br_prob_base;\n \t\tfrequency += tmp;\n@@ -3082,7 +3083,10 @@ propagate_freq (basic_block head, bitmap\n \t     = ((e->probability * BLOCK_INFO (bb)->frequency)\n \t     / REG_BR_PROB_BASE); */\n \n-\t  sreal tmp = e->probability.to_reg_br_prob_base ();\n+\t  /* FIXME: Graphite is producing edges with no profile. Once\n+\t     this is fixed, drop this.  */\n+\t  sreal tmp = e->probability.initialized_p () ?\n+\t\t      e->probability.to_reg_br_prob_base () : 0;\n \t  tmp *= BLOCK_INFO (bb)->frequency;\n \t  EDGE_INFO (e)->back_edge_prob = tmp * real_inv_br_prob_base;\n \t}\n@@ -3196,10 +3200,26 @@ drop_profile (struct cgraph_node *node,\n     }\n \n   basic_block bb;\n-  FOR_ALL_BB_FN (bb, fn)\n+  push_cfun (DECL_STRUCT_FUNCTION (node->decl));\n+  if (flag_guess_branch_prob)\n     {\n-      bb->count = profile_count::uninitialized ();\n+      bool clear_zeros\n+\t = ENTRY_BLOCK_PTR_FOR_FN\n+\t\t (DECL_STRUCT_FUNCTION (node->decl))->count.nonzero_p ();\n+      FOR_ALL_BB_FN (bb, fn)\n+\tif (clear_zeros || !(bb->count == profile_count::zero ()))\n+\t  bb->count = bb->count.guessed_local ();\n+      DECL_STRUCT_FUNCTION (node->decl)->cfg->count_max =\n+        DECL_STRUCT_FUNCTION (node->decl)->cfg->count_max.guessed_local ();\n     }\n+  else\n+    {\n+      FOR_ALL_BB_FN (bb, fn)\n+\tbb->count = profile_count::uninitialized ();\n+      DECL_STRUCT_FUNCTION (node->decl)->cfg->count_max\n+\t = profile_count::uninitialized ();\n+    }\n+  pop_cfun ();\n \n   struct cgraph_edge *e;\n   for (e = node->callees; e; e = e->next_caller)\n@@ -3300,33 +3320,16 @@ handle_missing_profiles (void)\n bool\n counts_to_freqs (void)\n {\n-  gcov_type count_max;\n-  profile_count true_count_max = profile_count::zero ();\n+  profile_count true_count_max = profile_count::uninitialized ();\n   basic_block bb;\n \n-  /* Don't overwrite the estimated frequencies when the profile for\n-     the function is missing.  We may drop this function PROFILE_GUESSED\n-     later in drop_profile ().  */\n-  if (!ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.initialized_p ()\n-      || ENTRY_BLOCK_PTR_FOR_FN (cfun)->count == profile_count::zero ())\n-    return false;\n-\n   FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (cfun), NULL, next_bb)\n-    if (bb->count > true_count_max)\n-      true_count_max = bb->count;\n+    if (!(bb->count < true_count_max))\n+      true_count_max = true_count_max.max (bb->count);\n \n-  /* If we have no counts to base frequencies on, keep those that are\n-     already there.  */\n-  if (!(true_count_max > 0))\n-    return false;\n-\n-  count_max = true_count_max.to_gcov_type ();\n+  cfun->cfg->count_max = true_count_max;\n \n-  FOR_ALL_BB_FN (bb, cfun)\n-    if (bb->count.initialized_p ())\n-      bb->frequency = RDIV (bb->count.to_gcov_type () * BB_FREQ_MAX, count_max);\n-\n-  return true;\n+  return true_count_max.nonzero_p ();\n }\n \n /* Return true if function is likely to be expensive, so there is no point to\n@@ -3348,11 +3351,11 @@ expensive_function_p (int threshold)\n   /* Frequencies are out of range.  This either means that function contains\n      internal loop executing more than BB_FREQ_MAX times or profile feedback\n      is available and function has not been executed at all.  */\n-  if (ENTRY_BLOCK_PTR_FOR_FN (cfun)->frequency == 0)\n+  if (ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.to_frequency (cfun) == 0)\n     return true;\n \n   /* Maximally BB_FREQ_MAX^2 so overflow won't happen.  */\n-  limit = ENTRY_BLOCK_PTR_FOR_FN (cfun)->frequency * threshold;\n+  limit = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.to_frequency (cfun) * threshold;\n   FOR_EACH_BB_FN (bb, cfun)\n     {\n       rtx_insn *insn;\n@@ -3360,7 +3363,7 @@ expensive_function_p (int threshold)\n       FOR_BB_INSNS (bb, insn)\n \tif (active_insn_p (insn))\n \t  {\n-\t    sum += bb->frequency;\n+\t    sum += bb->count.to_frequency (cfun);\n \t    if (sum > limit)\n \t      return true;\n \t}\n@@ -3409,7 +3412,6 @@ propagate_unlikely_bbs_forward (void)\n \t\t     \"Basic block %i is marked unlikely by forward prop\\n\",\n \t\t     bb->index);\n \t  bb->count = profile_count::zero ();\n-\t  bb->frequency = 0;\n \t}\n       else\n         bb->aux = NULL;\n@@ -3440,9 +3442,6 @@ determine_unlikely_bbs ()\n \t  bb->count = profile_count::zero ();\n \t}\n \n-      if (bb->count == profile_count::zero ())\n-        bb->frequency = 0;\n-\n       FOR_EACH_EDGE (e, ei, bb->succs)\n \tif (!(e->probability == profile_probability::never ())\n \t    && unlikely_executed_edge_p (e))\n@@ -3497,7 +3496,6 @@ determine_unlikely_bbs ()\n \t\t \"Basic block %i is marked unlikely by backward prop\\n\",\n \t\t bb->index);\n       bb->count = profile_count::zero ();\n-      bb->frequency = 0;\n       FOR_EACH_EDGE (e, ei, bb->preds)\n \tif (!(e->probability == profile_probability::never ()))\n \t  {\n@@ -3554,8 +3552,13 @@ estimate_bb_frequencies (bool force)\n \n \t  FOR_EACH_EDGE (e, ei, bb->succs)\n \t    {\n-\t      EDGE_INFO (e)->back_edge_prob\n-\t\t = e->probability.to_reg_br_prob_base ();\n+\t      /* FIXME: Graphite is producing edges with no profile. Once\n+\t\t this is fixed, drop this.  */\n+\t      if (e->probability.initialized_p ())\n+\t        EDGE_INFO (e)->back_edge_prob\n+\t\t   = e->probability.to_reg_br_prob_base ();\n+\t      else\n+\t\tEDGE_INFO (e)->back_edge_prob = REG_BR_PROB_BASE / 2;\n \t      EDGE_INFO (e)->back_edge_prob *= real_inv_br_prob_base;\n \t    }\n \t}\n@@ -3564,16 +3567,28 @@ estimate_bb_frequencies (bool force)\n          to outermost to examine frequencies for back edges.  */\n       estimate_loops ();\n \n+      bool global0 = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.initialized_p ()\n+\t\t     && ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.ipa_p ();\n+\n       freq_max = 0;\n       FOR_EACH_BB_FN (bb, cfun)\n \tif (freq_max < BLOCK_INFO (bb)->frequency)\n \t  freq_max = BLOCK_INFO (bb)->frequency;\n \n       freq_max = real_bb_freq_max / freq_max;\n+      cfun->cfg->count_max = profile_count::uninitialized ();\n       FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (cfun), NULL, next_bb)\n \t{\n \t  sreal tmp = BLOCK_INFO (bb)->frequency * freq_max + real_one_half;\n-\t  bb->frequency = tmp.to_int ();\n+\t  profile_count count = profile_count::from_gcov_type (tmp.to_int ());\t\n+\n+\t  /* If we have profile feedback in which this function was never\n+\t     executed, then preserve this info.  */\n+\t  if (global0)\n+\t    bb->count = count.global0 ();\n+\t  else if (!(bb->count == profile_count::zero ()))\n+\t    bb->count = count.guessed_local ();\n+          cfun->cfg->count_max = cfun->cfg->count_max.max (bb->count);\n \t}\n \n       free_aux_for_blocks ();\n@@ -3598,7 +3613,8 @@ compute_function_frequency (void)\n   if (profile_status_for_fn (cfun) != PROFILE_READ)\n     {\n       int flags = flags_from_decl_or_type (current_function_decl);\n-      if (ENTRY_BLOCK_PTR_FOR_FN (cfun)->count == profile_count::zero ()\n+      if ((ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.ipa_p ()\n+\t   && ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.ipa() == profile_count::zero ())\n \t  || lookup_attribute (\"cold\", DECL_ATTRIBUTES (current_function_decl))\n \t     != NULL)\n \t{\n@@ -3717,7 +3733,7 @@ pass_profile::execute (function *fun)\n    {\n      struct loop *loop;\n      FOR_EACH_LOOP (loop, LI_FROM_INNERMOST)\n-       if (loop->header->frequency)\n+       if (loop->header->count.initialized_p ())\n          fprintf (dump_file, \"Loop got predicted %d to iterate %i times.\\n\",\n        \t   loop->num,\n        \t   (int)expected_loop_iterations_unbounded (loop));\n@@ -3843,15 +3859,12 @@ rebuild_frequencies (void)\n      which may also lead to frequencies incorrectly reduced to 0. There\n      is less precision in the probabilities, so we only do this for small\n      max counts.  */\n-  profile_count count_max = profile_count::zero ();\n+  cfun->cfg->count_max = profile_count::uninitialized ();\n   basic_block bb;\n   FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (cfun), NULL, next_bb)\n-    if (bb->count > count_max)\n-      count_max = bb->count;\n+    cfun->cfg->count_max = cfun->cfg->count_max.max (bb->count);\n \n-  if (profile_status_for_fn (cfun) == PROFILE_GUESSED\n-      || (!flag_auto_profile && profile_status_for_fn (cfun) == PROFILE_READ\n-\t  && count_max < REG_BR_PROB_BASE / 10))\n+  if (profile_status_for_fn (cfun) == PROFILE_GUESSED)\n     {\n       loop_optimizer_init (0);\n       add_noreturn_fake_exit_edges ();\n@@ -4017,17 +4030,19 @@ force_edge_cold (edge e, bool impossible\n \t after loop transforms.  */\n       if (!(prob_sum > profile_probability::never ())\n \t  && count_sum == profile_count::zero ()\n-\t  && single_pred_p (e->src) && e->src->frequency > (impossible ? 0 : 1))\n+\t  && single_pred_p (e->src) && e->src->count.to_frequency (cfun)\n+\t     > (impossible ? 0 : 1))\n \t{\n-\t  int old_frequency = e->src->frequency;\n+\t  int old_frequency = e->src->count.to_frequency (cfun);\n \t  if (dump_file && (dump_flags & TDF_DETAILS))\n \t    fprintf (dump_file, \"Making bb %i %s.\\n\", e->src->index,\n \t\t     impossible ? \"impossible\" : \"cold\");\n-\t  e->src->frequency = MIN (e->src->frequency, impossible ? 0 : 1);\n+\t  int new_frequency = MIN (e->src->count.to_frequency (cfun),\n+\t\t\t\t   impossible ? 0 : 1);\n \t  if (impossible)\n \t    e->src->count = profile_count::zero ();\n \t  else\n-\t    e->src->count = e->count ().apply_scale (e->src->frequency,\n+\t    e->src->count = e->count ().apply_scale (new_frequency,\n \t\t\t\t\t\t     old_frequency);\n \t  force_edge_cold (single_pred_edge (e->src), impossible);\n \t}\nIndex: profile-count.c\n===================================================================\n--- profile-count.c\t(revision 254348)\n+++ profile-count.c\t(working copy)\n@@ -42,7 +42,11 @@ profile_count::dump (FILE *f) const\n   else\n     {\n       fprintf (f, \"%\" PRId64, m_val);\n-      if (m_quality == profile_adjusted)\n+      if (m_quality == profile_guessed_local)\n+\tfprintf (f, \" (estimated locally)\");\n+      else if (m_quality == profile_guessed_global0)\n+\tfprintf (f, \" (estimated locally, globally 0)\");\n+      else if (m_quality == profile_adjusted)\n \tfprintf (f, \" (adjusted)\");\n       else if (m_quality == profile_afdo)\n \tfprintf (f, \" (auto FDO)\");\n@@ -65,6 +69,7 @@ profile_count::debug () const\n bool\n profile_count::differs_from_p (profile_count other) const\n {\n+  gcc_checking_assert (compatible_p (other));\n   if (!initialized_p () || !other.initialized_p ())\n     return false;\n   if ((uint64_t)m_val - (uint64_t)other.m_val < 100\n@@ -213,3 +218,40 @@ slow_safe_scale_64bit (uint64_t a, uint6\n   *res = (uint64_t) -1;\n   return false;\n }\n+\n+/* Return count as frequency within FUN scaled in range 0 to REG_FREQ_MAX\n+   Used for legacy code and should not be used anymore.  */\n+\n+int\n+profile_count::to_frequency (struct function *fun) const\n+{\n+  if (!initialized_p ())\n+    return BB_FREQ_MAX;\n+  if (*this == profile_count::zero ())\n+    return 0;\n+  gcc_assert (REG_BR_PROB_BASE == BB_FREQ_MAX\n+\t      && fun->cfg->count_max.initialized_p ());\n+  profile_probability prob = probability_in (fun->cfg->count_max);\n+  if (!prob.initialized_p ())\n+    return REG_BR_PROB_BASE;\n+  return prob.to_reg_br_prob_base ();\n+}\n+\n+/* Return count as frequency within FUN scaled in range 0 to CGRAPH_FREQ_MAX\n+   where CGRAPH_FREQ_BASE means that count equals to entry block count.\n+   Used for legacy code and should not be used anymore.  */\n+\n+int\n+profile_count::to_cgraph_frequency (profile_count entry_bb_count) const\n+{\n+  if (!initialized_p ())\n+    return CGRAPH_FREQ_BASE;\n+  if (*this == profile_count::zero ())\n+    return 0;\n+  gcc_checking_assert (entry_bb_count.initialized_p ());\n+  uint64_t scale;\n+  if (!safe_scale_64bit (!entry_bb_count.m_val ? m_val + 1 : m_val,\n+\t\t\t CGRAPH_FREQ_BASE, MAX (1, entry_bb_count.m_val), &scale))\n+    return CGRAPH_FREQ_MAX;\n+  return MIN (scale, CGRAPH_FREQ_MAX);\n+}\nIndex: profile-count.h\n===================================================================\n--- profile-count.h\t(revision 254348)\n+++ profile-count.h\t(working copy)\n@@ -21,21 +21,37 @@ along with GCC; see the file COPYING3.\n #ifndef GCC_PROFILE_COUNT_H\n #define GCC_PROFILE_COUNT_H\n \n+struct function;\n+\n /* Quality of the profile count.  Because gengtype does not support enums\n    inside of classes, this is in global namespace.  */\n enum profile_quality {\n+  /* Profile is based on static branch prediction heuristics and may\n+     or may not match reality.  It is local to function and can not be compared\n+     inter-procedurally.  Never used by probabilities (they are always local).\n+   */\n+  profile_guessed_local = 0,\n+  /* Profile was read by feedback and was 0, we used local heuristics to guess\n+     better.  This is the case of functions not run in profile fedback.\n+     Never used by probabilities.  */\n+  profile_guessed_global0 = 1,\n+\n+\n   /* Profile is based on static branch prediction heuristics.  It may or may\n-     not reflect the reality.  */\n-  profile_guessed = 0,\n+     not reflect the reality but it can be compared interprocedurally\n+     (for example, we inlined function w/o profile feedback into function\n+      with feedback and propagated from that).\n+     Never used by probablities.  */\n+  profile_guessed = 2,\n   /* Profile was determined by autofdo.  */\n-  profile_afdo = 1,\n+  profile_afdo = 3,\n   /* Profile was originally based on feedback but it was adjusted\n      by code duplicating optimization.  It may not precisely reflect the\n      particular code path.  */\n-  profile_adjusted = 2,\n+  profile_adjusted = 4,\n   /* Profile was read from profile feedback or determined by accurate static\n      method.  */\n-  profile_precise = 3\n+  profile_precise = 5\n };\n \n /* The base value for branch probability notes and edge probabilities.  */\n@@ -114,15 +130,15 @@ safe_scale_64bit (uint64_t a, uint64_t b\n \n class GTY((user)) profile_probability\n {\n-  static const int n_bits = 30;\n+  static const int n_bits = 29;\n   /* We can technically use ((uint32_t) 1 << (n_bits - 1)) - 2 but that\n      will lead to harder multiplication sequences.  */\n   static const uint32_t max_probability = (uint32_t) 1 << (n_bits - 2);\n   static const uint32_t uninitialized_probability\n \t\t = ((uint32_t) 1 << (n_bits - 1)) - 1;\n \n-  uint32_t m_val : 30;\n-  enum profile_quality m_quality : 2;\n+  uint32_t m_val : 29;\n+  enum profile_quality m_quality : 3;\n \n   friend class profile_count;\n public:\n@@ -226,14 +242,14 @@ public:\n   static profile_probability from_reg_br_prob_note (int v)\n     {\n       profile_probability ret;\n-      ret.m_val = ((unsigned int)v) / 4;\n-      ret.m_quality = (enum profile_quality)(v & 3);\n+      ret.m_val = ((unsigned int)v) / 8;\n+      ret.m_quality = (enum profile_quality)(v & 7);\n       return ret;\n     }\n   int to_reg_br_prob_note () const\n     {\n       gcc_checking_assert (initialized_p ());\n-      int ret = m_val * 4 + m_quality;\n+      int ret = m_val * 8 + m_quality;\n       gcc_checking_assert (profile_probability::from_reg_br_prob_note (ret)\n \t\t\t   == *this);\n       return ret;\n@@ -489,8 +505,9 @@ public:\n     {\n       if (m_val == uninitialized_probability)\n \treturn m_quality == profile_guessed;\n-      else\n-\treturn m_val <= max_probability;\n+      else if (m_quality < profile_guessed)\n+\treturn false;\n+      return m_val <= max_probability;\n     }\n \n   /* Comparsions are three-state and conservative.  False is returned if\n@@ -530,9 +547,32 @@ public:\n   void stream_out (struct lto_output_stream *);\n };\n \n-/* Main data type to hold profile counters in GCC.  In most cases profile\n-   counts originate from profile feedback. They are 64bit integers\n-   representing number of executions during the train run.\n+/* Main data type to hold profile counters in GCC. Profile counts originate\n+   either from profile feedback, static profile estimation or both.  We do not\n+   perform whole program profile propagation and thus profile estimation\n+   counters are often local to function, while counters from profile feedback\n+   (or special cases of profile estimation) can be used inter-procedurally.\n+\n+   There are 3 basic types\n+     1) local counters which are result of intra-procedural static profile\n+        estimation.\n+     2) ipa counters which are result of profile feedback or special case\n+        of static profile estimation (such as in function main).\n+     3) counters which counts as 0 inter-procedurally (beause given function\n+        was never run in train feedback) but they hold local static profile\n+        estimate.\n+\n+   Counters of type 1 and 3 can not be mixed with counters of different type\n+   within operation (because whole function should use one type of counter)\n+   with exception that global zero mix in most operations where outcome is\n+   well defined.\n+\n+   To take local counter and use it inter-procedurally use ipa member function\n+   which strips information irelevant at the inter-procedural level.\n+\n+   Counters are 61bit integers representing number of executions during the\n+   train run or normalized frequency within the function.\n+\n    As the profile is maintained during the compilation, many adjustments are\n    made.  Not all transformations can be made precisely, most importantly\n    when code is being duplicated.  It also may happen that part of CFG has\n@@ -567,12 +607,25 @@ class GTY(()) profile_count\n      64bit.  Although a counter cannot be negative, we use a signed\n      type to hold various extra stages.  */\n \n-  static const int n_bits = 62;\n+  static const int n_bits = 61;\n   static const uint64_t max_count = ((uint64_t) 1 << n_bits) - 2;\n   static const uint64_t uninitialized_count = ((uint64_t) 1 << n_bits) - 1;\n \n   uint64_t m_val : n_bits;\n-  enum profile_quality m_quality : 2;\n+  enum profile_quality m_quality : 3;\n+\n+  /* Return true if both values can meaningfully appear in single function\n+     body.  We have either all counters in function local or global, otherwise\n+     operations between them are not really defined well.  */\n+  bool compatible_p (const profile_count other) const\n+    {\n+      if (!initialized_p () || !other.initialized_p ())\n+\treturn true;\n+      if (*this == profile_count::zero ()\n+\t  || other == profile_count::zero ())\n+\treturn true;\n+      return ipa_p () == other.ipa_p ();\n+    }\n public:\n \n   /* Used for counters which are expected to be never executed.  */\n@@ -597,7 +650,7 @@ public:\n     {\n       profile_count c;\n       c.m_val = uninitialized_count;\n-      c.m_quality = profile_guessed;\n+      c.m_quality = profile_guessed_local;\n       return c;\n     }\n \n@@ -630,6 +683,11 @@ public:\n     {\n       return m_quality >= profile_adjusted;\n     }\n+  /* Return true if vlaue can be operated inter-procedurally.  */\n+  bool ipa_p () const\n+    {\n+      return !initialized_p () || m_quality >= profile_guessed_global0;\n+    }\n \n   /* When merging basic blocks, the two different profile counts are unified.\n      Return true if this can be done without losing info about profile.\n@@ -671,6 +729,7 @@ public:\n \treturn profile_count::uninitialized ();\n \n       profile_count ret;\n+      gcc_checking_assert (compatible_p (other));\n       ret.m_val = m_val + other.m_val;\n       ret.m_quality = MIN (m_quality, other.m_quality);\n       return ret;\n@@ -688,6 +747,7 @@ public:\n \treturn *this = profile_count::uninitialized ();\n       else\n \t{\n+          gcc_checking_assert (compatible_p (other));\n \t  m_val += other.m_val;\n \t  m_quality = MIN (m_quality, other.m_quality);\n \t}\n@@ -699,6 +759,7 @@ public:\n \treturn *this;\n       if (!initialized_p () || !other.initialized_p ())\n \treturn profile_count::uninitialized ();\n+      gcc_checking_assert (compatible_p (other));\n       profile_count ret;\n       ret.m_val = m_val >= other.m_val ? m_val - other.m_val : 0;\n       ret.m_quality = MIN (m_quality, other.m_quality);\n@@ -712,6 +773,7 @@ public:\n \treturn *this = profile_count::uninitialized ();\n       else\n \t{\n+          gcc_checking_assert (compatible_p (other));\n \t  m_val = m_val >= other.m_val ? m_val - other.m_val: 0;\n \t  m_quality = MIN (m_quality, other.m_quality);\n \t}\n@@ -721,48 +783,115 @@ public:\n   /* Return false if profile_count is bogus.  */\n   bool verify () const\n     {\n-      return m_val != uninitialized_count || m_quality == profile_guessed;\n+      return m_val != uninitialized_count || m_quality == profile_guessed_local;\n     }\n \n   /* Comparsions are three-state and conservative.  False is returned if\n      the inequality can not be decided.  */\n   bool operator< (const profile_count &other) const\n     {\n-      return initialized_p () && other.initialized_p () && m_val < other.m_val;\n+      if (!initialized_p () || !other.initialized_p ())\n+\treturn false;\n+      if (*this == profile_count::zero ())\n+\treturn !(other == profile_count::zero ());\n+      if (other == profile_count::zero ())\n+\treturn false;\n+      gcc_checking_assert (compatible_p (other));\n+      return m_val < other.m_val;\n     }\n   bool operator> (const profile_count &other) const\n     {\n+      if (!initialized_p () || !other.initialized_p ())\n+\treturn false;\n+      if (*this  == profile_count::zero ())\n+\treturn false;\n+      if (other == profile_count::zero ())\n+\treturn !(*this == profile_count::zero ());\n+      gcc_checking_assert (compatible_p (other));\n       return initialized_p () && other.initialized_p () && m_val > other.m_val;\n     }\n   bool operator< (const gcov_type other) const\n     {\n+      gcc_checking_assert (ipa_p ());\n       gcc_checking_assert (other >= 0);\n       return initialized_p () && m_val < (uint64_t) other;\n     }\n   bool operator> (const gcov_type other) const\n     {\n+      gcc_checking_assert (ipa_p ());\n       gcc_checking_assert (other >= 0);\n       return initialized_p () && m_val > (uint64_t) other;\n     }\n \n   bool operator<= (const profile_count &other) const\n     {\n-      return initialized_p () && other.initialized_p () && m_val <= other.m_val;\n+      if (!initialized_p () || !other.initialized_p ())\n+\treturn false;\n+      if (*this == profile_count::zero ())\n+\treturn true;\n+      if (other == profile_count::zero ())\n+\treturn (*this == profile_count::zero ());\n+      gcc_checking_assert (compatible_p (other));\n+      return m_val <= other.m_val;\n     }\n   bool operator>= (const profile_count &other) const\n     {\n-      return initialized_p () && other.initialized_p () && m_val >= other.m_val;\n+      if (!initialized_p () || !other.initialized_p ())\n+\treturn false;\n+      if (other == profile_count::zero ())\n+\treturn true;\n+      if (*this == profile_count::zero ())\n+\treturn !(other == profile_count::zero ());\n+      gcc_checking_assert (compatible_p (other));\n+      return m_val >= other.m_val;\n     }\n   bool operator<= (const gcov_type other) const\n     {\n+      gcc_checking_assert (ipa_p ());\n       gcc_checking_assert (other >= 0);\n       return initialized_p () && m_val <= (uint64_t) other;\n     }\n   bool operator>= (const gcov_type other) const\n     {\n+      gcc_checking_assert (ipa_p ());\n       gcc_checking_assert (other >= 0);\n       return initialized_p () && m_val >= (uint64_t) other;\n     }\n+  /* Return true when value is not zero and can be used for scaling. \n+     This is different from *this > 0 because that requires counter to\n+     be IPA.  */\n+  bool nonzero_p () const\n+    {\n+      return initialized_p () && m_val != 0;\n+    }\n+\n+  /* Make counter forcingly nonzero.  */\n+  profile_count force_nonzero () const\n+    {\n+      if (!initialized_p ())\n+\treturn *this;\n+      profile_count ret = *this;\n+      if (ret.m_val == 0)\n+\tret.m_val = 1;\n+      return ret;\n+    }\n+\n+  profile_count max (profile_count other) const\n+    {\n+      if (!initialized_p ())\n+\treturn other;\n+      if (!other.initialized_p ())\n+\treturn *this;\n+      if (*this == profile_count::zero ())\n+\treturn other;\n+      if (other == profile_count::zero ())\n+\treturn *this;\n+      gcc_checking_assert (compatible_p (other));\n+      if (m_val < other.m_val || (m_val == other.m_val\n+\t\t\t\t  && m_quality < other.m_quality))\n+\treturn other;\n+      return *this;\n+    }\n \n   /* PROB is a probability in scale 0...REG_BR_PROB_BASE.  Scale counter\n      accordingly.  */\n@@ -814,13 +943,13 @@ public:\n     }\n   profile_count apply_scale (profile_count num, profile_count den) const\n     {\n-      if (m_val == 0)\n+      if (*this == profile_count::zero ())\n \treturn *this;\n-      if (num.m_val == 0)\n+      if (num == profile_count::zero ())\n \treturn num;\n       if (!initialized_p () || !num.initialized_p () || !den.initialized_p ())\n \treturn profile_count::uninitialized ();\n-      gcc_checking_assert (den > 0);\n+      gcc_checking_assert (den.m_val);\n       if (num == den)\n \treturn *this;\n \n@@ -828,7 +957,30 @@ public:\n       uint64_t val;\n       safe_scale_64bit (m_val, num.m_val, den.m_val, &val);\n       ret.m_val = MIN (val, max_count);\n-      ret.m_quality = MIN (m_quality, profile_adjusted);\n+      ret.m_quality = MIN (MIN (MIN (m_quality, profile_adjusted),\n+\t\t\t        num.m_quality), den.m_quality);\n+      if (num.ipa_p () && !ret.ipa_p ())\n+\tret.m_quality = MIN (num.m_quality, profile_guessed);\n+      return ret;\n+    }\n+\n+  /* Return THIS with quality dropped to GUESSED_LOCAL.  */\n+  profile_count guessed_local () const\n+    {\n+      profile_count ret = *this;\n+      if (!initialized_p ())\n+\treturn *this;\n+      ret.m_quality = profile_guessed_local;\n+      return ret;\n+    }\n+\n+  /* We know that profile is globally0 but keep local profile if present.  */\n+  profile_count global0 () const\n+    {\n+      profile_count ret = *this;\n+      if (!initialized_p ())\n+\treturn *this;\n+      ret.m_quality = profile_guessed_global0;\n       return ret;\n     }\n \n@@ -836,10 +988,21 @@ public:\n   profile_count guessed () const\n     {\n       profile_count ret = *this;\n-      ret.m_quality = profile_guessed;\n+      ret.m_quality = MIN (ret.m_quality, profile_guessed);\n       return ret;\n     }\n \n+  /* Return variant of profile counte which is always safe to compare\n+     acorss functions.  */\n+  profile_count ipa () const\n+    {\n+      if (m_quality > profile_guessed_global0)\n+\treturn *this;\n+      if (m_quality == profile_guessed_global0)\n+\treturn profile_count::zero ();\n+      return profile_count::uninitialized ();\n+    }\n+\n   /* Return THIS with quality dropped to AFDO.  */\n   profile_count afdo () const\n     {\n@@ -852,21 +1015,26 @@ public:\n      OVERALL.  */\n   profile_probability probability_in (const profile_count overall) const\n     {\n-      if (!m_val)\n+      if (*this == profile_count::zero ())\n \treturn profile_probability::never ();\n       if (!initialized_p () || !overall.initialized_p ()\n \t  || !overall.m_val)\n \treturn profile_probability::uninitialized ();\n       profile_probability ret;\n-      if (overall < m_val)\n+      gcc_checking_assert (compatible_p (overall));\n+\n+      if (overall.m_val < m_val)\n \tret.m_val = profile_probability::max_probability;\n       else\n \tret.m_val = RDIV (m_val * profile_probability::max_probability,\n \t\t\t  overall.m_val);\n-      ret.m_quality = MIN (m_quality, overall.m_quality);\n+      ret.m_quality = MAX (MIN (m_quality, overall.m_quality), profile_guessed);\n       return ret;\n     }\n \n+  int to_frequency (struct function *fun) const;\n+  int to_cgraph_frequency (profile_count entry_bb_count) const;\n+\n   /* Output THIS to F.  */\n   void dump (FILE *f) const;\n \nIndex: profile.c\n===================================================================\n--- profile.c\t(revision 254348)\n+++ profile.c\t(working copy)\n@@ -476,38 +476,6 @@ read_profile_edge_counts (gcov_type *exe\n     return num_edges;\n }\n \n-#define OVERLAP_BASE 10000\n-\n-/* Compare the static estimated profile to the actual profile, and\n-   return the \"degree of overlap\" measure between them.\n-\n-   Degree of overlap is a number between 0 and OVERLAP_BASE. It is\n-   the sum of each basic block's minimum relative weights between\n-   two profiles. And overlap of OVERLAP_BASE means two profiles are\n-   identical.  */\n-\n-static int\n-compute_frequency_overlap (void)\n-{\n-  gcov_type count_total = 0, freq_total = 0;\n-  int overlap = 0;\n-  basic_block bb;\n-\n-  FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (cfun), NULL, next_bb)\n-    {\n-      count_total += bb_gcov_count (bb);\n-      freq_total += bb->frequency;\n-    }\n-\n-  if (count_total == 0 || freq_total == 0)\n-    return 0;\n-\n-  FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (cfun), NULL, next_bb)\n-    overlap += MIN (bb_gcov_count (bb) * OVERLAP_BASE / count_total,\n-\t\t    bb->frequency * OVERLAP_BASE / freq_total);\n-\n-  return overlap;\n-}\n \n /* Compute the branch probabilities for the various branches.\n    Annotate them accordingly.  \n@@ -676,14 +644,6 @@ compute_branch_probabilities (unsigned c\n \t    }\n \t}\n     }\n-  if (dump_file)\n-    {\n-      int overlap = compute_frequency_overlap ();\n-      gimple_dump_cfg (dump_file, dump_flags);\n-      fprintf (dump_file, \"Static profile overlap: %d.%d%%\\n\",\n-\t       overlap / (OVERLAP_BASE / 100),\n-\t       overlap % (OVERLAP_BASE / 100));\n-    }\n \n   total_num_passes += passes;\n   if (dump_file)\n@@ -829,10 +789,18 @@ compute_branch_probabilities (unsigned c\n \t}\n     }\n \n-  FOR_ALL_BB_FN (bb, cfun)\n-    {\n+  /* If we have real data, use them!  */\n+  if (bb_gcov_count (ENTRY_BLOCK_PTR_FOR_FN (cfun))\n+      || !flag_guess_branch_prob)\n+    FOR_ALL_BB_FN (bb, cfun)\n       bb->count = profile_count::from_gcov_type (bb_gcov_count (bb));\n-    }\n+  /* If function was not trained, preserve local estimates including statically\n+     determined zero counts.  */\n+  else\n+    FOR_ALL_BB_FN (bb, cfun)\n+      if (!(bb->count == profile_count::zero ()))\n+        bb->count = bb->count.global0 ();\n+\n   bb_gcov_counts.release ();\n   delete edge_gcov_counts;\n   edge_gcov_counts = NULL;\nIndex: regs.h\n===================================================================\n--- regs.h\t(revision 254348)\n+++ regs.h\t(working copy)\n@@ -130,8 +130,10 @@ extern size_t reg_info_p_size;\n    frequency.  */\n #define REG_FREQ_FROM_BB(bb) (optimize_function_for_size_p (cfun)\t      \\\n \t\t\t      ? REG_FREQ_MAX\t\t\t\t      \\\n-\t\t\t      : ((bb)->frequency * REG_FREQ_MAX / BB_FREQ_MAX)\\\n-\t\t\t      ? ((bb)->frequency * REG_FREQ_MAX / BB_FREQ_MAX)\\\n+\t\t\t      : ((bb)->count.to_frequency (cfun)\t      \\\n+\t\t\t\t* REG_FREQ_MAX / BB_FREQ_MAX)\t\t      \\\n+\t\t\t      ? ((bb)->count.to_frequency (cfun)\t      \\\n+\t\t\t\t * REG_FREQ_MAX / BB_FREQ_MAX)\t\t      \\\n \t\t\t      : 1)\n \n /* Indexed by N, gives number of insns in which register N dies.\nIndex: sched-ebb.c\n===================================================================\n--- sched-ebb.c\t(revision 254348)\n+++ sched-ebb.c\t(working copy)\n@@ -231,11 +231,9 @@ rank (rtx_insn *insn1, rtx_insn *insn2)\n   basic_block bb1 = BLOCK_FOR_INSN (insn1);\n   basic_block bb2 = BLOCK_FOR_INSN (insn2);\n \n-  if (bb1->count > bb2->count\n-      || bb1->frequency > bb2->frequency)\n+  if (bb1->count > bb2->count)\n     return -1;\n-  if (bb1->count < bb2->count\n-      || bb1->frequency < bb2->frequency)\n+  if (bb1->count < bb2->count)\n     return 1;\n   return 0;\n }\nIndex: shrink-wrap.c\n===================================================================\n--- shrink-wrap.c\t(revision 254348)\n+++ shrink-wrap.c\t(working copy)\n@@ -561,7 +561,7 @@ handle_simple_exit (edge e)\n       BB_END (old_bb) = end;\n \n       redirect_edge_succ (e, new_bb);\n-      new_bb->frequency = EDGE_FREQUENCY (e);\n+      new_bb->count = e->count ();\n       e->flags |= EDGE_FALLTHRU;\n \n       e = make_single_succ_edge (new_bb, EXIT_BLOCK_PTR_FOR_FN (cfun), 0);\n@@ -887,7 +887,7 @@ try_shrink_wrapping (edge *entry_edge, r\n     if (!dominated_by_p (CDI_DOMINATORS, e->src, pro))\n       {\n \tnum += EDGE_FREQUENCY (e);\n-\tden += e->src->frequency;\n+\tden += e->src->count.to_frequency (cfun);\n       }\n \n   if (den == 0)\n@@ -920,8 +920,6 @@ try_shrink_wrapping (edge *entry_edge, r\n \tif (dump_file)\n \t  fprintf (dump_file, \"Duplicated %d to %d\\n\", bb->index, dup->index);\n \n-\tbb->frequency = RDIV (num * bb->frequency, den);\n-\tdup->frequency -= bb->frequency;\n \tbb->count = bb->count.apply_scale (num, den);\n \tdup->count -= bb->count;\n       }\n@@ -995,8 +993,7 @@ try_shrink_wrapping (edge *entry_edge, r\n \t  continue;\n \t}\n \n-      new_bb->count += e->src->count.apply_probability (e->probability);\n-      new_bb->frequency += EDGE_FREQUENCY (e);\n+      new_bb->count += e->count ();\n \n       redirect_edge_and_branch_force (e, new_bb);\n       if (dump_file)\n@@ -1181,7 +1178,7 @@ place_prologue_for_one_component (unsign\n \t     work: this does not always add up to the block frequency at\n \t     all, and even if it does, rounding error makes for bad\n \t     decisions.  */\n-\t  SW (bb)->own_cost = bb->frequency;\n+\t  SW (bb)->own_cost = bb->count.to_frequency (cfun);\n \n \t  edge e;\n \t  edge_iterator ei;\nIndex: testsuite/gcc.dg/no-strict-overflow-3.c\n===================================================================\n--- testsuite/gcc.dg/no-strict-overflow-3.c\t(revision 254348)\n+++ testsuite/gcc.dg/no-strict-overflow-3.c\t(working copy)\n@@ -9,7 +9,7 @@\n int\n foo (int i, int j)\n {\n-  return i + 100 < j + 1000;\n+  return i + 100 < j + 1234;\n }\n \n-/* { dg-final { scan-tree-dump \"1000\" \"optimized\" } } */\n+/* { dg-final { scan-tree-dump \"1234\" \"optimized\" } } */\nIndex: testsuite/gcc.dg/strict-overflow-3.c\n===================================================================\n--- testsuite/gcc.dg/strict-overflow-3.c\t(revision 254348)\n+++ testsuite/gcc.dg/strict-overflow-3.c\t(working copy)\n@@ -9,7 +9,7 @@\n int\n foo (int i, int j)\n {\n-  return i + 100 < j + 1000;\n+  return i + 100 < j + 1234;\n }\n \n-/* { dg-final { scan-tree-dump-not \"1000\" \"optimized\" } } */\n+/* { dg-final { scan-tree-dump-not \"1234\" \"optimized\" } } */\nIndex: testsuite/gcc.dg/tree-ssa/builtin-sprintf-2.c\n===================================================================\n--- testsuite/gcc.dg/tree-ssa/builtin-sprintf-2.c\t(revision 254348)\n+++ testsuite/gcc.dg/tree-ssa/builtin-sprintf-2.c\t(working copy)\n@@ -290,7 +290,7 @@ RNG (0,  6,   8, \"%s%ls\", \"1\", L\"2\");\n \n /*  Only conditional calls to must_not_eliminate must be made (with\n     any probability):\n-    { dg-final { scan-tree-dump-times \"> \\\\\\[\\[0-9.\\]+%\\\\\\] \\\\\\[count: \\[0-9INV\\]*\\\\\\]:\\n *must_not_eliminate\" 127 \"optimized\" { target { ilp32 || lp64 } } } }\n-    { dg-final { scan-tree-dump-times \"> \\\\\\[\\[0-9.\\]+%\\\\\\] \\\\\\[count: \\[0-9INV\\]*\\\\\\]:\\n *must_not_eliminate\" 96 \"optimized\" { target { { ! ilp32 } && { ! lp64 } } } } }\n+    { dg-final { scan-tree-dump-times \"> \\\\\\[local count: \\[0-9INV\\]*\\\\\\]:\\n *must_not_eliminate\" 127 \"optimized\" { target { ilp32 || lp64 } } } }\n+    { dg-final { scan-tree-dump-times \"> \\\\\\[local count: \\[0-9INV\\]*\\\\\\]:\\n *must_not_eliminate\" 96 \"optimized\" { target { { ! ilp32 } && { ! lp64 } } } } }\n     No unconditional calls to abort should be made:\n     { dg-final { scan-tree-dump-not \";\\n *must_not_eliminate\" \"optimized\" } } */\nIndex: testsuite/gcc.dg/tree-ssa/dump-2.c\n===================================================================\n--- testsuite/gcc.dg/tree-ssa/dump-2.c\t(revision 254348)\n+++ testsuite/gcc.dg/tree-ssa/dump-2.c\t(working copy)\n@@ -6,4 +6,4 @@ int f(void)\n   return 0;\n }\n \n-/* { dg-final { scan-tree-dump \"<bb \\[0-9\\]> \\\\\\[100\\\\\\.00%\\\\\\] \\\\\\[count: INV\\\\\\]:\" \"optimized\" } } */\n+/* { dg-final { scan-tree-dump \"<bb \\[0-9\\]> \\\\\\[local count: 10000\\\\\\]:\" \"optimized\" } } */\nIndex: testsuite/gcc.dg/tree-ssa/ifc-10.c\n===================================================================\n--- testsuite/gcc.dg/tree-ssa/ifc-10.c\t(revision 254348)\n+++ testsuite/gcc.dg/tree-ssa/ifc-10.c\t(working copy)\n@@ -26,5 +26,5 @@ int foo (int x, int n)\n    which is folded by vectorizer.  Both outgoing edges must have probability\n    100% so the resulting profile match after folding.  */\n /* { dg-final { scan-tree-dump-times \"Invalid sum of outgoing probabilities 200.0\" 1 \"ifcvt\" } } */\n-/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming frequencies\" 1 \"ifcvt\" } } */\n+/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming counts\" 1 \"ifcvt\" } } */\n \nIndex: testsuite/gcc.dg/tree-ssa/ifc-11.c\n===================================================================\n--- testsuite/gcc.dg/tree-ssa/ifc-11.c\t(revision 254348)\n+++ testsuite/gcc.dg/tree-ssa/ifc-11.c\t(working copy)\n@@ -24,5 +24,4 @@ int foo (float *x)\n    which is folded by vectorizer.  Both outgoing edges must have probability\n    100% so the resulting profile match after folding.  */\n /* { dg-final { scan-tree-dump-times \"Invalid sum of outgoing probabilities 200.0\" 1 \"ifcvt\" } } */\n-/* Sum is wrong here, but not enough for error to be reported.  */\n-/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming frequencies\" 0 \"ifcvt\" } } */\n+/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming counts\" 1 \"ifcvt\" } } */\nIndex: testsuite/gcc.dg/tree-ssa/ifc-12.c\n===================================================================\n--- testsuite/gcc.dg/tree-ssa/ifc-12.c\t(revision 254348)\n+++ testsuite/gcc.dg/tree-ssa/ifc-12.c\t(working copy)\n@@ -29,6 +29,5 @@ int foo (int x)\n    which is folded by vectorizer.  Both outgoing edges must have probability\n    100% so the resulting profile match after folding.  */\n /* { dg-final { scan-tree-dump-times \"Invalid sum of outgoing probabilities 200.0\" 1 \"ifcvt\" } } */\n-/* Sum is wrong here, but not enough for error to be reported.  */\n-/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming frequencies\" 0 \"ifcvt\" } } */\n+/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming counts\" 1 \"ifcvt\" } } */\n \nIndex: testsuite/gcc.dg/tree-ssa/ifc-20040816-1.c\n===================================================================\n--- testsuite/gcc.dg/tree-ssa/ifc-20040816-1.c\t(revision 254348)\n+++ testsuite/gcc.dg/tree-ssa/ifc-20040816-1.c\t(working copy)\n@@ -39,4 +39,4 @@ int main1 ()\n    which is folded by vectorizer.  Both outgoing edges must have probability\n    100% so the resulting profile match after folding.  */\n /* { dg-final { scan-tree-dump-times \"Invalid sum of outgoing probabilities 200.0\" 1 \"ifcvt\" } } */\n-/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming frequencies\" 1 \"ifcvt\" } } */\n+/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming counts\" 1 \"ifcvt\" } } */\nIndex: testsuite/gcc.dg/tree-ssa/ifc-20040816-2.c\n===================================================================\n--- testsuite/gcc.dg/tree-ssa/ifc-20040816-2.c\t(revision 254348)\n+++ testsuite/gcc.dg/tree-ssa/ifc-20040816-2.c\t(working copy)\n@@ -43,5 +43,4 @@ void foo(const int * __restrict__ zr_in,\n    which is folded by vectorizer.  Both outgoing edges must have probability\n    100% so the resulting profile match after folding.  */\n /* { dg-final { scan-tree-dump-times \"Invalid sum of outgoing probabilities 200.0\" 1 \"ifcvt\" } } */\n-/* Sum is wrong here, but not enough for error to be reported.  */\n-/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming frequencies\" 0 \"ifcvt\" } } */\n+/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming counts\" 1 \"ifcvt\" } } */\nIndex: testsuite/gcc.dg/tree-ssa/ifc-5.c\n===================================================================\n--- testsuite/gcc.dg/tree-ssa/ifc-5.c\t(revision 254348)\n+++ testsuite/gcc.dg/tree-ssa/ifc-5.c\t(working copy)\n@@ -27,4 +27,4 @@ dct_unquantize_h263_inter_c (short *bloc\n    which is folded by vectorizer.  Both outgoing edges must have probability\n    100% so the resulting profile match after folding.  */\n /* { dg-final { scan-tree-dump-times \"Invalid sum of outgoing probabilities 200.0\" 1 \"ifcvt\" } } */\n-/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming frequencies\" 1 \"ifcvt\" } } */\n+/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming counts\" 1 \"ifcvt\" } } */\nIndex: testsuite/gcc.dg/tree-ssa/ifc-8.c\n===================================================================\n--- testsuite/gcc.dg/tree-ssa/ifc-8.c\t(revision 254348)\n+++ testsuite/gcc.dg/tree-ssa/ifc-8.c\t(working copy)\n@@ -22,5 +22,4 @@ void test ()\n    which is folded by vectorizer.  Both outgoing edges must have probability\n    100% so the resulting profile match after folding.  */\n /* { dg-final { scan-tree-dump-times \"Invalid sum of outgoing probabilities 200.0\" 1 \"ifcvt\" } } */\n-/* Sum is wrong here, but not enough for error to be reported.  */\n-/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming frequencies\" 0 \"ifcvt\" } } */\n+/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming counts\" 1 \"ifcvt\" } } */\nIndex: testsuite/gcc.dg/tree-ssa/ifc-9.c\n===================================================================\n--- testsuite/gcc.dg/tree-ssa/ifc-9.c\t(revision 254348)\n+++ testsuite/gcc.dg/tree-ssa/ifc-9.c\t(working copy)\n@@ -26,4 +26,4 @@ int foo (int x, int n)\n    which is folded by vectorizer.  Both outgoing edges must have probability\n    100% so the resulting profile match after folding.  */\n /* { dg-final { scan-tree-dump-times \"Invalid sum of outgoing probabilities 200.0\" 1 \"ifcvt\" } } */\n-/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming frequencies\" 1 \"ifcvt\" } } */\n+/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming counts\" 1 \"ifcvt\" } } */\nIndex: testsuite/gcc.dg/tree-ssa/ifc-cd.c\n===================================================================\n--- testsuite/gcc.dg/tree-ssa/ifc-cd.c\t(revision 254348)\n+++ testsuite/gcc.dg/tree-ssa/ifc-cd.c\t(working copy)\n@@ -32,5 +32,4 @@ void foo (int *x1, int *x2, int *x3, int\n    which is folded by vectorizer.  Both outgoing edges must have probability\n    100% so the resulting profile match after folding.  */\n /* { dg-final { scan-tree-dump-times \"Invalid sum of outgoing probabilities 200.0\" 1 \"ifcvt\" } } */\n-/* Sum is wrong here, but not enough for error to be reported.  */\n-/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming frequencies\" 0 \"ifcvt\" } } */\n+/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming counts\" 1 \"ifcvt\" } } */\nIndex: testsuite/gcc.dg/tree-ssa/ifc-pr56541.c\n===================================================================\n--- testsuite/gcc.dg/tree-ssa/ifc-pr56541.c\t(revision 254348)\n+++ testsuite/gcc.dg/tree-ssa/ifc-pr56541.c\t(working copy)\n@@ -29,5 +29,4 @@ void foo()\n    which is folded by vectorizer.  Both outgoing edges must have probability\n    100% so the resulting profile match after folding.  */\n /* { dg-final { scan-tree-dump-times \"Invalid sum of outgoing probabilities 200.0\" 1 \"ifcvt\" } } */\n-/* Sum is wrong here, but not enough for error to be reported.  */\n-/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming frequencies\" 0 \"ifcvt\" } } */\n+/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming counts\" 1 \"ifcvt\" } } */\nIndex: testsuite/gcc.dg/tree-ssa/ifc-pr68583.c\n===================================================================\n--- testsuite/gcc.dg/tree-ssa/ifc-pr68583.c\t(revision 254348)\n+++ testsuite/gcc.dg/tree-ssa/ifc-pr68583.c\t(working copy)\n@@ -26,5 +26,5 @@ void foo (long *a)\n    which is folded by vectorizer.  Both outgoing edges must have probability\n    100% so the resulting profile match after folding.  */\n /* { dg-final { scan-tree-dump-times \"Invalid sum of outgoing probabilities 200.0\" 1 \"ifcvt\" } } */\n-/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming frequencies\" 1 \"ifcvt\" } } */\n+/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming counts\" 1 \"ifcvt\" } } */\n \nIndex: testsuite/gcc.dg/tree-ssa/ifc-pr69489-1.c\n===================================================================\n--- testsuite/gcc.dg/tree-ssa/ifc-pr69489-1.c\t(revision 254348)\n+++ testsuite/gcc.dg/tree-ssa/ifc-pr69489-1.c\t(working copy)\n@@ -20,5 +20,4 @@ void foo (int a[], int b[])\n    which is folded by vectorizer.  Both outgoing edges must have probability\n    100% so the resulting profile match after folding.  */\n /* { dg-final { scan-tree-dump-times \"Invalid sum of outgoing probabilities 200.0\" 1 \"ifcvt\" } } */\n-/* Sum is wrong here, but not enough for error to be reported.  */\n-/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming frequencies\" 0 \"ifcvt\" } } */\n+/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming counts\" 1 \"ifcvt\" } } */\nIndex: testsuite/gcc.dg/tree-ssa/ifc-pr69489-2.c\n===================================================================\n--- testsuite/gcc.dg/tree-ssa/ifc-pr69489-2.c\t(revision 254348)\n+++ testsuite/gcc.dg/tree-ssa/ifc-pr69489-2.c\t(working copy)\n@@ -21,4 +21,4 @@ foo (const char *u, const char *v, long\n    which is folded by vectorizer.  Both outgoing edges must have probability\n    100% so the resulting profile match after folding.  */\n /* { dg-final { scan-tree-dump-times \"Invalid sum of outgoing probabilities 200.0\" 1 \"ifcvt\" } } */\n-/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming frequencies\" 1 \"ifcvt\" } } */\n+/* { dg-final { scan-tree-dump-times \"Invalid sum of incoming counts\" 1 \"ifcvt\" } } */\nIndex: testsuite/gcc.target/i386/pr61403.c\n===================================================================\n--- testsuite/gcc.target/i386/pr61403.c\t(revision 254348)\n+++ testsuite/gcc.target/i386/pr61403.c\t(working copy)\n@@ -23,4 +23,4 @@ norm (struct XYZ *in, struct XYZ *out, i\n     }\n }\n \n-/* { dg-final { scan-assembler \"blend\" } } */\n+/* { dg-final { scan-assembler \"rsqrtps\" } } */\nIndex: tracer.c\n===================================================================\n--- tracer.c\t(revision 254348)\n+++ tracer.c\t(working copy)\n@@ -179,7 +179,7 @@ find_best_predecessor (basic_block bb)\n   if (!best || ignore_bb_p (best->src))\n     return NULL;\n   if (EDGE_FREQUENCY (best) * REG_BR_PROB_BASE\n-      < bb->frequency * branch_ratio_cutoff)\n+      < bb->count.to_frequency (cfun) * branch_ratio_cutoff)\n     return NULL;\n   return best;\n }\n@@ -194,7 +194,7 @@ find_trace (basic_block bb, basic_block\n   edge e;\n \n   if (dump_file)\n-    fprintf (dump_file, \"Trace seed %i [%i]\", bb->index, bb->frequency);\n+    fprintf (dump_file, \"Trace seed %i [%i]\", bb->index, bb->count.to_frequency (cfun));\n \n   while ((e = find_best_predecessor (bb)) != NULL)\n     {\n@@ -203,11 +203,11 @@ find_trace (basic_block bb, basic_block\n \t  || find_best_successor (bb2) != e)\n \tbreak;\n       if (dump_file)\n-\tfprintf (dump_file, \",%i [%i]\", bb->index, bb->frequency);\n+\tfprintf (dump_file, \",%i [%i]\", bb->index, bb->count.to_frequency (cfun));\n       bb = bb2;\n     }\n   if (dump_file)\n-    fprintf (dump_file, \" forward %i [%i]\", bb->index, bb->frequency);\n+    fprintf (dump_file, \" forward %i [%i]\", bb->index, bb->count.to_frequency (cfun));\n   trace[i++] = bb;\n \n   /* Follow the trace in forward direction.  */\n@@ -218,7 +218,7 @@ find_trace (basic_block bb, basic_block\n \t  || find_best_predecessor (bb) != e)\n \tbreak;\n       if (dump_file)\n-\tfprintf (dump_file, \",%i [%i]\", bb->index, bb->frequency);\n+\tfprintf (dump_file, \",%i [%i]\", bb->index, bb->count.to_frequency (cfun));\n       trace[i++] = bb;\n     }\n   if (dump_file)\n@@ -282,11 +282,11 @@ tail_duplicate (void)\n     {\n       int n = count_insns (bb);\n       if (!ignore_bb_p (bb))\n-\tblocks[bb->index] = heap.insert (-bb->frequency, bb);\n+\tblocks[bb->index] = heap.insert (-bb->count.to_frequency (cfun), bb);\n \n       counts [bb->index] = n;\n       ninsns += n;\n-      weighted_insns += n * bb->frequency;\n+      weighted_insns += n * bb->count.to_frequency (cfun);\n     }\n \n   if (profile_info && profile_status_for_fn (cfun) == PROFILE_READ)\n@@ -314,7 +314,7 @@ tail_duplicate (void)\n       n = find_trace (bb, trace);\n \n       bb = trace[0];\n-      traced_insns += bb->frequency * counts [bb->index];\n+      traced_insns += bb->count.to_frequency (cfun) * counts [bb->index];\n       if (blocks[bb->index])\n \t{\n \t  heap.delete_node (blocks[bb->index]);\n@@ -330,7 +330,7 @@ tail_duplicate (void)\n \t      heap.delete_node (blocks[bb2->index]);\n \t      blocks[bb2->index] = NULL;\n \t    }\n-\t  traced_insns += bb2->frequency * counts [bb2->index];\n+\t  traced_insns += bb2->count.to_frequency (cfun) * counts [bb2->index];\n \t  if (EDGE_COUNT (bb2->preds) > 1\n \t      && can_duplicate_block_p (bb2)\n \t      /* We have the tendency to duplicate the loop header\n@@ -345,11 +345,11 @@ tail_duplicate (void)\n \t      /* Reconsider the original copy of block we've duplicated.\n \t         Removing the most common predecessor may make it to be\n \t         head.  */\n-\t      blocks[bb2->index] = heap.insert (-bb2->frequency, bb2);\n+\t      blocks[bb2->index] = heap.insert (-bb2->count.to_frequency (cfun), bb2);\n \n \t      if (dump_file)\n \t\tfprintf (dump_file, \"Duplicated %i as %i [%i]\\n\",\n-\t\t\t bb2->index, copy->index, copy->frequency);\n+\t\t\t bb2->index, copy->index, copy->count.to_frequency (cfun));\n \n \t      bb2 = copy;\n \t      changed = true;\nIndex: trans-mem.c\n===================================================================\n--- trans-mem.c\t(revision 254348)\n+++ trans-mem.c\t(working copy)\n@@ -2932,7 +2932,6 @@ expand_transaction (struct tm_region *re\n       edge ef = make_edge (test_bb, join_bb, EDGE_FALSE_VALUE);\n       redirect_edge_pred (fallthru_edge, join_bb);\n \n-      join_bb->frequency = test_bb->frequency = transaction_bb->frequency;\n       join_bb->count = test_bb->count = transaction_bb->count;\n \n       ei->probability = profile_probability::always ();\n@@ -2940,7 +2939,6 @@ expand_transaction (struct tm_region *re\n       ef->probability = profile_probability::unlikely ();\n \n       code_bb->count = et->count ();\n-      code_bb->frequency = EDGE_FREQUENCY (et);\n \n       transaction_bb = join_bb;\n     }\n@@ -2964,7 +2962,6 @@ expand_transaction (struct tm_region *re\n       gsi_insert_after (&gsi, stmt, GSI_CONTINUE_LINKING);\n \n       edge ei = make_edge (transaction_bb, test_bb, EDGE_FALLTHRU);\n-      test_bb->frequency = transaction_bb->frequency;\n       test_bb->count = transaction_bb->count;\n       ei->probability = profile_probability::always ();\n \n@@ -3006,7 +3003,6 @@ expand_transaction (struct tm_region *re\n       edge e = make_edge (transaction_bb, test_bb, fallthru_edge->flags);\n       e->probability = fallthru_edge->probability;\n       test_bb->count = fallthru_edge->count ();\n-      test_bb->frequency = EDGE_FREQUENCY (e);\n \n       // Now update the edges to the inst/uninist implementations.\n       // For now assume that the paths are equally likely.  When using HTM,\nIndex: tree-call-cdce.c\n===================================================================\n--- tree-call-cdce.c\t(revision 254348)\n+++ tree-call-cdce.c\t(working copy)\n@@ -906,7 +906,6 @@ shrink_wrap_one_built_in_call_with_conds\n      Here we take the second approach because it's slightly simpler\n      and because it's easy to see that it doesn't lose profile counts.  */\n   bi_call_bb->count = profile_count::zero ();\n-  bi_call_bb->frequency = 0;\n   while (!edges.is_empty ())\n     {\n       edge_pair e = edges.pop ();\n@@ -919,16 +918,10 @@ shrink_wrap_one_built_in_call_with_conds\n       nocall_edge->probability = profile_probability::always ()\n \t\t\t\t - call_edge->probability;\n \n-      unsigned int call_frequency\n-\t = call_edge->probability.apply (src_bb->frequency);\n-\n       bi_call_bb->count += call_edge->count ();\n-      bi_call_bb->frequency += call_frequency;\n \n       if (nocall_edge->dest != join_tgt_bb)\n-\t{\n-\t  nocall_edge->dest->frequency = src_bb->frequency - call_frequency;\n-\t}\n+\tnocall_edge->dest->count = src_bb->count - bi_call_bb->count;\n     }\n \n   if (dom_info_available_p (CDI_DOMINATORS))\nIndex: tree-cfg.c\n===================================================================\n--- tree-cfg.c\t(revision 254348)\n+++ tree-cfg.c\t(working copy)\n@@ -1071,7 +1071,6 @@ gimple_find_sub_bbs (gimple_seq seq, gim\n       tree_guess_outgoing_edge_probabilities (bb);\n       if (all || profile_status_for_fn (cfun) == PROFILE_READ)\n         bb->count = cnt;\n-      bb->frequency = freq;\n \n       bb = bb->next_bb;\n     }\n@@ -2081,7 +2080,6 @@ gimple_merge_blocks (basic_block a, basi\n   if (a->loop_father == b->loop_father)\n     {\n       a->count = a->count.merge (b->count);\n-      a->frequency = MAX (a->frequency, b->frequency);\n     }\n \n   /* Merge the sequences.  */\n@@ -2840,7 +2838,6 @@ gimple_split_edge (edge edge_in)\n   after_bb = split_edge_bb_loc (edge_in);\n \n   new_bb = create_empty_bb (after_bb);\n-  new_bb->frequency = EDGE_FREQUENCY (edge_in);\n   new_bb->count = edge_in->count ();\n \n   e = redirect_edge_and_branch (edge_in, new_bb);\n@@ -6306,9 +6303,8 @@ gimple_duplicate_sese_region (edge entry\n   bool free_region_copy = false, copying_header = false;\n   struct loop *loop = entry->dest->loop_father;\n   edge exit_copy;\n-  vec<basic_block> doms;\n+  vec<basic_block> doms = vNULL;\n   edge redirected;\n-  int total_freq = 0, entry_freq = 0;\n   profile_count total_count = profile_count::uninitialized ();\n   profile_count entry_count = profile_count::uninitialized ();\n \n@@ -6376,21 +6372,10 @@ gimple_duplicate_sese_region (edge entry\n       if (entry_count > total_count)\n \tentry_count = total_count;\n     }\n-  if (!(total_count > 0) || !(entry_count > 0))\n-    {\n-      total_freq = entry->dest->frequency;\n-      entry_freq = EDGE_FREQUENCY (entry);\n-      /* Fix up corner cases, to avoid division by zero or creation of negative\n-\t frequencies.  */\n-      if (total_freq == 0)\n-\ttotal_freq = 1;\n-      else if (entry_freq > total_freq)\n-\tentry_freq = total_freq;\n-    }\n \n   copy_bbs (region, n_region, region_copy, &exit, 1, &exit_copy, loop,\n \t    split_edge_bb_loc (entry), update_dominance);\n-  if (total_count > 0 && entry_count > 0)\n+  if (total_count.initialized_p () && entry_count.initialized_p ())\n     {\n       scale_bbs_frequencies_profile_count (region, n_region,\n \t\t\t\t           total_count - entry_count,\n@@ -6398,12 +6383,6 @@ gimple_duplicate_sese_region (edge entry\n       scale_bbs_frequencies_profile_count (region_copy, n_region, entry_count,\n \t\t\t\t           total_count);\n     }\n-  else\n-    {\n-      scale_bbs_frequencies_int (region, n_region, total_freq - entry_freq,\n-\t\t\t\t total_freq);\n-      scale_bbs_frequencies_int (region_copy, n_region, entry_freq, total_freq);\n-    }\n \n   if (copying_header)\n     {\n@@ -6492,7 +6471,6 @@ gimple_duplicate_sese_tail (edge entry,\n   struct loop *orig_loop = entry->dest->loop_father;\n   basic_block switch_bb, entry_bb, nentry_bb;\n   vec<basic_block> doms;\n-  int total_freq = 0, exit_freq = 0;\n   profile_count total_count = profile_count::uninitialized (),\n \t\texit_count = profile_count::uninitialized ();\n   edge exits[2], nexits[2], e;\n@@ -6537,30 +6515,16 @@ gimple_duplicate_sese_tail (edge entry,\n      inside.  */\n   doms = get_dominated_by_region (CDI_DOMINATORS, region, n_region);\n \n-  if (exit->src->count > 0)\n-    {\n-      total_count = exit->src->count;\n-      exit_count = exit->count ();\n-      /* Fix up corner cases, to avoid division by zero or creation of negative\n-\t frequencies.  */\n-      if (exit_count > total_count)\n-\texit_count = total_count;\n-    }\n-  else\n-    {\n-      total_freq = exit->src->frequency;\n-      exit_freq = EDGE_FREQUENCY (exit);\n-      /* Fix up corner cases, to avoid division by zero or creation of negative\n-\t frequencies.  */\n-      if (total_freq == 0)\n-\ttotal_freq = 1;\n-      if (exit_freq > total_freq)\n-\texit_freq = total_freq;\n-    }\n+  total_count = exit->src->count;\n+  exit_count = exit->count ();\n+  /* Fix up corner cases, to avoid division by zero or creation of negative\n+     frequencies.  */\n+  if (exit_count > total_count)\n+    exit_count = total_count;\n \n   copy_bbs (region, n_region, region_copy, exits, 2, nexits, orig_loop,\n \t    split_edge_bb_loc (exit), true);\n-  if (total_count.initialized_p ())\n+  if (total_count.initialized_p () && exit_count.initialized_p ())\n     {\n       scale_bbs_frequencies_profile_count (region, n_region,\n \t\t\t\t           total_count - exit_count,\n@@ -6568,12 +6532,6 @@ gimple_duplicate_sese_tail (edge entry,\n       scale_bbs_frequencies_profile_count (region_copy, n_region, exit_count,\n \t\t\t\t           total_count);\n     }\n-  else\n-    {\n-      scale_bbs_frequencies_int (region, n_region, total_freq - exit_freq,\n-\t\t\t\t total_freq);\n-      scale_bbs_frequencies_int (region_copy, n_region, exit_freq, total_freq);\n-    }\n \n   /* Create the switch block, and put the exit condition to it.  */\n   entry_bb = entry->dest;\n@@ -7614,9 +7572,15 @@ move_sese_region_to_fn (struct function\n      FIXME, this is silly.  The CFG ought to become a parameter to\n      these helpers.  */\n   push_cfun (dest_cfun);\n-  make_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun), entry_bb, EDGE_FALLTHRU);\n+  ENTRY_BLOCK_PTR_FOR_FN (cfun)->count = entry_bb->count;\n+  make_single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun), entry_bb, EDGE_FALLTHRU);\n   if (exit_bb)\n-    make_edge (exit_bb,  EXIT_BLOCK_PTR_FOR_FN (cfun), 0);\n+    {\n+      make_single_succ_edge (exit_bb,  EXIT_BLOCK_PTR_FOR_FN (cfun), 0);\n+      EXIT_BLOCK_PTR_FOR_FN (cfun)->count = exit_bb->count;\n+    }\n+  else\n+    EXIT_BLOCK_PTR_FOR_FN (cfun)->count = profile_count::zero ();\n   pop_cfun ();\n \n   /* Back in the original function, the SESE region has disappeared,\n@@ -8691,7 +8655,7 @@ gimple_account_profile_record (basic_blo\n       else if (profile_status_for_fn (cfun) == PROFILE_GUESSED)\n \trecord->time[after_pass]\n \t  += estimate_num_insns (gsi_stmt (i),\n-\t\t\t\t &eni_time_weights) * bb->frequency;\n+\t\t\t\t &eni_time_weights) * bb->count.to_frequency (cfun);\n     }\n }\n \n@@ -8843,7 +8807,6 @@ insert_cond_bb (basic_block bb, gimple *\n   edge e = make_edge (bb, new_bb, EDGE_TRUE_VALUE);\n   e->probability = prob;\n   new_bb->count = e->count ();\n-  new_bb->frequency = prob.apply (bb->frequency);\n   make_single_succ_edge (new_bb, fall->dest, EDGE_FALLTHRU);\n \n   /* Fix edge for split bb.  */\n@@ -9264,9 +9227,9 @@ execute_fixup_cfg (void)\n   cgraph_node *node = cgraph_node::get (current_function_decl);\n   profile_count num = node->count;\n   profile_count den = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;\n-  bool scale = num.initialized_p ()\n-\t       && (den > 0 || num == profile_count::zero ())\n-\t       && !(num == den);\n+  bool scale = num.initialized_p () && den.ipa_p ()\n+\t       && (den.nonzero_p () || num == profile_count::zero ())\n+\t       && !(num == den.ipa ());\n \n   if (scale)\n     {\nIndex: tree-complex.c\n===================================================================\n--- tree-complex.c\t(revision 254348)\n+++ tree-complex.c\t(working copy)\n@@ -1191,7 +1191,6 @@ expand_complex_div_wide (gimple_stmt_ite\n       bb_join = e->dest;\n       bb_true = create_empty_bb (bb_cond);\n       bb_false = create_empty_bb (bb_true);\n-      bb_true->frequency = bb_false->frequency = bb_cond->frequency / 2;\n       bb_true->count = bb_false->count\n \t = bb_cond->count.apply_probability (profile_probability::even ());\n \nIndex: tree-eh.c\n===================================================================\n--- tree-eh.c\t(revision 254348)\n+++ tree-eh.c\t(working copy)\n@@ -3224,6 +3224,7 @@ lower_resx (basic_block bb, gresx *stmt,\n \t      gimple_stmt_iterator gsi2;\n \n \t      new_bb = create_empty_bb (bb);\n+\t      new_bb->count = bb->count;\n \t      add_bb_to_loop (new_bb, bb->loop_father);\n \t      lab = gimple_block_label (new_bb);\n \t      gsi2 = gsi_start_bb (new_bb);\nIndex: tree-inline.c\n===================================================================\n--- tree-inline.c\t(revision 254348)\n+++ tree-inline.c\t(working copy)\n@@ -1763,16 +1763,15 @@ remap_gimple_stmt (gimple *stmt, copy_bo\n    later  */\n \n static basic_block\n-copy_bb (copy_body_data *id, basic_block bb, int frequency_scale,\n+copy_bb (copy_body_data *id, basic_block bb,\n          profile_count num, profile_count den)\n {\n   gimple_stmt_iterator gsi, copy_gsi, seq_gsi;\n   basic_block copy_basic_block;\n   tree decl;\n-  gcov_type freq;\n   basic_block prev;\n-  bool scale = num.initialized_p ()\n-\t       && (den > 0 || num == profile_count::zero ());\n+  bool scale = !num.initialized_p ()\n+\t       || (den.nonzero_p () || num == profile_count::zero ());\n \n   /* Search for previous copied basic block.  */\n   prev = bb->prev_bb;\n@@ -1784,15 +1783,8 @@ copy_bb (copy_body_data *id, basic_block\n   copy_basic_block = create_basic_block (NULL, (basic_block) prev->aux);\n   if (scale)\n     copy_basic_block->count = bb->count.apply_scale (num, den);\n-\n-  /* We are going to rebuild frequencies from scratch.  These values\n-     have just small importance to drive canonicalize_loop_headers.  */\n-  freq = apply_scale ((gcov_type)bb->frequency, frequency_scale);\n-\n-  /* We recompute frequencies after inlining, so this is quite safe.  */\n-  if (freq > BB_FREQ_MAX)\n-    freq = BB_FREQ_MAX;\n-  copy_basic_block->frequency = freq;\n+  else if (num.initialized_p ())\n+    copy_basic_block->count = bb->count;\n \n   copy_gsi = gsi_start_bb (copy_basic_block);\n \n@@ -2068,8 +2060,8 @@ copy_bb (copy_body_data *id, basic_block\n \t\t\t      fprintf (dump_file,\n \t\t\t\t       \"Orig bb: %i, orig bb freq %i, new bb freq %i\\n\",\n \t\t\t\t       bb->index,\n-\t\t\t\t       bb->frequency,\n-\t\t\t\t       copy_basic_block->frequency);\n+\t\t\t\t       bb->count.to_frequency (cfun),\n+\t\t\t\t       copy_basic_block->count.to_frequency (cfun));\n \t\t\t    }\n \t\t\t}\n \t\t    }\n@@ -2507,11 +2499,8 @@ initialize_cfun (tree new_fndecl, tree c\n \n   profile_status_for_fn (cfun) = profile_status_for_fn (src_cfun);\n \n-  /* FIXME: When all counts are known to be zero, scaling is also meaningful.\n-   */\n   if (ENTRY_BLOCK_PTR_FOR_FN (src_cfun)->count.initialized_p ()\n-      && count.initialized_p ()\n-      && ENTRY_BLOCK_PTR_FOR_FN (src_cfun)->count.initialized_p ())\n+      && count.ipa ().initialized_p ())\n     {\n       ENTRY_BLOCK_PTR_FOR_FN (cfun)->count =\n \tENTRY_BLOCK_PTR_FOR_FN (src_cfun)->count.apply_scale (count,\n@@ -2520,10 +2509,13 @@ initialize_cfun (tree new_fndecl, tree c\n \tEXIT_BLOCK_PTR_FOR_FN (src_cfun)->count.apply_scale (count,\n \t\t\t\t    ENTRY_BLOCK_PTR_FOR_FN (src_cfun)->count);\n     }\n-  ENTRY_BLOCK_PTR_FOR_FN (cfun)->frequency\n-    = ENTRY_BLOCK_PTR_FOR_FN (src_cfun)->frequency;\n-  EXIT_BLOCK_PTR_FOR_FN (cfun)->frequency =\n-    EXIT_BLOCK_PTR_FOR_FN (src_cfun)->frequency;\n+  else\n+    {\n+      ENTRY_BLOCK_PTR_FOR_FN (cfun)->count\n+\t   = ENTRY_BLOCK_PTR_FOR_FN (src_cfun)->count;\n+      EXIT_BLOCK_PTR_FOR_FN (cfun)->count\n+\t   = EXIT_BLOCK_PTR_FOR_FN (src_cfun)->count;\n+    }\n   if (src_cfun->eh)\n     init_eh_for_function ();\n \n@@ -2680,27 +2672,11 @@ redirect_all_calls (copy_body_data * id,\n     }\n }\n \n-/* Convert estimated frequencies into counts for NODE, scaling COUNT\n-   with each bb's frequency. Used when NODE has a 0-weight entry\n-   but we are about to inline it into a non-zero count call bb.\n-   See the comments for handle_missing_profiles() in predict.c for\n-   when this can happen for COMDATs.  */\n-\n-void\n-freqs_to_counts (struct cgraph_node *node, profile_count count)\n-{\n-  basic_block bb;\n-  struct function *fn = DECL_STRUCT_FUNCTION (node->decl);\n-\n-  FOR_ALL_BB_FN(bb, fn)\n-    bb->count = count.apply_scale (bb->frequency, BB_FREQ_MAX);\n-}\n-\n /* Make a copy of the body of FN so that it can be inserted inline in\n    another function.  Walks FN via CFG, returns new fndecl.  */\n \n static tree\n-copy_cfg_body (copy_body_data * id, profile_count count, int frequency_scale,\n+copy_cfg_body (copy_body_data * id, profile_count,\n \t       basic_block entry_block_map, basic_block exit_block_map,\n \t       basic_block new_entry)\n {\n@@ -2712,31 +2688,10 @@ copy_cfg_body (copy_body_data * id, prof\n   tree new_fndecl = NULL;\n   bool need_debug_cleanup = false;\n   int last;\n-  int incoming_frequency = 0;\n-  profile_count incoming_count = profile_count::zero ();\n-  profile_count num = count;\n   profile_count den = ENTRY_BLOCK_PTR_FOR_FN (src_cfun)->count;\n-  bool scale = num.initialized_p ()\n-\t       && (den > 0 || num == profile_count::zero ());\n+  profile_count num = entry_block_map->count;\n \n-  /* This can happen for COMDAT routines that end up with 0 counts\n-     despite being called (see the comments for handle_missing_profiles()\n-     in predict.c as to why). Apply counts to the blocks in the callee\n-     before inlining, using the guessed edge frequencies, so that we don't\n-     end up with a 0-count inline body which can confuse downstream\n-     optimizations such as function splitting.  */\n-  if (!(ENTRY_BLOCK_PTR_FOR_FN (src_cfun)->count > 0) && count > 0)\n-    {\n-      /* Apply the larger of the call bb count and the total incoming\n-         call edge count to the callee.  */\n-      profile_count in_count = profile_count::zero ();\n-      struct cgraph_edge *in_edge;\n-      for (in_edge = id->src_node->callers; in_edge;\n-           in_edge = in_edge->next_caller)\n-\tif (in_edge->count.initialized_p ())\n-          in_count += in_edge->count;\n-      freqs_to_counts (id->src_node, count > in_count ? count : in_count);\n-    }\n+  cfun_to_copy = id->src_cfun = DECL_STRUCT_FUNCTION (callee_fndecl);\n \n   /* Register specific tree functions.  */\n   gimple_register_cfg_hooks ();\n@@ -2750,25 +2705,18 @@ copy_cfg_body (copy_body_data * id, prof\n     {\n       edge e;\n       edge_iterator ei;\n+      den = profile_count::zero ();\n \n       FOR_EACH_EDGE (e, ei, new_entry->preds)\n \tif (!e->src->aux)\n-\t  incoming_frequency += EDGE_FREQUENCY (e);\n-      if (scale)\n-        incoming_count = incoming_count.apply_scale (num, den);\n-      else\n-\tincoming_count = profile_count::uninitialized ();\n-      incoming_frequency\n-\t= apply_scale ((gcov_type)incoming_frequency, frequency_scale);\n-      ENTRY_BLOCK_PTR_FOR_FN (cfun)->count = incoming_count;\n-      ENTRY_BLOCK_PTR_FOR_FN (cfun)->frequency = incoming_frequency;\n+\t  den += e->count ();\n+      ENTRY_BLOCK_PTR_FOR_FN (cfun)->count = den;\n     }\n \n   /* Must have a CFG here at this point.  */\n   gcc_assert (ENTRY_BLOCK_PTR_FOR_FN\n \t      (DECL_STRUCT_FUNCTION (callee_fndecl)));\n \n-  cfun_to_copy = id->src_cfun = DECL_STRUCT_FUNCTION (callee_fndecl);\n \n   ENTRY_BLOCK_PTR_FOR_FN (cfun_to_copy)->aux = entry_block_map;\n   EXIT_BLOCK_PTR_FOR_FN (cfun_to_copy)->aux = exit_block_map;\n@@ -2784,7 +2732,7 @@ copy_cfg_body (copy_body_data * id, prof\n   FOR_EACH_BB_FN (bb, cfun_to_copy)\n     if (!id->blocks_to_copy || bitmap_bit_p (id->blocks_to_copy, bb->index))\n       {\n-\tbasic_block new_bb = copy_bb (id, bb, frequency_scale, num, den);\n+\tbasic_block new_bb = copy_bb (id, bb, num, den);\n \tbb->aux = new_bb;\n \tnew_bb->aux = bb;\n \tnew_bb->loop_father = entry_block_map->loop_father;\n@@ -3011,7 +2959,7 @@ copy_tree_body (copy_body_data *id)\n    another function.  */\n \n static tree\n-copy_body (copy_body_data *id, profile_count count, int frequency_scale,\n+copy_body (copy_body_data *id, profile_count count,\n \t   basic_block entry_block_map, basic_block exit_block_map,\n \t   basic_block new_entry)\n {\n@@ -3020,7 +2968,7 @@ copy_body (copy_body_data *id, profile_c\n \n   /* If this body has a CFG, walk CFG and copy.  */\n   gcc_assert (ENTRY_BLOCK_PTR_FOR_FN (DECL_STRUCT_FUNCTION (fndecl)));\n-  body = copy_cfg_body (id, count, frequency_scale, entry_block_map, exit_block_map,\n+  body = copy_cfg_body (id, count, entry_block_map, exit_block_map,\n \t\t\tnew_entry);\n   copy_debug_stmts (id);\n \n@@ -4771,7 +4719,6 @@ expand_call_inline (basic_block bb, gimp\n      a self-referential call; if we're calling ourselves, we need to\n      duplicate our body before altering anything.  */\n   copy_body (id, cg_edge->callee->count,\n-  \t     GCOV_COMPUTE_SCALE (cg_edge->frequency, CGRAPH_FREQ_BASE),\n \t     bb, return_block, NULL);\n \n   reset_debug_bindings (id, stmt_gsi);\n@@ -5146,6 +5093,7 @@ optimize_inline_calls (tree fn)\n     }\n \n   /* Fold queued statements.  */\n+  counts_to_freqs ();\n   fold_marked_statements (last, id.statements_to_fold);\n   delete id.statements_to_fold;\n \n@@ -6090,7 +6038,7 @@ tree_function_versioning (tree old_decl,\n     }\n \n   /* Copy the Function's body.  */\n-  copy_body (&id, old_entry_block->count, REG_BR_PROB_BASE,\n+  copy_body (&id, old_entry_block->count,\n \t     ENTRY_BLOCK_PTR_FOR_FN (cfun), EXIT_BLOCK_PTR_FOR_FN (cfun),\n \t     new_entry);\n \n@@ -6122,6 +6070,7 @@ tree_function_versioning (tree old_decl,\n   free_dominance_info (CDI_DOMINATORS);\n   free_dominance_info (CDI_POST_DOMINATORS);\n \n+  counts_to_freqs ();\n   fold_marked_statements (0, id.statements_to_fold);\n   delete id.statements_to_fold;\n   delete_unreachable_blocks_update_callgraph (&id);\n@@ -6141,20 +6090,20 @@ tree_function_versioning (tree old_decl,\n       struct cgraph_edge *e;\n       rebuild_frequencies ();\n \n-      new_version_node->count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;\n+      new_version_node->count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.ipa ();\n       for (e = new_version_node->callees; e; e = e->next_callee)\n \t{\n \t  basic_block bb = gimple_bb (e->call_stmt);\n \t  e->frequency = compute_call_stmt_bb_frequency (current_function_decl,\n \t\t\t\t\t\t\t bb);\n-\t  e->count = bb->count;\n+\t  e->count = bb->count.ipa ();\n \t}\n       for (e = new_version_node->indirect_calls; e; e = e->next_callee)\n \t{\n \t  basic_block bb = gimple_bb (e->call_stmt);\n \t  e->frequency = compute_call_stmt_bb_frequency (current_function_decl,\n \t\t\t\t\t\t\t bb);\n-\t  e->count = bb->count;\n+\t  e->count = bb->count.ipa ();\n \t}\n     }\n \nIndex: tree-ssa-coalesce.c\n===================================================================\n--- tree-ssa-coalesce.c\t(revision 254348)\n+++ tree-ssa-coalesce.c\t(working copy)\n@@ -164,7 +164,7 @@ coalesce_cost (int frequency, bool optim\n static inline int\n coalesce_cost_bb (basic_block bb)\n {\n-  return coalesce_cost (bb->frequency, optimize_bb_for_size_p (bb));\n+  return coalesce_cost (bb->count.to_frequency (cfun), optimize_bb_for_size_p (bb));\n }\n \n \nIndex: tree-ssa-ifcombine.c\n===================================================================\n--- tree-ssa-ifcombine.c\t(revision 254348)\n+++ tree-ssa-ifcombine.c\t(working copy)\n@@ -366,7 +366,6 @@ update_profile_after_ifcombine (basic_bl\n \t\t\t\t - inner_taken->probability;\n \n   outer_to_inner->probability = profile_probability::always ();\n-  inner_cond_bb->frequency = outer_cond_bb->frequency;\n   outer2->probability = profile_probability::never ();\n }\n \nIndex: tree-ssa-loop-im.c\n===================================================================\n--- tree-ssa-loop-im.c\t(revision 254348)\n+++ tree-ssa-loop-im.c\t(working copy)\n@@ -1803,7 +1803,7 @@ execute_sm_if_changed (edge ex, tree mem\n   for (hash_set<basic_block>::iterator it = flag_bbs->begin ();\n        it != flag_bbs->end (); ++it)\n     {\n-       freq_sum += (*it)->frequency;\n+       freq_sum += (*it)->count.to_frequency (cfun);\n        if ((*it)->count.initialized_p ())\n          count_sum += (*it)->count, ncount ++;\n        if (dominated_by_p (CDI_DOMINATORS, ex->src, *it))\n@@ -1815,20 +1815,15 @@ execute_sm_if_changed (edge ex, tree mem\n \n   if (flag_probability.initialized_p ())\n     ;\n-  else if (ncount == nbbs && count_sum > 0 && preheader->count () >= count_sum)\n+  else if (ncount == nbbs\n+\t   && preheader->count () >= count_sum && preheader->count ().nonzero_p ())\n     {\n       flag_probability = count_sum.probability_in (preheader->count ());\n       if (flag_probability > cap)\n \tflag_probability = cap;\n     }\n-  else if (freq_sum > 0 && EDGE_FREQUENCY (preheader) >= freq_sum)\n-    {\n-      flag_probability = profile_probability::from_reg_br_prob_base\n-\t\t(GCOV_COMPUTE_SCALE (freq_sum, EDGE_FREQUENCY (preheader)));\n-      if (flag_probability > cap)\n-\tflag_probability = cap;\n-    }\n-  else\n+\n+  if (!flag_probability.initialized_p ())\n     flag_probability = cap;\n \n   /* ?? Insert store after previous store if applicable.  See note\n@@ -1861,7 +1856,6 @@ execute_sm_if_changed (edge ex, tree mem\n   old_dest = ex->dest;\n   new_bb = split_edge (ex);\n   then_bb = create_empty_bb (new_bb);\n-  then_bb->frequency = flag_probability.apply (new_bb->frequency);\n   then_bb->count = new_bb->count.apply_probability (flag_probability);\n   if (irr)\n     then_bb->flags = BB_IRREDUCIBLE_LOOP;\nIndex: tree-ssa-loop-ivcanon.c\n===================================================================\n--- tree-ssa-loop-ivcanon.c\t(revision 254348)\n+++ tree-ssa-loop-ivcanon.c\t(working copy)\n@@ -647,7 +647,6 @@ unloop_loops (bitmap loop_closed_ssa_inv\n \n       add_bb_to_loop (latch_edge->dest, current_loops->tree_root);\n       latch_edge->dest->count = profile_count::zero ();\n-      latch_edge->dest->frequency = 0;\n       set_immediate_dominator (CDI_DOMINATORS, latch_edge->dest, latch_edge->src);\n \n       gsi = gsi_start_bb (latch_edge->dest);\n@@ -1090,7 +1089,6 @@ try_peel_loop (struct loop *loop,\n \t}\n     }\n   profile_count entry_count = profile_count::zero ();\n-  int entry_freq = 0;\n \n   edge e;\n   edge_iterator ei;\n@@ -1099,15 +1097,10 @@ try_peel_loop (struct loop *loop,\n       {\n \tif (e->src->count.initialized_p ())\n \t  entry_count = e->src->count + e->src->count;\n-\tentry_freq += e->src->frequency;\n \tgcc_assert (!flow_bb_inside_loop_p (loop, e->src));\n       }\n   profile_probability p = profile_probability::very_unlikely ();\n-  if (loop->header->count > 0)\n-    p = entry_count.probability_in (loop->header->count);\n-  else if (loop->header->frequency)\n-    p = profile_probability::probability_in_gcov_type\n-\t\t (entry_freq, loop->header->frequency);\n+  p = entry_count.probability_in (loop->header->count);\n   scale_loop_profile (loop, p, 0);\n   bitmap_set_bit (peeled_loops, loop->num);\n   return true;\nIndex: tree-ssa-loop-ivopts.c\n===================================================================\n--- tree-ssa-loop-ivopts.c\t(revision 254348)\n+++ tree-ssa-loop-ivopts.c\t(working copy)\n@@ -4457,8 +4457,8 @@ get_address_cost (struct ivopts_data *da\n static comp_cost\n get_scaled_computation_cost_at (ivopts_data *data, gimple *at, comp_cost cost)\n {\n-   int loop_freq = data->current_loop->header->frequency;\n-   int bb_freq = gimple_bb (at)->frequency;\n+   int loop_freq = data->current_loop->header->count.to_frequency (cfun);\n+   int bb_freq = gimple_bb (at)->count.to_frequency (cfun);\n    if (loop_freq != 0)\n      {\n        gcc_assert (cost.scratch <= cost.cost);\nIndex: tree-ssa-loop-manip.c\n===================================================================\n--- tree-ssa-loop-manip.c\t(revision 254348)\n+++ tree-ssa-loop-manip.c\t(working copy)\n@@ -1122,6 +1122,9 @@ niter_for_unrolled_loop (struct loop *lo\n      converts back.  */\n   gcov_type new_est_niter = est_niter / factor;\n \n+  if (est_niter == -1)\n+    return -1;\n+\n   /* Without profile feedback, loops for which we do not know a better estimate\n      are assumed to roll 10 times.  When we unroll such loop, it appears to\n      roll too little, and it may even seem to be cold.  To avoid this, we\n@@ -1370,14 +1373,7 @@ tree_transform_and_unroll_loop (struct l\n \n   freq_h = loop->header->count;\n   freq_e = (loop_preheader_edge (loop))->count ();\n-  /* Use frequency only if counts are zero.  */\n-  if (!(freq_h > 0) && !(freq_e > 0))\n-    {\n-      freq_h = profile_count::from_gcov_type (loop->header->frequency);\n-      freq_e = profile_count::from_gcov_type\n-\t\t (EDGE_FREQUENCY (loop_preheader_edge (loop)));\n-    }\n-  if (freq_h > 0)\n+  if (freq_h.nonzero_p ())\n     {\n       /* Avoid dropping loop body profile counter to 0 because of zero count\n \t in loop's preheader.  */\n@@ -1392,7 +1388,6 @@ tree_transform_and_unroll_loop (struct l\n \t\t\t\t.apply_scale (1, new_est_niter + 1);\n \n   rest->count += new_exit->count ();\n-  rest->frequency += EDGE_FREQUENCY (new_exit);\n \n   new_nonexit = single_pred_edge (loop->latch);\n   prob = new_nonexit->probability;\nIndex: tree-ssa-loop-niter.c\n===================================================================\n--- tree-ssa-loop-niter.c\t(revision 254348)\n+++ tree-ssa-loop-niter.c\t(working copy)\n@@ -3901,7 +3901,7 @@ estimate_numbers_of_iterations (struct l\n      recomputing iteration bounds later in the compilation process will just\n      introduce random roundoff errors.  */\n   if (!loop->any_estimate\n-      && loop->header->count > 0)\n+      && loop->header->count.reliable_p ())\n     {\n       gcov_type nit = expected_loop_iterations_unbounded (loop);\n       bound = gcov_type_to_wide_int (nit);\nIndex: tree-ssa-loop-unswitch.c\n===================================================================\n--- tree-ssa-loop-unswitch.c\t(revision 254348)\n+++ tree-ssa-loop-unswitch.c\t(working copy)\n@@ -852,7 +852,7 @@ hoist_guard (struct loop *loop, edge gua\n   /* Determine the probability that we skip the loop.  Assume that loop has\n      same average number of iterations regardless outcome of guard.  */\n   new_edge->probability = guard->probability;\n-  profile_count skip_count = guard->src->count > 0\n+  profile_count skip_count = guard->src->count.nonzero_p ()\n \t\t   ? guard->count ().apply_scale (pre_header->count,\n \t\t\t\t\t       guard->src->count)\n \t\t   : guard->count ().apply_probability (new_edge->probability);\n@@ -875,7 +875,6 @@ hoist_guard (struct loop *loop, edge gua\n      to loop header...  */\n   e->probability = new_edge->probability.invert ();\n   e->dest->count = e->count ();\n-  e->dest->frequency = EDGE_FREQUENCY (e);\n \n   /* ... now update profile to represent that original guard will be optimized\n      away ...  */\nIndex: tree-ssa-sink.c\n===================================================================\n--- tree-ssa-sink.c\t(revision 254348)\n+++ tree-ssa-sink.c\t(working copy)\n@@ -226,7 +226,8 @@ select_best_block (basic_block early_bb,\n   /* If BEST_BB is at the same nesting level, then require it to have\n      significantly lower execution frequency to avoid gratutious movement.  */\n   if (bb_loop_depth (best_bb) == bb_loop_depth (early_bb)\n-      && best_bb->frequency < (early_bb->frequency * threshold / 100.0))\n+      && best_bb->count.to_frequency (cfun)\n+\t < (early_bb->count.to_frequency (cfun) * threshold / 100.0))\n     return best_bb;\n \n   /* No better block found, so return EARLY_BB, which happens to be the\nIndex: tree-ssa-tail-merge.c\n===================================================================\n--- tree-ssa-tail-merge.c\t(revision 254348)\n+++ tree-ssa-tail-merge.c\t(working copy)\n@@ -1530,8 +1530,6 @@ static void\n replace_block_by (basic_block bb1, basic_block bb2)\n {\n   edge pred_edge;\n-  edge e1, e2;\n-  edge_iterator ei;\n   unsigned int i;\n   gphi *bb2_phi;\n \n@@ -1560,9 +1558,13 @@ replace_block_by (basic_block bb1, basic\n \n   bb2->count += bb1->count;\n \n+  /* FIXME: Fix merging of probabilities.  They need to be redistributed\n+     according to the relative counts of merged BBs.  */\n+#if 0\n   /* Merge the outgoing edge counts from bb1 onto bb2.  */\n   profile_count out_sum = profile_count::zero ();\n   int out_freq_sum = 0;\n+  edge e1, e2;\n \n   /* Recompute the edge probabilities from the new merged edge count.\n      Use the sum of the new merged edge counts computed above instead\n@@ -1580,7 +1582,6 @@ replace_block_by (basic_block bb1, basic\n \tout_sum += e1->count ();\n       out_freq_sum += EDGE_FREQUENCY (e1);\n     }\n-\n   FOR_EACH_EDGE (e1, ei, bb1->succs)\n     {\n       e2 = find_edge (bb2, e1->dest);\n@@ -1589,9 +1590,9 @@ replace_block_by (basic_block bb1, basic\n \t{\n \t  e2->probability = e2->count ().probability_in (bb2->count);\n \t}\n-      else if (bb1->frequency && bb2->frequency)\n+      else if (bb1->count.to_frequency (cfun) && bb2->count.to_frequency (cfun))\n \te2->probability = e1->probability;\n-      else if (bb2->frequency && !bb1->frequency)\n+      else if (bb2->count.to_frequency (cfun) && !bb1->count.to_frequency (cfun))\n \t;\n       else if (out_freq_sum)\n \te2->probability = profile_probability::from_reg_br_prob_base\n@@ -1600,9 +1601,7 @@ replace_block_by (basic_block bb1, basic\n \t\t\t\t     out_freq_sum));\n       out_sum += e2->count ();\n     }\n-  bb2->frequency += bb1->frequency;\n-  if (bb2->frequency > BB_FREQ_MAX)\n-    bb2->frequency = BB_FREQ_MAX;\n+#endif\n \n   /* Move over any user labels from bb1 after the bb2 labels.  */\n   gimple_stmt_iterator gsi1 = gsi_start_bb (bb1);\nIndex: tree-ssa-threadupdate.c\n===================================================================\n--- tree-ssa-threadupdate.c\t(revision 254348)\n+++ tree-ssa-threadupdate.c\t(working copy)\n@@ -339,7 +339,6 @@ create_block_for_threading (basic_block\n     e->aux = NULL;\n \n   /* Zero out the profile, since the block is unreachable for now.  */\n-  rd->dup_blocks[count]->frequency = 0;\n   rd->dup_blocks[count]->count = profile_count::uninitialized ();\n   if (duplicate_blocks)\n     bitmap_set_bit (*duplicate_blocks, rd->dup_blocks[count]->index);\n@@ -590,7 +589,7 @@ any_remaining_duplicated_blocks (vec<jum\n }\n \n \n-/* Compute the amount of profile count/frequency coming into the jump threading\n+/* Compute the amount of profile count coming into the jump threading\n    path stored in RD that we are duplicating, returned in PATH_IN_COUNT_PTR and\n    PATH_IN_FREQ_PTR, as well as the amount of counts flowing out of the\n    duplicated path, returned in PATH_OUT_COUNT_PTR.  LOCAL_INFO is used to\n@@ -598,7 +597,7 @@ any_remaining_duplicated_blocks (vec<jum\n    edges that need to be ignored in the analysis.  Return true if path contains\n    a joiner, false otherwise.\n \n-   In the non-joiner case, this is straightforward - all the counts/frequency\n+   In the non-joiner case, this is straightforward - all the counts\n    flowing into the jump threading path should flow through the duplicated\n    block and out of the duplicated path.\n \n@@ -851,16 +850,14 @@ compute_path_counts (struct redirection_\n \n /* Update the counts and frequencies for both an original path\n    edge EPATH and its duplicate EDUP.  The duplicate source block\n-   will get a count/frequency of PATH_IN_COUNT and PATH_IN_FREQ,\n+   will get a count of PATH_IN_COUNT and PATH_IN_FREQ,\n    and the duplicate edge EDUP will have a count of PATH_OUT_COUNT.  */\n static void\n update_profile (edge epath, edge edup, profile_count path_in_count,\n-\t\tprofile_count path_out_count, int path_in_freq)\n+\t\tprofile_count path_out_count)\n {\n-  if (!(path_in_count > 0))\n-    return;\n \n-  /* First update the duplicated block's count / frequency.  */\n+  /* First update the duplicated block's count.  */\n   if (edup)\n     {\n       basic_block dup_block = edup->src;\n@@ -894,167 +891,54 @@ update_profile (edge epath, edge edup, p\n \t    if (esucc != edup)\n \t      esucc->probability *= scale;\n \t}\n-      edup->probability = edup_prob;\n+      if (edup_prob.initialized_p ())\n+        edup->probability = edup_prob;\n \n-      /* FIXME once freqs_to_counts is dropped re-enable this check.  */\n-      gcc_assert (!dup_block->count.initialized_p () || 1);\n-      gcc_assert (dup_block->frequency == 0);\n+      gcc_assert (!dup_block->count.initialized_p ());\n       dup_block->count = path_in_count;\n-      dup_block->frequency = path_in_freq;\n     }\n \n+  if (path_in_count == profile_count::zero ())\n+    return;\n+\n   profile_count final_count = epath->count () - path_out_count;\n \n-  /* Now update the original block's count and frequency in the\n+  /* Now update the original block's count in the\n      opposite manner - remove the counts/freq that will flow\n      into the duplicated block.  Handle underflow due to precision/\n      rounding issues.  */\n   epath->src->count -= path_in_count;\n-  epath->src->frequency -= path_in_freq;\n-  if (epath->src->frequency < 0)\n-    epath->src->frequency = 0;\n \n   /* Next update this path edge's original and duplicated counts.  We know\n      that the duplicated path will have path_out_count flowing\n      out of it (in the joiner case this is the count along the duplicated path\n      out of the duplicated joiner).  This count can then be removed from the\n      original path edge.  */\n-  if (epath->src->count > 0)\n-    {\n-      edge esucc;\n-      edge_iterator ei;\n-      profile_probability epath_prob = final_count.probability_in (epath->src->count);\n-\n-      if (epath->probability > epath_prob)\n-\t{\n-\t   profile_probability rev_scale\n-\t     = (profile_probability::always () - epath->probability)\n-\t       / (profile_probability::always () - epath_prob);\n-\t   FOR_EACH_EDGE (esucc, ei, epath->src->succs)\n-\t     if (esucc != epath)\n-\t       esucc->probability /= rev_scale;\n-\t}\n-      else if (epath->probability < epath_prob)\n-\t{\n-\t   profile_probability scale\n-\t     = (profile_probability::always () - epath_prob)\n-\t       / (profile_probability::always () - epath->probability);\n-\t  FOR_EACH_EDGE (esucc, ei, epath->src->succs)\n-\t    if (esucc != epath)\n-\t      esucc->probability *= scale;\n-\t}\n-      epath->probability = epath_prob;\n-    }\n-}\n-\n \n-/* Check if the paths through RD all have estimated frequencies but zero\n-   profile counts.  This is more accurate than checking the entry block\n-   for a zero profile count, since profile insanities sometimes creep in.  */\n-\n-static bool\n-estimated_freqs_path (struct redirection_data *rd)\n-{\n-  edge e = rd->incoming_edges->e;\n-  vec<jump_thread_edge *> *path = THREAD_PATH (e);\n-  edge ein;\n+  edge esucc;\n   edge_iterator ei;\n-  bool non_zero_freq = false;\n-  FOR_EACH_EDGE (ein, ei, e->dest->preds)\n-    {\n-      if (ein->count () > 0)\n-\treturn false;\n-      non_zero_freq |= ein->src->frequency != 0;\n-    }\n+  profile_probability epath_prob = final_count.probability_in (epath->src->count);\n \n-  for (unsigned int i = 1; i < path->length (); i++)\n+  if (epath->probability > epath_prob)\n     {\n-      edge epath = (*path)[i]->e;\n-      if (epath->src->count > 0)\n-\treturn false;\n-      non_zero_freq |= epath->src->frequency != 0;\n-      edge esucc;\n+       profile_probability rev_scale\n+\t = (profile_probability::always () - epath->probability)\n+\t   / (profile_probability::always () - epath_prob);\n+       FOR_EACH_EDGE (esucc, ei, epath->src->succs)\n+\t if (esucc != epath)\n+\t   esucc->probability /= rev_scale;\n+    }\n+  else if (epath->probability < epath_prob)\n+    {\n+       profile_probability scale\n+\t = (profile_probability::always () - epath_prob)\n+\t   / (profile_probability::always () - epath->probability);\n       FOR_EACH_EDGE (esucc, ei, epath->src->succs)\n-\t{\n-\t  if (esucc->count () > 0)\n-\t    return false;\n-\t  non_zero_freq |= esucc->src->frequency != 0;\n-\t}\n-    }\n-  return non_zero_freq;\n-}\n-\n-\n-/* Invoked for routines that have guessed frequencies and no profile\n-   counts to record the block and edge frequencies for paths through RD\n-   in the profile count fields of those blocks and edges.  This is because\n-   ssa_fix_duplicate_block_edges incrementally updates the block and\n-   edge counts as edges are redirected, and it is difficult to do that\n-   for edge frequencies which are computed on the fly from the source\n-   block frequency and probability.  When a block frequency is updated\n-   its outgoing edge frequencies are affected and become difficult to\n-   adjust.  */\n-\n-static void\n-freqs_to_counts_path (struct redirection_data *rd)\n-{\n-  edge e = rd->incoming_edges->e;\n-  vec<jump_thread_edge *> *path = THREAD_PATH (e);\n-  edge ein;\n-  edge_iterator ei;\n-\n-  FOR_EACH_EDGE (ein, ei, e->dest->preds)\n-    ein->src->count = profile_count::from_gcov_type\n-\t  (ein->src->frequency * REG_BR_PROB_BASE);\n-  for (unsigned int i = 1; i < path->length (); i++)\n-    {\n-      edge epath = (*path)[i]->e;\n-      /* Scale up the frequency by REG_BR_PROB_BASE, to avoid rounding\n-\t errors applying the edge probability when the frequencies are very\n-\t small.  */\n-      epath->src->count = \n-\tprofile_count::from_gcov_type\n-\t  (epath->src->frequency * REG_BR_PROB_BASE);\n-    }\n-}\n-\n-\n-/* For routines that have guessed frequencies and no profile counts, where we\n-   used freqs_to_counts_path to record block and edge frequencies for paths\n-   through RD, we clear the counts after completing all updates for RD.\n-   The updates in ssa_fix_duplicate_block_edges are based off the count fields,\n-   but the block frequencies and edge probabilities were updated as well,\n-   so we can simply clear the count fields.  */\n-\n-static void\n-clear_counts_path (struct redirection_data *rd)\n-{\n-  edge e = rd->incoming_edges->e;\n-  vec<jump_thread_edge *> *path = THREAD_PATH (e);\n-  profile_count val = profile_count::uninitialized ();\n-  if (profile_status_for_fn (cfun) == PROFILE_READ)\n-    val = profile_count::zero ();\n-\n-  edge ein;\n-  edge_iterator ei;\n-\n-  FOR_EACH_EDGE (ein, ei, e->dest->preds)\n-    ein->src->count = val;\n-\n-  /* First clear counts along original path.  */\n-  for (unsigned int i = 1; i < path->length (); i++)\n-    {\n-      edge epath = (*path)[i]->e;\n-      epath->src->count = val;\n-    }\n-  /* Also need to clear the counts along duplicated path.  */\n-  for (unsigned int i = 0; i < 2; i++)\n-    {\n-      basic_block dup = rd->dup_blocks[i];\n-      if (!dup)\n-\tcontinue;\n-      dup->count = val;\n+\tif (esucc != epath)\n+\t  esucc->probability *= scale;\n     }\n+  if (epath_prob.initialized_p ())\n+    epath->probability = epath_prob;\n }\n \n /* Wire up the outgoing edges from the duplicate blocks and\n@@ -1072,20 +956,6 @@ ssa_fix_duplicate_block_edges (struct re\n   profile_count path_out_count = profile_count::zero ();\n   int path_in_freq = 0;\n \n-  /* This routine updates profile counts, frequencies, and probabilities\n-     incrementally. Since it is difficult to do the incremental updates\n-     using frequencies/probabilities alone, for routines without profile\n-     data we first take a snapshot of the existing block and edge frequencies\n-     by copying them into the empty profile count fields.  These counts are\n-     then used to do the incremental updates, and cleared at the end of this\n-     routine.  If the function is marked as having a profile, we still check\n-     to see if the paths through RD are using estimated frequencies because\n-     the routine had zero profile counts.  */\n-  bool do_freqs_to_counts = (profile_status_for_fn (cfun) != PROFILE_READ\n-\t\t\t     || estimated_freqs_path (rd));\n-  if (do_freqs_to_counts)\n-    freqs_to_counts_path (rd);\n-\n   /* First determine how much profile count to move from original\n      path to the duplicate path.  This is tricky in the presence of\n      a joiner (see comments for compute_path_counts), where some portion\n@@ -1096,7 +966,6 @@ ssa_fix_duplicate_block_edges (struct re\n \t\t\t\t\t &path_in_count, &path_out_count,\n \t\t\t\t\t &path_in_freq);\n \n-  int cur_path_freq = path_in_freq;\n   for (unsigned int count = 0, i = 1; i < path->length (); i++)\n     {\n       edge epath = (*path)[i]->e;\n@@ -1162,19 +1031,14 @@ ssa_fix_duplicate_block_edges (struct re\n \t\t}\n \t    }\n \n-\t  /* Update the counts and frequency of both the original block\n+\t  /* Update the counts of both the original block\n \t     and path edge, and the duplicates.  The path duplicate's\n-\t     incoming count and frequency are the totals for all edges\n+\t     incoming count are the totals for all edges\n \t     incoming to this jump threading path computed earlier.\n \t     And we know that the duplicated path will have path_out_count\n \t     flowing out of it (i.e. along the duplicated path out of the\n \t     duplicated joiner).  */\n-\t  update_profile (epath, e2, path_in_count, path_out_count,\n-\t\t\t  path_in_freq);\n-\n-\t  /* Record the frequency flowing to the downstream duplicated\n-\t     path blocks.  */\n-\t  cur_path_freq = EDGE_FREQUENCY (e2);\n+\t  update_profile (epath, e2, path_in_count, path_out_count);\n \t}\n       else if ((*path)[i]->type == EDGE_COPY_SRC_BLOCK)\n \t{\n@@ -1184,7 +1048,7 @@ ssa_fix_duplicate_block_edges (struct re\n \t  if (count == 1)\n \t    single_succ_edge (rd->dup_blocks[1])->aux = NULL;\n \n-\t  /* Update the counts and frequency of both the original block\n+\t  /* Update the counts of both the original block\n \t     and path edge, and the duplicates.  Since we are now after\n \t     any joiner that may have existed on the path, the count\n \t     flowing along the duplicated threaded path is path_out_count.\n@@ -1194,7 +1058,7 @@ ssa_fix_duplicate_block_edges (struct re\n \t     been updated at the end of that handling to the edge frequency\n \t     along the duplicated joiner path edge.  */\n \t  update_profile (epath, EDGE_SUCC (rd->dup_blocks[count], 0),\n-\t\t\t  path_out_count, path_out_count, cur_path_freq);\n+\t\t\t  path_out_count, path_out_count);\n \t}\n       else\n \t{\n@@ -1211,8 +1075,7 @@ ssa_fix_duplicate_block_edges (struct re\n \t     thread path (path_in_freq).  If we had a joiner, it would have\n \t     been updated at the end of that handling to the edge frequency\n \t     along the duplicated joiner path edge.  */\n-\t   update_profile (epath, NULL, path_out_count, path_out_count,\n-\t\t\t   cur_path_freq);\n+\t   update_profile (epath, NULL, path_out_count, path_out_count);\n \t}\n \n       /* Increment the index into the duplicated path when we processed\n@@ -1223,11 +1086,6 @@ ssa_fix_duplicate_block_edges (struct re\n \t  count++;\n \t}\n     }\n-\n-  /* Done with all profile and frequency updates, clear counts if they\n-     were copied.  */\n-  if (do_freqs_to_counts)\n-    clear_counts_path (rd);\n }\n \n /* Hash table traversal callback routine to create duplicate blocks.  */\n@@ -2137,7 +1995,6 @@ duplicate_thread_path (edge entry, edge\n   struct loop *loop = entry->dest->loop_father;\n   edge exit_copy;\n   edge redirected;\n-  int curr_freq;\n   profile_count curr_count;\n \n   if (!can_copy_bbs_p (region, n_region))\n@@ -2170,7 +2027,6 @@ duplicate_thread_path (edge entry, edge\n      the jump-thread path in order.  */\n \n   curr_count = entry->count ();\n-  curr_freq = EDGE_FREQUENCY (entry);\n \n   for (i = 0; i < n_region; i++)\n     {\n@@ -2181,10 +2037,8 @@ duplicate_thread_path (edge entry, edge\n       /* Watch inconsistent profile.  */\n       if (curr_count > region[i]->count)\n \tcurr_count = region[i]->count;\n-      if (curr_freq > region[i]->frequency)\n-\tcurr_freq = region[i]->frequency;\n       /* Scale current BB.  */\n-      if (region[i]->count > 0 && curr_count.initialized_p ())\n+      if (region[i]->count.nonzero_p () && curr_count.initialized_p ())\n \t{\n \t  /* In the middle of the path we only scale the frequencies.\n \t     In last BB we need to update probabilities of outgoing edges\n@@ -2195,24 +2049,11 @@ duplicate_thread_path (edge entry, edge\n \t\t\t\t\t         region[i]->count);\n \t  else\n \t    update_bb_profile_for_threading (region[i],\n-\t\t\t\t\t     curr_freq, curr_count,\n+\t\t\t\t\t     curr_count,\n \t\t\t\t\t     exit);\n \t  scale_bbs_frequencies_profile_count (region_copy + i, 1, curr_count,\n \t\t\t\t\t       region_copy[i]->count);\n \t}\n-      else if (region[i]->frequency)\n-\t{\n-\t  if (i + 1 != n_region)\n-\t    scale_bbs_frequencies_int (region + i, 1,\n-\t\t\t\t       region[i]->frequency - curr_freq,\n-\t\t\t\t       region[i]->frequency);\n-\t  else\n-\t    update_bb_profile_for_threading (region[i],\n-\t\t\t\t\t     curr_freq, curr_count,\n-\t\t\t\t\t     exit);\n-\t  scale_bbs_frequencies_int (region_copy + i, 1, curr_freq,\n-\t\t\t\t     region_copy[i]->frequency);\n-\t}\n \n       if (single_succ_p (bb))\n \t{\n@@ -2221,7 +2062,6 @@ duplicate_thread_path (edge entry, edge\n \t\t      || region_copy[i + 1] == single_succ_edge (bb)->dest);\n \t  if (i + 1 != n_region)\n \t    {\n-\t      curr_freq = EDGE_FREQUENCY (single_succ_edge (bb));\n \t      curr_count = single_succ_edge (bb)->count ();\n \t    }\n \t  continue;\n@@ -2252,7 +2092,6 @@ duplicate_thread_path (edge entry, edge\n \t  }\n \telse\n \t  {\n-\t    curr_freq = EDGE_FREQUENCY (e);\n \t    curr_count = e->count ();\n \t  }\n     }\nIndex: tree-switch-conversion.c\n===================================================================\n--- tree-switch-conversion.c\t(revision 254348)\n+++ tree-switch-conversion.c\t(working copy)\n@@ -1443,10 +1443,10 @@ gen_inbound_check (gswitch *swtch, struc\n     }\n \n   /* frequencies of the new BBs */\n-  bb1->frequency = EDGE_FREQUENCY (e01);\n-  bb2->frequency = EDGE_FREQUENCY (e02);\n+  bb1->count = e01->count ();\n+  bb2->count = e02->count ();\n   if (!info->default_case_nonstandard)\n-    bbf->frequency = EDGE_FREQUENCY (e1f) + EDGE_FREQUENCY (e2f);\n+    bbf->count = e1f->count () + e2f->count ();\n \n   /* Tidy blocks that have become unreachable.  */\n   prune_bbs (bbd, info->final_bb,\nIndex: tree-tailcall.c\n===================================================================\n--- tree-tailcall.c\t(revision 254348)\n+++ tree-tailcall.c\t(working copy)\n@@ -805,12 +805,9 @@ adjust_return_value (basic_block bb, tre\n /* Subtract COUNT and FREQUENCY from the basic block and it's\n    outgoing edge.  */\n static void\n-decrease_profile (basic_block bb, profile_count count, int frequency)\n+decrease_profile (basic_block bb, profile_count count)\n {\n   bb->count = bb->count - count;\n-  bb->frequency -= frequency;\n-  if (bb->frequency < 0)\n-    bb->frequency = 0;\n   if (!single_succ_p (bb))\n     {\n       gcc_assert (!EDGE_COUNT (bb->succs));\n@@ -892,11 +889,10 @@ eliminate_tail_call (struct tailcall *t)\n \n   /* Number of executions of function has reduced by the tailcall.  */\n   e = single_succ_edge (gsi_bb (t->call_gsi));\n-  decrease_profile (EXIT_BLOCK_PTR_FOR_FN (cfun), e->count (), EDGE_FREQUENCY (e));\n-  decrease_profile (ENTRY_BLOCK_PTR_FOR_FN (cfun), e->count (),\n-\t\t    EDGE_FREQUENCY (e));\n+  decrease_profile (EXIT_BLOCK_PTR_FOR_FN (cfun), e->count ());\n+  decrease_profile (ENTRY_BLOCK_PTR_FOR_FN (cfun), e->count ());\n   if (e->dest != EXIT_BLOCK_PTR_FOR_FN (cfun))\n-    decrease_profile (e->dest, e->count (), EDGE_FREQUENCY (e));\n+    decrease_profile (e->dest, e->count ());\n \n   /* Replace the call by a jump to the start of function.  */\n   e = redirect_edge_and_branch (single_succ_edge (gsi_bb (t->call_gsi)),\nIndex: tree-vect-loop-manip.c\n===================================================================\n--- tree-vect-loop-manip.c\t(revision 254348)\n+++ tree-vect-loop-manip.c\t(working copy)\n@@ -1843,7 +1843,6 @@ vect_do_peeling (loop_vec_info loop_vinf\n \n \t  /* Simply propagate profile info from guard_bb to guard_to which is\n \t     a merge point of control flow.  */\n-\t  guard_to->frequency = guard_bb->frequency;\n \t  guard_to->count = guard_bb->count;\n \t  /* Scale probability of epilog loop back.\n \t     FIXME: We should avoid scaling down and back up.  Profile may\nIndex: tree-vect-loop.c\n===================================================================\n--- tree-vect-loop.c\t(revision 254348)\n+++ tree-vect-loop.c\t(working copy)\n@@ -7229,20 +7229,14 @@ scale_profile_for_vect_loop (struct loop\n   gcov_type new_est_niter = niter_for_unrolled_loop (loop, vf);\n   profile_count freq_h = loop->header->count, freq_e = preheader->count ();\n \n-  /* Use frequency only if counts are zero.  */\n-  if (!(freq_h > 0) && !(freq_e > 0))\n-    {\n-      freq_h = profile_count::from_gcov_type (loop->header->frequency);\n-      freq_e = profile_count::from_gcov_type (EDGE_FREQUENCY (preheader));\n-    }\n-  if (freq_h > 0)\n+  if (freq_h.nonzero_p ())\n     {\n       profile_probability p;\n \n       /* Avoid dropping loop body profile counter to 0 because of zero count\n \t in loop's preheader.  */\n-      if (!(freq_e > profile_count::from_gcov_type (1)))\n-       freq_e = profile_count::from_gcov_type (1);\n+      if (!(freq_e == profile_count::zero ()))\n+        freq_e = freq_e.force_nonzero ();\n       p = freq_e.apply_scale (new_est_niter + 1, 1).probability_in (freq_h);\n       scale_loop_frequencies (loop, p);\n     }\n@@ -7781,7 +7775,7 @@ optimize_mask_stores (struct loop *loop)\n       efalse = make_edge (bb, store_bb, EDGE_FALSE_VALUE);\n       /* Put STORE_BB to likely part.  */\n       efalse->probability = profile_probability::unlikely ();\n-      store_bb->frequency = PROB_ALWAYS - EDGE_FREQUENCY (efalse);\n+      store_bb->count = efalse->count ();\n       make_single_succ_edge (store_bb, join_bb, EDGE_FALLTHRU);\n       if (dom_info_available_p (CDI_DOMINATORS))\n \tset_immediate_dominator (CDI_DOMINATORS, store_bb, bb);\nIndex: tree-vect-stmts.c\n===================================================================\n--- tree-vect-stmts.c\t(revision 254348)\n+++ tree-vect-stmts.c\t(working copy)\n@@ -3221,7 +3221,7 @@ vectorizable_simd_clone_call (gimple *st\n   vec<tree> vargs = vNULL;\n   size_t i, nargs;\n   tree lhs, rtype, ratype;\n-  vec<constructor_elt, va_gc> *ret_ctor_elts;\n+  vec<constructor_elt, va_gc> *ret_ctor_elts = NULL;\n \n   /* Is STMT a vectorizable call?   */\n   if (!is_gimple_call (stmt))\nIndex: ubsan.c\n===================================================================\n--- ubsan.c\t(revision 254348)\n+++ ubsan.c\t(working copy)\n@@ -804,6 +804,7 @@ ubsan_expand_null_ifn (gimple_stmt_itera\n      this edge is unlikely taken, so set up the probability accordingly.  */\n   e = make_edge (cond_bb, then_bb, EDGE_TRUE_VALUE);\n   e->probability = profile_probability::very_unlikely ();\n+  then_bb->count = e->count ();\n \n   /* Connect 'then block' with the 'else block'.  This is needed\n      as the ubsan routines we call in the 'then block' are not noreturn.\n@@ -1085,6 +1086,7 @@ ubsan_expand_ptr_ifn (gimple_stmt_iterat\n \t accordingly.  */\n       e = make_edge (cond_bb, then_bb, EDGE_TRUE_VALUE);\n       e->probability = profile_probability::very_unlikely ();\n+      then_bb->count = e->count ();\n     }\n   else\n     {\n@@ -1098,12 +1100,14 @@ ubsan_expand_ptr_ifn (gimple_stmt_iterat\n \n       e = make_edge (cond_neg_bb, then_bb, EDGE_TRUE_VALUE);\n       e->probability = profile_probability::very_unlikely ();\n+      then_bb->count = e->count ();\n \n       cond_pos_bb = create_empty_bb (cond_bb);\n       add_bb_to_loop (cond_pos_bb, cond_bb->loop_father);\n \n       e = make_edge (cond_bb, cond_pos_bb, EDGE_TRUE_VALUE);\n       e->probability = profile_probability::even ();\n+      cond_pos_bb->count = e->count ();\n \n       e = make_edge (cond_pos_bb, then_bb, EDGE_TRUE_VALUE);\n       e->probability = profile_probability::very_unlikely ();\nIndex: value-prof.c\n===================================================================\n--- value-prof.c\t(revision 254348)\n+++ value-prof.c\t(working copy)\n@@ -583,7 +583,7 @@ static bool\n check_counter (gimple *stmt, const char * name,\n \t       gcov_type *count, gcov_type *all, profile_count bb_count_d)\n {\n-  gcov_type bb_count = bb_count_d.to_gcov_type ();\n+  gcov_type bb_count = bb_count_d.ipa ().to_gcov_type ();\n   if (*all != bb_count || *count > *all)\n     {\n       location_t locus;\n@@ -1299,7 +1299,7 @@ check_ic_target (gcall *call_stmt, struc\n \n gcall *\n gimple_ic (gcall *icall_stmt, struct cgraph_node *direct_call,\n-\t   profile_probability prob, profile_count count, profile_count all)\n+\t   profile_probability prob)\n {\n   gcall *dcall_stmt;\n   gassign *load_stmt;\n@@ -1354,11 +1354,11 @@ gimple_ic (gcall *icall_stmt, struct cgr\n   /* Edge e_cd connects cond_bb to dcall_bb, etc; note the first letters. */\n   e_cd = split_block (cond_bb, cond_stmt);\n   dcall_bb = e_cd->dest;\n-  dcall_bb->count = count;\n+  dcall_bb->count = cond_bb->count.apply_probability (prob);\n \n   e_di = split_block (dcall_bb, dcall_stmt);\n   icall_bb = e_di->dest;\n-  icall_bb->count = all - count;\n+  icall_bb->count = cond_bb->count - dcall_bb->count;\n \n   /* Do not disturb existing EH edges from the indirect call.  */\n   if (!stmt_ends_bb_p (icall_stmt))\n@@ -1376,7 +1376,7 @@ gimple_ic (gcall *icall_stmt, struct cgr\n   if (e_ij != NULL)\n     {\n       join_bb = e_ij->dest;\n-      join_bb->count = all;\n+      join_bb->count = cond_bb->count;\n     }\n \n   e_cd->flags = (e_cd->flags & ~EDGE_FALLTHRU) | EDGE_TRUE_VALUE;\n@@ -1518,7 +1518,7 @@ gimple_ic_transform (gimple_stmt_iterato\n   count = histogram->hvalue.counters [1];\n   all = histogram->hvalue.counters [2];\n \n-  bb_all = gimple_bb (stmt)->count.to_gcov_type ();\n+  bb_all = gimple_bb (stmt)->count.ipa ().to_gcov_type ();\n   /* The order of CHECK_COUNTER calls is important -\n      since check_counter can correct the third parameter\n      and we want to make count <= all <= bb_all. */\nIndex: value-prof.h\n===================================================================\n--- value-prof.h\t(revision 254348)\n+++ value-prof.h\t(working copy)\n@@ -90,8 +90,7 @@ void gimple_move_stmt_histograms (struct\n void verify_histograms (void);\n void free_histograms (function *);\n void stringop_block_profile (gimple *, unsigned int *, HOST_WIDE_INT *);\n-gcall *gimple_ic (gcall *, struct cgraph_node *, profile_probability,\n-\t\t  profile_count, profile_count);\n+gcall *gimple_ic (gcall *, struct cgraph_node *, profile_probability);\n bool check_ic_target (gcall *, struct cgraph_node *);","headers":{"Return-Path":"<gcc-patches-return-465867-incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list gcc-patches@gcc.gnu.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=gcc-patches-return-465867-incoming=patchwork.ozlabs.org@gcc.gnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tunprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org\n\theader.b=\"Llo4lopK\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3yT5xV5Jtsz9sNw\n\tfor <incoming@patchwork.ozlabs.org>;\n\tSat,  4 Nov 2017 02:49:50 +1100 (AEDT)","(qmail 87925 invoked by alias); 3 Nov 2017 15:49:10 -0000","(qmail 87462 invoked by uid 89); 3 Nov 2017 15:49:09 -0000","from nikam.ms.mff.cuni.cz (HELO nikam.ms.mff.cuni.cz)\n\t(195.113.20.16) by sourceware.org\n\t(qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP;\n\tFri, 03 Nov 2017 15:48:49 +0000","by nikam.ms.mff.cuni.cz (Postfix, from userid 16202)\tid\n\t0EDA3549841; Fri,  3 Nov 2017 16:48:45 +0100 (CET)"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:date\n\t:from:to:cc:subject:message-id:references:mime-version\n\t:content-type:in-reply-to; q=dns; s=default; b=RFtUTTLvIGWZJEm9v\n\tsgKhRPxZZPysfUYj+AQxrwZHyqlVRrAqeZBj4m7mzsNHwSjx/+kJgUG2eWK4mX2A\n\tNJGrYcF2SaUkHL2MTXoY4Z3IDWxanafUhjqq2/c0cKRqu/mGE+HfOTikgj/T6v+4\n\tgpz9ZZYHKMgFVl6qBgT7Orx0BI=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:date\n\t:from:to:cc:subject:message-id:references:mime-version\n\t:content-type:in-reply-to; s=default; bh=Zj1e3uV6m9Z746fKpogUY0E\n\tR/JQ=; b=Llo4lopK0QONYsyDHL76XBqy4RIjqbPlOZRUdkasnMWnELfq0dTRToy\n\toOwRF31qfMQTDqx6PYIohB+II6kO9jXiXVXtbfdAUWbI+QQRDKE7TETFn2AHrx9W\n\tyXc9myqczhPQQZ8a+u7Ot9SABW+jdQSBPlP19LXZYicMvcBA65Kk=","Mailing-List":"contact gcc-patches-help@gcc.gnu.org; run by ezmlm","Precedence":"bulk","List-Id":"<gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<mailto:gcc-patches-unsubscribe-incoming=patchwork.ozlabs.org@gcc.gnu.org>","List-Archive":"<http://gcc.gnu.org/ml/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-help@gcc.gnu.org>","Sender":"gcc-patches-owner@gcc.gnu.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-14.1 required=5.0 tests=AWL, BAYES_00,\n\tGIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS,\n\tKAM_LAZY_DOMAIN_SECURITY,\n\tRP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=","X-HELO":"nikam.ms.mff.cuni.cz","Date":"Fri, 3 Nov 2017 16:48:45 +0100","From":"Jan Hubicka <hubicka@ucw.cz>","To":"Martin =?iso-8859-2?q?Li=B9ka?= <mliska@suse.cz>","Cc":"gcc-patches@gcc.gnu.org","Subject":"Re: Drop frequencies from basic blocks","Message-ID":"<20171103154845.GA3108@kam.mff.cuni.cz>","References":"<20171102153225.GA53964@kam.mff.cuni.cz>\n\t<da7c915d-aa07-76d3-d79d-9e90419bbd79@suse.cz>\n\t<20171102190652.GB31407@kam.mff.cuni.cz>\n\t<89e2ec2f-12b7-af91-634e-82cc74f2183f@suse.cz>\n\t<7ab9b7b2-1c71-3700-82be-0f1de795ec51@suse.cz>\n\t<8b1ca935-223d-29b7-aecf-d4850efaf7a7@suse.cz>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<8b1ca935-223d-29b7-aecf-d4850efaf7a7@suse.cz>","User-Agent":"Mutt/1.5.23 (2014-03-12)"}},{"id":1799091,"web_url":"http://patchwork.ozlabs.org/comment/1799091/","msgid":"<87zi82l1gv.fsf@linux-m68k.org>","list_archive_url":null,"date":"2017-11-04T11:36:48","subject":"Re: Drop frequencies from basic blocks","submitter":{"id":2170,"url":"http://patchwork.ozlabs.org/api/people/2170/","name":"Andreas Schwab","email":"schwab@linux-m68k.org"},"content":"This breaks gfortran.dg/bounds_check_15.f90 with -O3 -funroll-loops\n-fbounds-check on ia64:\n\nError: qsort comparator non-negative on sorted output: 1\nduring RTL pass: mach\n../gcc/testsuite/gfortran.dg/bounds_check_15.f90:32:0: internal compiler error: qsort checking failed\n0x40000000001cc1ff qsort_chk_error\n        ../../gcc/vec.c:222\n0x400000000223130f qsort_chk(void*, unsigned long, unsigned long, int (*)(void const*, void const*))\n        ../../gcc/vec.c:274\n0x400000000114ba4f vec<_expr*, va_heap, vl_embed>::qsort(int (*)(void const*, void const*))\n        ../../gcc/vec.h:973\n0x400000000114ba4f vec<_expr*, va_heap, vl_ptr>::qsort(int (*)(void const*, void const*))\n        ../../gcc/vec.h:1735\n0x400000000114ba4f fill_vec_av_set\n        ../../gcc/sel-sched.c:3725\n0x40000000011517df fill_ready_list\n        ../../gcc/sel-sched.c:4022\n0x40000000011517df find_best_expr\n        ../../gcc/sel-sched.c:4382\n0x40000000011517df fill_insns\n        ../../gcc/sel-sched.c:5539\n0x40000000011517df schedule_on_fences\n        ../../gcc/sel-sched.c:7356\n0x40000000011517df sel_sched_region_2\n        ../../gcc/sel-sched.c:7494\n0x4000000001158d0f sel_sched_region_1\n        ../../gcc/sel-sched.c:7536\n0x4000000001158d0f sel_sched_region(int)\n        ../../gcc/sel-sched.c:7637\n0x400000000115a0af run_selective_scheduling()\n        ../../gcc/sel-sched.c:7713\n0x4000000001a50a5f ia64_reorg\n        ../../gcc/config/ia64/ia64.c:9854\n0x40000000010c2a8f execute\n        ../../gcc/reorg.c:3947\n\nAndreas.","headers":{"Return-Path":"<gcc-patches-return-465936-incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list gcc-patches@gcc.gnu.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=gcc-patches-return-465936-incoming=patchwork.ozlabs.org@gcc.gnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tunprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org\n\theader.b=\"iX3fkyAd\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3yTcHN1s59z9sNd\n\tfor <incoming@patchwork.ozlabs.org>;\n\tSat,  4 Nov 2017 22:37:02 +1100 (AEDT)","(qmail 96659 invoked by alias); 4 Nov 2017 11:36:55 -0000","(qmail 96648 invoked by uid 89); 4 Nov 2017 11:36:55 -0000","from mail-out.m-online.net (HELO mail-out.m-online.net)\n\t(212.18.0.9) by sourceware.org\n\t(qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP;\n\tSat, 04 Nov 2017 11:36:53 +0000","from frontend01.mail.m-online.net (unknown [192.168.8.182])\tby\n\tmail-out.m-online.net (Postfix) with ESMTP id\n\t3yTcH71YlBz1qsDL; Sat,  4 Nov 2017 12:36:50 +0100 (CET)","from localhost (dynscan1.mnet-online.de [192.168.6.70])\tby\n\tmail.m-online.net (Postfix) with ESMTP id 3yTcH604d6z1qql0;\n\tSat,  4 Nov 2017 12:36:49 +0100 (CET)","from mail.mnet-online.de ([192.168.8.182])\tby localhost\n\t(dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new,\n\tport 10024)\twith ESMTP id jQojMsueYg55;\n\tSat,  4 Nov 2017 12:36:49 +0100 (CET)","from localhost (ppp-188-174-146-58.dynamic.mnet-online.de\n\t[188.174.146.58])\t(using TLSv1.2 with cipher\n\tECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\t(No client\n\tcertificate requested)\tby mail.mnet-online.de (Postfix) with\n\tESMTPSA; Sat,  4 Nov 2017 12:36:49 +0100 (CET)","by localhost (Postfix, from userid 1000)\tid 523CD2C110B;\n\tSat,  4 Nov 2017 12:36:48 +0100 (CET)"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:from\n\t:to:cc:subject:references:date:in-reply-to:message-id\n\t:mime-version:content-type; q=dns; s=default; b=EHYKyUy4SGVGy8sA\n\trVXOurSfXva+Ez4pgOmdWAB8GoHVONLDzj830WSjA23FVOxpW6xeGJ0x/IghgjQH\n\ttsX/ybU0dNsKv2ux+LBswFa/r2PJq2u2NgdEmlUmOrB4W7ElWqgWMb9f7BJmMo7G\n\tJUslNyhcdG2ayDKTAJfv/3bFzBg=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:from\n\t:to:cc:subject:references:date:in-reply-to:message-id\n\t:mime-version:content-type; s=default; bh=0hQs7ZotEHeFkePlfzIfKo\n\taHFxk=; b=iX3fkyAdVBAV3IYK8+wMdKQri/moy6MTLE2y8KHJpPdT/Mxt418Hmh\n\t+sSae7W8nCfI3VMlphzlDKd8/+q/HX1rEguFCSb1ddJ/z0JjWZFAt2W1+xVBVBD1\n\tUQC4W1H3ee3aK2Edq1L4TZks4y3MNH5kBvFJ9U+wdIaHO90b1Mudk=","Mailing-List":"contact gcc-patches-help@gcc.gnu.org; run by ezmlm","Precedence":"bulk","List-Id":"<gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<mailto:gcc-patches-unsubscribe-incoming=patchwork.ozlabs.org@gcc.gnu.org>","List-Archive":"<http://gcc.gnu.org/ml/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-help@gcc.gnu.org>","Sender":"gcc-patches-owner@gcc.gnu.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-1.6 required=5.0 tests=BAYES_00,\n\tKAM_LAZY_DOMAIN_SECURITY,\n\tRCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 spammy=gpg,\n\tHX-HELO:sk:mail-ou","X-HELO":"mail-out.m-online.net","X-Auth-Info":"8kIol7B1glQhb/EL2shj88DxOig6cVwEQmaj6Sl2f/DiFP/yr6w8YXLPv7j+b20Y","From":"Andreas Schwab <schwab@linux-m68k.org>","To":"Jan Hubicka <hubicka@ucw.cz>","Cc":"Martin =?utf-8?b?TGnFoWth?= <mliska@suse.cz>,  gcc-patches@gcc.gnu.org","Subject":"Re: Drop frequencies from basic blocks","References":"<20171102153225.GA53964@kam.mff.cuni.cz>\t<da7c915d-aa07-76d3-d79d-9e90419bbd79@suse.cz>\t<20171102190652.GB31407@kam.mff.cuni.cz>\t<89e2ec2f-12b7-af91-634e-82cc74f2183f@suse.cz>\t<7ab9b7b2-1c71-3700-82be-0f1de795ec51@suse.cz>\t<8b1ca935-223d-29b7-aecf-d4850efaf7a7@suse.cz>\t<20171103154845.GA3108@kam.mff.cuni.cz>","X-Yow":"I'll take ROAST BEEF if you're out of LAMB!!","Date":"Sat, 04 Nov 2017 12:36:48 +0100","In-Reply-To":"<20171103154845.GA3108@kam.mff.cuni.cz> (Jan Hubicka's message\n\tof\t\"Fri, 3 Nov 2017 16:48:45 +0100\")","Message-ID":"<87zi82l1gv.fsf@linux-m68k.org>","User-Agent":"Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux)","MIME-Version":"1.0","Content-Type":"text/plain"}},{"id":1799235,"web_url":"http://patchwork.ozlabs.org/comment/1799235/","msgid":"<20171105095313.GA237@x4>","list_archive_url":null,"date":"2017-11-05T09:53:13","subject":"Re: Drop frequencies from basic blocks","submitter":{"id":1014,"url":"http://patchwork.ozlabs.org/api/people/1014/","name":"Markus Trippelsdorf","email":"markus@trippelsdorf.de"},"content":"On 2017.11.03 at 16:48 +0100, Jan Hubicka wrote:\n> this is updated patch which I have comitted after profiledbootstrapping x86-64\n\nUnfortunately, compiling tramp3d-v4.cpp is 6-7% slower after this patch.\nThis happens with an LTO/PGO bootstrapped gcc using --enable-checking=release.\n\nOn X86_64:\n\nBefore:\n Performance counter stats for 'g++ -w -Ofast tramp3d-v4.cpp' (4 runs):\n\n      25040.360183      task-clock (msec)         #    1.000 CPUs utilized            ( +-  0.25% )\n               650      context-switches          #    0.026 K/sec                    ( +- 76.87% )\n                 2      cpu-migrations            #    0.000 K/sec                    ( +- 28.87% )\n           268,141      page-faults               #    0.011 M/sec                    ( +-  0.01% )\n    80,210,085,167      cycles                    #    3.203 GHz                      ( +-  0.26% )  (66.67%)\n    21,061,765,388      stalled-cycles-frontend   #   26.26% frontend cycles idle     ( +-  0.37% )  (66.67%)\n    24,699,976,439      stalled-cycles-backend    #   30.79% backend cycles idle      ( +-  0.57% )  (66.68%)\n    69,167,169,243      instructions              #    0.86  insn per cycle\n                                                  #    0.36  stalled cycles per insn  ( +-  0.05% )  (66.68%)\n    15,230,229,662      branches                  #  608.227 M/sec                    ( +-  0.06% )  (66.68%)\n       986,612,296      branch-misses             #    6.48% of all branches          ( +-  0.07% )  (66.68%)\n\n      25.046439011 seconds time elapsed                                          ( +-  0.25% )\n\nAfter:\n Performance counter stats for 'g++ -w -Ofast tramp3d-v4.cpp' (4 runs):\n\n      26710.577065      task-clock (msec)         #    1.000 CPUs utilized            ( +-  0.27% )\n               199      context-switches          #    0.007 K/sec                    ( +- 21.12% )\n                 2      cpu-migrations            #    0.000 K/sec                    ( +- 14.29% )\n           267,676      page-faults               #    0.010 M/sec                    ( +-  0.01% )\n    85,561,962,974      cycles                    #    3.203 GHz                      ( +-  0.26% )  (66.66%)\n    19,581,827,643      stalled-cycles-frontend   #   22.89% frontend cycles idle     ( +-  0.30% )  (66.66%)\n    26,056,535,726      stalled-cycles-backend    #   30.45% backend cycles idle      ( +-  0.65% )  (66.68%)\n    77,222,167,966      instructions              #    0.90  insn per cycle\n                                                  #    0.34  stalled cycles per insn  ( +-  0.04% )  (66.68%)\n    17,471,652,187      branches                  #  654.110 M/sec                    ( +-  0.05% )  (66.69%)\n     1,082,141,013      branch-misses             #    6.19% of all branches          ( +-  0.04% )  (66.69%)\n\n      26.713823720 seconds time elapsed                                          ( +-  0.27% )\n\n==================================================================================================================\n\nOn PPC64le:\n\nBefore:\n Performance counter stats for 'g++ -w -Ofast tramp3d-v4.cpp' (4 runs):\n\n      24281.894597      task-clock (msec)         #    0.989 CPUs utilized            ( +-  1.85% )\n               166      context-switches          #    0.007 K/sec                    ( +-  2.46% )\n                 5      cpu-migrations            #    0.000 K/sec                    ( +- 18.03% )\n            52,908      page-faults               #    0.002 M/sec                    ( +- 11.61% )\n    84,939,354,171      cycles                    #    3.498 GHz                      ( +-  1.82% )  (66.71%)\n     4,680,693,343      stalled-cycles-frontend   #    5.51% frontend cycles idle     ( +-  8.75% )  (49.98%)\n    46,697,372,688      stalled-cycles-backend    #   54.98% backend cycles idle      ( +-  2.06% )  (50.05%)\n    94,990,460,746      instructions              #    1.12  insn per cycle\n                                                  #    0.49  stalled cycles per insn  ( +-  0.10% )  (66.72%)\n    19,562,344,992      branches                  #  805.635 M/sec                    ( +-  0.07% )  (50.06%)\n       807,701,262      branch-misses             #    4.13% of all branches          ( +-  0.45% )  (50.05%)\n\n      24.550558669 seconds time elapsed                                          ( +-  1.83% )\n\nAfter:\n Performance counter stats for 'g++ -w -Ofast tramp3d-v4.cpp' (4 runs):\n\n      26383.472582      task-clock (msec)         #    0.995 CPUs utilized            ( +-  1.83% )\n               202      context-switches          #    0.008 K/sec                    ( +-  1.68% )\n                 5      cpu-migrations            #    0.000 K/sec                    ( +- 14.29% )\n            53,114      page-faults               #    0.002 M/sec                    ( +- 17.86% )\n    92,099,443,793      cycles                    #    3.491 GHz                      ( +-  0.96% )  (66.68%)\n     3,706,147,243      stalled-cycles-frontend   #    4.02% frontend cycles idle     ( +-  8.31% )  (50.00%)\n    51,376,299,749      stalled-cycles-backend    #   55.78% backend cycles idle      ( +-  0.83% )  (50.05%)\n   105,872,124,981      instructions              #    1.15  insn per cycle\n                                                  #    0.49  stalled cycles per insn  ( +-  0.05% )  (66.74%)\n    22,348,839,937      branches                  #  847.077 M/sec                    ( +-  0.16% )  (50.04%)\n       847,288,219      branch-misses             #    3.79% of all branches          ( +-  0.06% )  (50.02%)\n\n      26.511790685 seconds time elapsed                                          ( +-  1.84% )\n\n--\nMarkus","headers":{"Return-Path":"<gcc-patches-return-465954-incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list gcc-patches@gcc.gnu.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=gcc-patches-return-465954-incoming=patchwork.ozlabs.org@gcc.gnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tunprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org\n\theader.b=\"b6S+8ylX\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3yV9xZ5qsrz9t34\n\tfor <incoming@patchwork.ozlabs.org>;\n\tSun,  5 Nov 2017 20:53:28 +1100 (AEDT)","(qmail 84425 invoked by alias); 5 Nov 2017 09:53:21 -0000","(qmail 84414 invoked by uid 89); 5 Nov 2017 09:53:20 -0000","from ud10.udmedia.de (HELO mail.ud10.udmedia.de) (194.117.254.50)\n\tby sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with\n\tESMTP; Sun, 05 Nov 2017 09:53:17 +0000","(qmail 4029 invoked from network); 5 Nov 2017 10:53:13 +0100","from ip5b405f48.dynamic.kabel-deutschland.de (HELO x4)\n\t(ud10?360p3@91.64.95.72) by mail.ud10.udmedia.de with ESMTPSA\n\t(ECDHE-RSA-AES256-SHA encrypted, authenticated);\n\t5 Nov 2017 10:53:13 +0100"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:date\n\t:from:to:cc:subject:message-id:references:mime-version\n\t:content-type:in-reply-to; q=dns; s=default; b=FkcvfS2inUjVmv9Jk\n\tKhVFAS1uShBM0bqWBIwWBBOnTt6k/08/oCEluM7pTO6RLGAvooSZkocW+zRFZTqO\n\twH9LsEWvPyysopOhp9erhPzKPavWX70x7KhM0RkR9s/YNZxJYfOCGXnnMQT/ixTu\n\tA4DyVI7dYVTizZyrgiZX3ECn+w=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:date\n\t:from:to:cc:subject:message-id:references:mime-version\n\t:content-type:in-reply-to; s=default; bh=AsaN5ZtFEXUdXyGedcbtP2P\n\tT+wY=; b=b6S+8ylXcRvQWxhng4noqvvfTw7n0v2vSjNbqsOvDrPBUO2KWtdbwIC\n\tAR9hdyJ5FuLcWmYVfVk8lwH+S3Eyzu5ESbAUU1w0ap+1rhiSoxxsDHEhoxjxMBgT\n\tIrYoFYk2W/uJjwvJLXVOCZGMN7XO4msmpIoF7fWZh1SobKt6fsfM=","Mailing-List":"contact gcc-patches-help@gcc.gnu.org; run by ezmlm","Precedence":"bulk","List-Id":"<gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<mailto:gcc-patches-unsubscribe-incoming=patchwork.ozlabs.org@gcc.gnu.org>","List-Archive":"<http://gcc.gnu.org/ml/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-help@gcc.gnu.org>","Sender":"gcc-patches-owner@gcc.gnu.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-2.6 required=5.0 tests=AWL, BAYES_00,\n\tKAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW,\n\tSPF_HELO_PASS autolearn=no version=3.3.2 spammy=5000,\n\tPerformance, 036, 7687","X-HELO":"mail.ud10.udmedia.de","Date":"Sun, 5 Nov 2017 10:53:13 +0100","From":"Markus Trippelsdorf <markus@trippelsdorf.de>","To":"Jan Hubicka <hubicka@ucw.cz>","Cc":"Martin =?utf-8?b?TGnFoWth?= <mliska@suse.cz>, gcc-patches@gcc.gnu.org","Subject":"Re: Drop frequencies from basic blocks","Message-ID":"<20171105095313.GA237@x4>","References":"<20171102153225.GA53964@kam.mff.cuni.cz>\n\t<da7c915d-aa07-76d3-d79d-9e90419bbd79@suse.cz>\n\t<20171102190652.GB31407@kam.mff.cuni.cz>\n\t<89e2ec2f-12b7-af91-634e-82cc74f2183f@suse.cz>\n\t<7ab9b7b2-1c71-3700-82be-0f1de795ec51@suse.cz>\n\t<8b1ca935-223d-29b7-aecf-d4850efaf7a7@suse.cz>\n\t<20171103154845.GA3108@kam.mff.cuni.cz>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20171103154845.GA3108@kam.mff.cuni.cz>"}},{"id":1799242,"web_url":"http://patchwork.ozlabs.org/comment/1799242/","msgid":"<20171105105552.GA16632@kam.mff.cuni.cz>","list_archive_url":null,"date":"2017-11-05T10:55:52","subject":"Re: Drop frequencies from basic blocks","submitter":{"id":4327,"url":"http://patchwork.ozlabs.org/api/people/4327/","name":"Jan Hubicka","email":"hubicka@ucw.cz"},"content":"> On 2017.11.03 at 16:48 +0100, Jan Hubicka wrote:\n> > this is updated patch which I have comitted after profiledbootstrapping x86-64\n> \n> Unfortunately, compiling tramp3d-v4.cpp is 6-7% slower after this patch.\n> This happens with an LTO/PGO bootstrapped gcc using --enable-checking=release.\n\nour periodic testers has also picked up the change and there is no compile time\nregression reported for tramp3d.\nhttps://gcc.opensuse.org/gcc-old/c++bench-czerny/tramp3d/\nso I would conclude that it is regression in LTO+PGO bootstrap.  I am fixing one checking\nbug that may cause it (where we mix local and global profiles) so perhaps it will go away\nafterwards.\n\nThe patch has changed a lot of details because I had to merge FDO and non-FDO paths\neverywhere and also decide on code that seemed buggy and did not translate fluently\ninto new API.\n\nLooking at today results there are no significant perofrmance implications of this patch\non x86-64 nor Itanium but there are significant code size reductions which I am not quite\nsure where they come from\nhttps://gcc.opensuse.org/gcc-old/c++bench-czerny/\n\nMy overall plan is the following\n 1) Fix checking enabled fallout of the cfg patch\n 2) finish conversion by dropping frequencies from callgraph\n 3) audit code for bugs and profile updating insanities.\n    Situation is not bad - we have fewer insanties than GCC 7 on tramp3d -Ofast\n    build but it is worse than before conversion, so I may have dragged in some bugs\n    (again numbers are not fully comparable)\n 4) do full retunning of inliner metrics and FDO params in stage 3.\n    This stage1 we got a lot of changes that affects IPA metrics - the conversion\n    to sreals, context sensitive time estimates, new profile maintenance.\n\n    Also FDO metrics will hopefully become more realistic as we had fixed many instances\n    of dropped proifles.\n\nSo hope to get those 7% back for sure :)  I will also try to oprofile to see if I spot\nsomething obvious if today fixes will not cover this regression.\n\nHonza","headers":{"Return-Path":"<gcc-patches-return-465962-incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list gcc-patches@gcc.gnu.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=gcc-patches-return-465962-incoming=patchwork.ozlabs.org@gcc.gnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tunprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org\n\theader.b=\"HZd2g22F\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3yVCKh4xjbz9s83\n\tfor <incoming@patchwork.ozlabs.org>;\n\tSun,  5 Nov 2017 21:56:07 +1100 (AEDT)","(qmail 96280 invoked by alias); 5 Nov 2017 10:55:58 -0000","(qmail 96270 invoked by uid 89); 5 Nov 2017 10:55:58 -0000","from nikam.ms.mff.cuni.cz (HELO nikam.ms.mff.cuni.cz)\n\t(195.113.20.16) by sourceware.org\n\t(qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP;\n\tSun, 05 Nov 2017 10:55:56 +0000","by nikam.ms.mff.cuni.cz (Postfix, from userid 16202)\tid\n\tA2AB1548BA2; Sun,  5 Nov 2017 11:55:52 +0100 (CET)"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:date\n\t:from:to:cc:subject:message-id:references:mime-version\n\t:content-type:in-reply-to; q=dns; s=default; b=W+vHMkc4Yz2OLvOTC\n\ti0wR0/1dtLEHjBw/QIJE+8dh1GkA3kXZSZSsyFh5I78pLA9GpmnC57qwxW9z8hQE\n\tng9L+x/ozutR5FhHQ3hvIJ2i53xnO3M6itIwXEgBs3VU+Q9bdCjF0pZz4kdk+Yc1\n\tR8+IeSltO16h0gcy3xX9yEBrzs=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:date\n\t:from:to:cc:subject:message-id:references:mime-version\n\t:content-type:in-reply-to; s=default; bh=tZ78BVkNfnasHrJFncqwT3u\n\t668A=; b=HZd2g22FFJXjy+XBl+9r3QgVVMnhot6V5NgSMwD0lDDB1SJH/5yl4+S\n\tWpxjbW2jPhbM93fOSH7IKlmGORx3GmKeEXF3WD7ai7CxEBJBuvWhix0pZQ+RvNvE\n\tCMM/BkQ7VykRc5750IqtddMeisB/+qpGdsnaCpFqR/8xu/RbpKbY=","Mailing-List":"contact gcc-patches-help@gcc.gnu.org; run by ezmlm","Precedence":"bulk","List-Id":"<gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<mailto:gcc-patches-unsubscribe-incoming=patchwork.ozlabs.org@gcc.gnu.org>","List-Archive":"<http://gcc.gnu.org/ml/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-help@gcc.gnu.org>","Sender":"gcc-patches-owner@gcc.gnu.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-1.3 required=5.0 tests=AWL, BAYES_00,\n\tKAM_LAZY_DOMAIN_SECURITY,\n\tRP_MATCHES_RCVD autolearn=no version=3.3.2 spammy=translate,\n\trealistic, dropped, testers","X-HELO":"nikam.ms.mff.cuni.cz","Date":"Sun, 5 Nov 2017 11:55:52 +0100","From":"Jan Hubicka <hubicka@ucw.cz>","To":"Markus Trippelsdorf <markus@trippelsdorf.de>","Cc":"Martin =?iso-8859-2?q?Li=B9ka?= <mliska@suse.cz>,\tgcc-patches@gcc.gnu.org","Subject":"Re: Drop frequencies from basic blocks","Message-ID":"<20171105105552.GA16632@kam.mff.cuni.cz>","References":"<20171102153225.GA53964@kam.mff.cuni.cz>\n\t<da7c915d-aa07-76d3-d79d-9e90419bbd79@suse.cz>\n\t<20171102190652.GB31407@kam.mff.cuni.cz>\n\t<89e2ec2f-12b7-af91-634e-82cc74f2183f@suse.cz>\n\t<7ab9b7b2-1c71-3700-82be-0f1de795ec51@suse.cz>\n\t<8b1ca935-223d-29b7-aecf-d4850efaf7a7@suse.cz>\n\t<20171103154845.GA3108@kam.mff.cuni.cz> <20171105095313.GA237@x4>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20171105095313.GA237@x4>","User-Agent":"Mutt/1.5.23 (2014-03-12)"}},{"id":1799482,"web_url":"http://patchwork.ozlabs.org/comment/1799482/","msgid":"<20171106075630.GA238@x4>","list_archive_url":null,"date":"2017-11-06T07:56:30","subject":"Re: Drop frequencies from basic blocks","submitter":{"id":1014,"url":"http://patchwork.ozlabs.org/api/people/1014/","name":"Markus Trippelsdorf","email":"markus@trippelsdorf.de"},"content":"On 2017.11.05 at 11:55 +0100, Jan Hubicka wrote:\n> > On 2017.11.03 at 16:48 +0100, Jan Hubicka wrote:\n> > > this is updated patch which I have comitted after profiledbootstrapping x86-64\n> > \n> > Unfortunately, compiling tramp3d-v4.cpp is 6-7% slower after this patch.\n> > This happens with an LTO/PGO bootstrapped gcc using --enable-checking=release.\n> \n> our periodic testers has also picked up the change and there is no compile time\n> regression reported for tramp3d.\n> https://gcc.opensuse.org/gcc-old/c++bench-czerny/tramp3d/\n> so I would conclude that it is regression in LTO+PGO bootstrap.  I am fixing one checking\n> bug that may cause it (where we mix local and global profiles) so perhaps it will go away\n> afterwards.\n\nJust to confirm: pure PGO bootstrap is fine, e.g. on Ryzen:\n(LTO/PGO) 17.65 sec ( +- 0.68% )\n(PGO)     15.74 sec ( +- 0.27% )","headers":{"Return-Path":"<gcc-patches-return-465987-incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list gcc-patches@gcc.gnu.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=gcc-patches-return-465987-incoming=patchwork.ozlabs.org@gcc.gnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tunprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org\n\theader.b=\"kZ2BDtea\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3yVlJR00B5z9s82\n\tfor <incoming@patchwork.ozlabs.org>;\n\tMon,  6 Nov 2017 18:56:51 +1100 (AEDT)","(qmail 70593 invoked by alias); 6 Nov 2017 07:56:41 -0000","(qmail 70582 invoked by uid 89); 6 Nov 2017 07:56:40 -0000","from ud10.udmedia.de (HELO mail.ud10.udmedia.de) (194.117.254.50)\n\tby sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with\n\tESMTP; Mon, 06 Nov 2017 07:56:38 +0000","(qmail 6720 invoked from network); 6 Nov 2017 08:56:30 +0100","from ip5b405f48.dynamic.kabel-deutschland.de (HELO x4)\n\t(ud10?360p3@91.64.95.72) by mail.ud10.udmedia.de with ESMTPSA\n\t(ECDHE-RSA-AES256-SHA encrypted, authenticated);\n\t6 Nov 2017 08:56:30 +0100"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:date\n\t:from:to:cc:subject:message-id:references:mime-version\n\t:content-type:in-reply-to; q=dns; s=default; b=U9ACDCblzqBiTutbw\n\t4UAdlQb1d21OG9f+oLwe4WfM/Gnt23gWEqm+sgZ7CEIkCEUoE0Mwv91k2FinHtnb\n\tZL3/8NOlaKCNa7pQN0whYxXDJMdwE33ewUj2BJtnvVz/NALj4KeVv6wcu3vzXL/M\n\t0P2QbATQr2tn/RssmMt5SYRen4=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:date\n\t:from:to:cc:subject:message-id:references:mime-version\n\t:content-type:in-reply-to; s=default; bh=wS3J1izGxpis0QcXSX1NIzY\n\tcGgk=; b=kZ2BDtea7JV2d1RfZSYRzjKEaeBrnOzVvW1Ep2pnhUntNyt2VBPbCsV\n\ts6mSaxSYM9IwmcuO2eaVaYdHcf+LSr4bsy7HLsU2ol+0Rv6gyaHT9JxYET75XSK2\n\tIBOyo8A8DZ+NjMfk/NsdMnXZ1aXxDZa7jQMHTHizbzisws456r+Q=","Mailing-List":"contact gcc-patches-help@gcc.gnu.org; run by ezmlm","Precedence":"bulk","List-Id":"<gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<mailto:gcc-patches-unsubscribe-incoming=patchwork.ozlabs.org@gcc.gnu.org>","List-Archive":"<http://gcc.gnu.org/ml/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-help@gcc.gnu.org>","Sender":"gcc-patches-owner@gcc.gnu.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-3.3 required=5.0 tests=AWL, BAYES_00,\n\tRCVD_IN_DNSWL_LOW,\n\tSPF_HELO_PASS autolearn=ham version=3.3.2 spammy=068,\n\tHx-languages-length:901, our","X-HELO":"mail.ud10.udmedia.de","Date":"Mon, 6 Nov 2017 08:56:30 +0100","From":"Markus Trippelsdorf <markus@trippelsdorf.de>","To":"Jan Hubicka <hubicka@ucw.cz>","Cc":"Martin =?utf-8?b?TGnFoWth?= <mliska@suse.cz>, gcc-patches@gcc.gnu.org","Subject":"Re: Drop frequencies from basic blocks","Message-ID":"<20171106075630.GA238@x4>","References":"<20171102153225.GA53964@kam.mff.cuni.cz>\n\t<da7c915d-aa07-76d3-d79d-9e90419bbd79@suse.cz>\n\t<20171102190652.GB31407@kam.mff.cuni.cz>\n\t<89e2ec2f-12b7-af91-634e-82cc74f2183f@suse.cz>\n\t<7ab9b7b2-1c71-3700-82be-0f1de795ec51@suse.cz>\n\t<8b1ca935-223d-29b7-aecf-d4850efaf7a7@suse.cz>\n\t<20171103154845.GA3108@kam.mff.cuni.cz> <20171105095313.GA237@x4>\n\t<20171105105552.GA16632@kam.mff.cuni.cz>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20171105105552.GA16632@kam.mff.cuni.cz>"}},{"id":1800094,"web_url":"http://patchwork.ozlabs.org/comment/1800094/","msgid":"<20171106231232.GA71309@kam.mff.cuni.cz>","list_archive_url":null,"date":"2017-11-06T23:12:32","subject":"Re: Drop frequencies from basic blocks","submitter":{"id":4327,"url":"http://patchwork.ozlabs.org/api/people/4327/","name":"Jan Hubicka","email":"hubicka@ucw.cz"},"content":"> On 2017.11.05 at 11:55 +0100, Jan Hubicka wrote:\n> > > On 2017.11.03 at 16:48 +0100, Jan Hubicka wrote:\n> > > > this is updated patch which I have comitted after profiledbootstrapping x86-64\n> > > \n> > > Unfortunately, compiling tramp3d-v4.cpp is 6-7% slower after this patch.\n> > > This happens with an LTO/PGO bootstrapped gcc using --enable-checking=release.\n> > \n> > our periodic testers has also picked up the change and there is no compile time\n> > regression reported for tramp3d.\n> > https://gcc.opensuse.org/gcc-old/c++bench-czerny/tramp3d/\n> > so I would conclude that it is regression in LTO+PGO bootstrap.  I am fixing one checking\n> > bug that may cause it (where we mix local and global profiles) so perhaps it will go away\n> > afterwards.\n> \n> Just to confirm: pure PGO bootstrap is fine, e.g. on Ryzen:\n> (LTO/PGO) 17.65 sec ( +- 0.68% )\n> (PGO)     15.74 sec ( +- 0.27% )\n\nThanks.  I have comitted the patch for inlining profile update bug, so with some\nluck LTO/PGO may be fine again.   I will look for other insanities after chasing\nout the ICEs.\n\ncallgraph is currently still having frequencies which I plan to drop next. With that\nthe profile updating will become bitmore consistent over whole program.\n\nIPA profile updates will be fun with LTO though - even for gcc we link libbackend\ninto multiple binaries and thus the whole program profile is not really whole\nprogram after all.  It is bit of the common libbackend profile combined with\nfrontend profiles and thus it can easilly accumulate to false zeros.\n\nHonza\n> \n> -- \n> Markus","headers":{"Return-Path":"<gcc-patches-return-466085-incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list gcc-patches@gcc.gnu.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=gcc-patches-return-466085-incoming=patchwork.ozlabs.org@gcc.gnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tunprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org\n\theader.b=\"UqUydPU7\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3yW7dC5t9cz9sP1\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue,  7 Nov 2017 10:12:46 +1100 (AEDT)","(qmail 65956 invoked by alias); 6 Nov 2017 23:12:38 -0000","(qmail 65944 invoked by uid 89); 6 Nov 2017 23:12:37 -0000","from nikam.ms.mff.cuni.cz (HELO nikam.ms.mff.cuni.cz)\n\t(195.113.20.16) by sourceware.org\n\t(qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP;\n\tMon, 06 Nov 2017 23:12:35 +0000","by nikam.ms.mff.cuni.cz (Postfix, from userid 16202)\tid\n\tE41235493C5; Tue,  7 Nov 2017 00:12:32 +0100 (CET)"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:date\n\t:from:to:cc:subject:message-id:references:mime-version\n\t:content-type:in-reply-to; q=dns; s=default; b=XImAFDL9pNvTWX2oU\n\t+zzj6ZF+UyMEZ/u+9znlZlD37w3Kkn+zmVc49F/NxKLdgxe4kES0lZX4hZrMZpOV\n\tw+tV3MiaLVVxjQX1HZYd6s3cewq4dZoU11Zw6T6bFj7ZQHLKT0DjBcBWpw5SkuJn\n\tPcaYKCwbphe2qrkT7QvYFHFQ+U=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:date\n\t:from:to:cc:subject:message-id:references:mime-version\n\t:content-type:in-reply-to; s=default; bh=2o/WkdMIo9FGVeFombtofVA\n\tQt5w=; b=UqUydPU7DsmTJ/52n8skIWAIpSMLWa1NZPXagvXzZhnWCBIodMYrPxg\n\tc8WKXjVLkEd5ivJytwEuBpcFeaNAIW9UkcO42R4bG29d8saK5D0psgp0iJj1wYky\n\tT+6a6JERa1SpE3OXyfvB9AaE8inmhCTlsO8AVXeVKrkF54z8pv5s=","Mailing-List":"contact gcc-patches-help@gcc.gnu.org; run by ezmlm","Precedence":"bulk","List-Id":"<gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<mailto:gcc-patches-unsubscribe-incoming=patchwork.ozlabs.org@gcc.gnu.org>","List-Archive":"<http://gcc.gnu.org/ml/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-help@gcc.gnu.org>","Sender":"gcc-patches-owner@gcc.gnu.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-1.3 required=5.0 tests=AWL, BAYES_00,\n\tKAM_LAZY_DOMAIN_SECURITY,\n\tRP_MATCHES_RCVD autolearn=no version=3.3.2 spammy=HTo:U*markus,\n\tour","X-HELO":"nikam.ms.mff.cuni.cz","Date":"Tue, 7 Nov 2017 00:12:32 +0100","From":"Jan Hubicka <hubicka@ucw.cz>","To":"Markus Trippelsdorf <markus@trippelsdorf.de>","Cc":"Martin =?iso-8859-2?q?Li=B9ka?= <mliska@suse.cz>,\tgcc-patches@gcc.gnu.org","Subject":"Re: Drop frequencies from basic blocks","Message-ID":"<20171106231232.GA71309@kam.mff.cuni.cz>","References":"<20171102153225.GA53964@kam.mff.cuni.cz>\n\t<da7c915d-aa07-76d3-d79d-9e90419bbd79@suse.cz>\n\t<20171102190652.GB31407@kam.mff.cuni.cz>\n\t<89e2ec2f-12b7-af91-634e-82cc74f2183f@suse.cz>\n\t<7ab9b7b2-1c71-3700-82be-0f1de795ec51@suse.cz>\n\t<8b1ca935-223d-29b7-aecf-d4850efaf7a7@suse.cz>\n\t<20171103154845.GA3108@kam.mff.cuni.cz> <20171105095313.GA237@x4>\n\t<20171105105552.GA16632@kam.mff.cuni.cz>\n\t<20171106075630.GA238@x4>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20171106075630.GA238@x4>","User-Agent":"Mutt/1.5.23 (2014-03-12)"}},{"id":1800264,"web_url":"http://patchwork.ozlabs.org/comment/1800264/","msgid":"<20171107070231.GA236@x4>","list_archive_url":null,"date":"2017-11-07T07:02:31","subject":"Re: Drop frequencies from basic blocks","submitter":{"id":1014,"url":"http://patchwork.ozlabs.org/api/people/1014/","name":"Markus Trippelsdorf","email":"markus@trippelsdorf.de"},"content":"On 2017.11.07 at 00:12 +0100, Jan Hubicka wrote:\n> > On 2017.11.05 at 11:55 +0100, Jan Hubicka wrote:\n> > > > On 2017.11.03 at 16:48 +0100, Jan Hubicka wrote:\n> > > > > this is updated patch which I have comitted after profiledbootstrapping x86-64\n> > > >\n> > > > Unfortunately, compiling tramp3d-v4.cpp is 6-7% slower after this patch.\n> > > > This happens with an LTO/PGO bootstrapped gcc using --enable-checking=release.\n> > >\n> > > our periodic testers has also picked up the change and there is no compile time\n> > > regression reported for tramp3d.\n> > > https://gcc.opensuse.org/gcc-old/c++bench-czerny/tramp3d/\n> > > so I would conclude that it is regression in LTO+PGO bootstrap.  I am fixing one checking\n> > > bug that may cause it (where we mix local and global profiles) so perhaps it will go away\n> > > afterwards.\n> >\n> > Just to confirm: pure PGO bootstrap is fine, e.g. on Ryzen:\n> > (LTO/PGO) 17.65 sec ( +- 0.68% )\n> > (PGO)     15.74 sec ( +- 0.27% )\n>\n> Thanks.  I have comitted the patch for inlining profile update bug, so with some\n> luck LTO/PGO may be fine again.\n\nIt got worse, unfortunately:\n\nPure PGO:\n Performance counter stats for '/home/trippels/gcc_8/usr/local/bin/g++ -w -Ofast tramp3d-v4.cpp' (4 runs):\n\n      16213.529306      task-clock (msec)         #    0.999 CPUs utilized            ( +-  0.25% )\n             1,387      context-switches          #    0.086 K/sec                    ( +-  0.17% )\n                 4      cpu-migrations            #    0.000 K/sec                    ( +- 14.80% )\n           261,764      page-faults               #    0.016 M/sec                    ( +-  0.03% )\n    62,633,457,222      cycles                    #    3.863 GHz                      ( +-  0.20% )  (83.32%)\n    13,990,050,204      stalled-cycles-frontend   #   22.34% frontend cycles idle     ( +-  0.51% )  (83.33%)\n    13,189,755,888      stalled-cycles-backend    #   21.06% backend cycles idle      ( +-  0.04% )  (83.31%)\n    75,194,592,630      instructions              #    1.20  insn per cycle\n                                                  #    0.19  stalled cycles per insn  ( +-  0.03% )  (83.35%)\n    17,113,639,942      branches                  # 1055.516 M/sec                    ( +-  0.02% )  (83.38%)\n       634,471,544      branch-misses             #    3.71% of all branches          ( +-  0.07% )  (83.34%)\n\n      16.226375499 seconds time elapsed                                          ( +-  0.24% )\n\nLTO/PGO:\n Performance counter stats for '/home/trippels/gcc_8/usr/local/bin/g++ -w -Ofast tramp3d-v4.cpp' (4 runs):\n\n      18622.496264      task-clock (msec)         #    0.999 CPUs utilized            ( +-  0.35% )\n             1,592      context-switches          #    0.086 K/sec                    ( +-  0.32% )\n                 4      cpu-migrations            #    0.000 K/sec                    ( +- 14.43% )\n           261,370      page-faults               #    0.014 M/sec                    ( +-  0.12% )\n    71,849,030,564      cycles                    #    3.858 GHz                      ( +-  0.08% )  (83.34%)\n    15,987,209,604      stalled-cycles-frontend   #   22.25% frontend cycles idle     ( +-  0.47% )  (83.32%)\n    14,336,345,458      stalled-cycles-backend    #   19.95% backend cycles idle      ( +-  0.05% )  (83.33%)\n    87,674,608,740      instructions              #    1.22  insn per cycle\n                                                  #    0.18  stalled cycles per insn  ( +-  0.01% )  (83.36%)\n    20,610,950,144      branches                  # 1106.777 M/sec                    ( +-  0.01% )  (83.35%)\n       638,454,497      branch-misses             #    3.10% of all branches          ( +-  0.08% )  (83.35%)\n\n      18.644370559 seconds time elapsed                                          ( +-  0.38% )\n\n--\nMarkus","headers":{"Return-Path":"<gcc-patches-return-466096-incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list gcc-patches@gcc.gnu.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=gcc-patches-return-466096-incoming=patchwork.ozlabs.org@gcc.gnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tunprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org\n\theader.b=\"L68Gf/e0\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3yWL3x6sBnz9t3R\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue,  7 Nov 2017 18:02:58 +1100 (AEDT)","(qmail 4449 invoked by alias); 7 Nov 2017 07:02:48 -0000","(qmail 123318 invoked by uid 89); 7 Nov 2017 07:02:40 -0000","from ud10.udmedia.de (HELO mail.ud10.udmedia.de) (194.117.254.50)\n\tby sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with\n\tESMTP; Tue, 07 Nov 2017 07:02:37 +0000","(qmail 25040 invoked from network); 7 Nov 2017 08:02:31 +0100","from ip5b405f48.dynamic.kabel-deutschland.de (HELO x4)\n\t(ud10?360p3@91.64.95.72) by mail.ud10.udmedia.de with ESMTPSA\n\t(ECDHE-RSA-AES256-SHA encrypted, authenticated);\n\t7 Nov 2017 08:02:31 +0100"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:date\n\t:from:to:cc:subject:message-id:references:mime-version\n\t:content-type:in-reply-to; q=dns; s=default; b=FkRxUiEPXyB/BDEjc\n\t8M7/iiROX0lhbWMfEK5QmE3gsXZv//MUr+WB2ELr4OnAVkPnXxFMh39vebti2V79\n\tYfLyD3XMkc/54TmnDTBxvjlTRfqiA04k/7M/+H/GXzftI7ASAfL3+tD7SwaAroDy\n\tQX4+w1O958fkNGGP+mEWpACU44=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:date\n\t:from:to:cc:subject:message-id:references:mime-version\n\t:content-type:in-reply-to; s=default; bh=hvKc9WgFvYeTnRD2EoU5P5S\n\tZywA=; b=L68Gf/e0WIiWJkIBkDx9LUKpcHAj5fggptLmVcyNDu/PNQiKyYX2ARW\n\t7UoPQrB045RhNcTxgONVYvR8975CrukpJ8GE1hxSwFXtGqzHBNbtq7Warauhnr1T\n\ttq/B6tJBHB1k7trpL4jjFOJN8y8fmqc6Jqb92Df3xAEIrPTelx10=","Mailing-List":"contact gcc-patches-help@gcc.gnu.org; run by ezmlm","Precedence":"bulk","List-Id":"<gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<mailto:gcc-patches-unsubscribe-incoming=patchwork.ozlabs.org@gcc.gnu.org>","List-Archive":"<http://gcc.gnu.org/ml/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-help@gcc.gnu.org>","Sender":"gcc-patches-owner@gcc.gnu.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-3.3 required=5.0 tests=AWL, BAYES_00,\n\tRCVD_IN_DNSWL_LOW,\n\tSPF_HELO_PASS autolearn=ham version=3.3.2 spammy=0014, 0016,\n\t018, 020","X-HELO":"mail.ud10.udmedia.de","Date":"Tue, 7 Nov 2017 08:02:31 +0100","From":"Markus Trippelsdorf <markus@trippelsdorf.de>","To":"Jan Hubicka <hubicka@ucw.cz>","Cc":"Martin =?utf-8?b?TGnFoWth?= <mliska@suse.cz>, gcc-patches@gcc.gnu.org","Subject":"Re: Drop frequencies from basic blocks","Message-ID":"<20171107070231.GA236@x4>","References":"<da7c915d-aa07-76d3-d79d-9e90419bbd79@suse.cz>\n\t<20171102190652.GB31407@kam.mff.cuni.cz>\n\t<89e2ec2f-12b7-af91-634e-82cc74f2183f@suse.cz>\n\t<7ab9b7b2-1c71-3700-82be-0f1de795ec51@suse.cz>\n\t<8b1ca935-223d-29b7-aecf-d4850efaf7a7@suse.cz>\n\t<20171103154845.GA3108@kam.mff.cuni.cz> <20171105095313.GA237@x4>\n\t<20171105105552.GA16632@kam.mff.cuni.cz>\n\t<20171106075630.GA238@x4>\n\t<20171106231232.GA71309@kam.mff.cuni.cz>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20171106231232.GA71309@kam.mff.cuni.cz>"}}]