Hi,
here are few minor issues I run across while auditing the profile updating code.
The function.c changes solve some misupdates in jump threading.
tree-inline and except can be seen with -fprofile-feedback.

Bootstrapped/regtested x86_64-linux, will commit it shortly.

Honza

        * tree-inline.c (tree_function_versioning): Set counts of split 
functions.
        * function.c (dup_block_and_redirect): Update the whole path through
        epilogue.
        (convert_jumps_to_returns): Update profile after redirection.
        * cfgexpand.c (expand_gimple_tailcall): Initialize new edge.
        * except.c (dw2_build_landing_pads, sjlj_emit_dispatch_table,
        sjlj_emit_dispatch_table): Initialize profile of newly created
        basic blocks
Index: tree-inline.c
===================================================================
*** tree-inline.c       (revision 192080)
--- tree-inline.c       (working copy)
*************** tree_function_versioning (tree old_decl,
*** 5251,5256 ****
--- 5251,5258 ----
    if (new_entry)
      {
        struct cgraph_edge *e;
+       ENTRY_BLOCK_PTR->count = new_entry->count;
+       EXIT_BLOCK_PTR->count = new_entry->count;
        rebuild_frequencies ();
  
        new_version_node->count = ENTRY_BLOCK_PTR->count;
Index: function.c
===================================================================
*** function.c  (revision 192080)
--- function.c  (working copy)
*************** dup_block_and_redirect (basic_block bb,
*** 5670,5683 ****
        {
        int freq = EDGE_FREQUENCY (e);
        copy_bb->count += e->count;
!       copy_bb->frequency += EDGE_FREQUENCY (e);
!       e->dest->count -= e->count;
!       if (e->dest->count < 0)
!         e->dest->count = 0;
!       e->dest->frequency -= freq;
!       if (e->dest->frequency < 0)
!         e->dest->frequency = 0;
!       redirect_edge_and_branch_force (e, copy_bb);
        continue;
        }
      else
--- 5670,5690 ----
        {
        int freq = EDGE_FREQUENCY (e);
        copy_bb->count += e->count;
!       copy_bb->frequency += freq;
!       while (bb != EXIT_BLOCK_PTR)
!         {
!           edge se;
!           bb->count -= e->count;
!           if (bb->count < 0)
!             bb->count = 0;
!           bb->frequency -= freq;
!           if (bb->frequency < 0)
!             bb->frequency = 0;
!           se = single_succ_edge (bb);
!           se->count -= e->count;
!           bb = se->dest;
!         }
!         redirect_edge_and_branch_force (e, copy_bb);
        continue;
        }
      else
*************** convert_jumps_to_returns (basic_block la
*** 5797,5802 ****
--- 5804,5815 ----
        }
  
        /* Fix up the CFG for the successful change we just made.  */
+       e->dest->count -= e->count;
+       if (e->dest->count < 0)
+       e->dest->count = 0;
+       e->dest->frequency -= EDGE_FREQUENCY (e);
+       if (e->dest->frequency < 0)
+       e->dest->frequency = 0;
        redirect_edge_succ (e, EXIT_BLOCK_PTR);
        e->flags &= ~EDGE_CROSSING;
      }
*************** epilogue_done:
*** 6581,6587 ****
              emit_barrier_after (start);
  
              *pdest_bb = bb;
!             make_edge (bb, EXIT_BLOCK_PTR, 0);
            }
          redirect_edge_and_branch_force (e, *pdest_bb);
        }
--- 6599,6607 ----
              emit_barrier_after (start);
  
              *pdest_bb = bb;
!             se = make_edge (bb, EXIT_BLOCK_PTR, 0);
!             se->count = e->count;;
!             se->probability = REG_BR_PROB_BASE;
            }
          redirect_edge_and_branch_force (e, *pdest_bb);
        }
Index: cfgexpand.c
===================================================================
*** cfgexpand.c (revision 192080)
--- cfgexpand.c (working copy)
*************** expand_gimple_tailcall (basic_block bb,
*** 2313,2320 ****
      }
  
    e = make_edge (bb, EXIT_BLOCK_PTR, EDGE_ABNORMAL | EDGE_SIBCALL);
!   e->probability += probability;
!   e->count += count;
    BB_END (bb) = last;
    update_bb_for_insn (bb);
  
--- 2313,2320 ----
      }
  
    e = make_edge (bb, EXIT_BLOCK_PTR, EDGE_ABNORMAL | EDGE_SIBCALL);
!   e->probability = probability;
!   e->count = count;
    BB_END (bb) = last;
    update_bb_for_insn (bb);
  
Index: except.c
===================================================================
*** except.c    (revision 192080)
--- except.c    (working copy)
*************** dw2_build_landing_pads (void)
*** 988,993 ****
--- 988,995 ----
  
        bb = emit_to_new_bb_before (seq, label_rtx (lp->post_landing_pad));
        e = make_edge (bb, bb->next_bb, e_flags);
+       bb->count = bb->next_bb->count;
+       bb->frequency = bb->next_bb->frequency;
        e->count = bb->count;
        e->probability = REG_BR_PROB_BASE;
        if (current_loops)
*************** sjlj_emit_dispatch_table (rtx dispatch_l
*** 1332,1337 ****
--- 1334,1341 ----
  
        before = label_rtx (lp->post_landing_pad);
        bb = emit_to_new_bb_before (seq2, before);
+         bb->count = bb->next_bb->count;
+         bb->frequency = bb->next_bb->frequency;
        e = make_edge (bb, bb->next_bb, EDGE_FALLTHRU);
        e->count = bb->count;
        e->probability = REG_BR_PROB_BASE;
*************** sjlj_emit_dispatch_table (rtx dispatch_l
*** 1373,1378 ****
--- 1377,1384 ----
    end_sequence ();
  
    bb = emit_to_new_bb_before (seq, first_reachable_label);
+   bb->count = bb->next_bb->count;
+   bb->frequency = bb->next_bb->frequency;
    if (num_dispatch == 1)
      {
        e = make_edge (bb, bb->next_bb, EDGE_FALLTHRU);

Reply via email to