diff mbox series

Fix profile updatin in tree-ssa-threadupdate

Message ID 20191205101204.2obitkvozbxbtu4l@kam.mff.cuni.cz
State New
Headers show
Series Fix profile updatin in tree-ssa-threadupdate | expand

Commit Message

Jan Hubicka Dec. 5, 2019, 10:12 a.m. UTC
Hi,
this patch makes tree-ssa-threadupdate to not leave basic blocks with
undefined counts in the program.  

create_block_for_threading sets counts as follows:

  /* Zero out the profile, since the block is unreachable for now.  */
  rd->dup_blocks[count]->count = profile_count::uninitialized ();

which is usually set to correct count in update_profile. However
template_blocks are not seen by it and thus this patch calculates the
profile while redirecting edgs to it.

Bootstrapped/regtested x86_64-linux and also checked that the profile is
correct. Does it make sense?  There is no testcase since I plan to
commit sanity check that triggers several times during the testsuite and
bootstrap w/o this patch.

Honza

	* tree-ssa-threadupdate.c

Comments

Jeff Law Dec. 6, 2019, 10:11 p.m. UTC | #1
On Thu, 2019-12-05 at 11:12 +0100, Jan Hubicka wrote:
> Hi,
> this patch makes tree-ssa-threadupdate to not leave basic blocks with
> undefined counts in the program.  
> 
> create_block_for_threading sets counts as follows:
> 
>   /* Zero out the profile, since the block is unreachable for
> now.  */
>   rd->dup_blocks[count]->count = profile_count::uninitialized ();
> 
> which is usually set to correct count in update_profile. However
> template_blocks are not seen by it and thus this patch calculates the
> profile while redirecting edgs to it.
> 
> Bootstrapped/regtested x86_64-linux and also checked that the profile
> is
> correct. Does it make sense?  There is no testcase since I plan to
> commit sanity check that triggers several times during the testsuite
> and
> bootstrap w/o this patch.

I would have expected a call to update_profile even in the case of the
template block.

ISTM we would call ssa_fixup_template_block, which in turn would call
ssa_fix_duplicate_block_edges which in turn would have called
update_profile.

jeff
diff mbox series

Patch

Index: tree-ssa-threadupdate.c
===================================================================
--- tree-ssa-threadupdate.c	(revision 278959)
+++ tree-ssa-threadupdate.c	(working copy)
@@ -1286,6 +1286,10 @@  ssa_redirect_edges (struct redirection_d
 	  /* Redirect the incoming edge (possibly to the joiner block) to the
 	     appropriate duplicate block.  */
 	  e2 = redirect_edge_and_branch (e, rd->dup_blocks[0]);
+	  if (single_pred_p (rd->dup_blocks[0]))
+	    rd->dup_blocks[0]->count = e2->count ();
+	  else
+	    rd->dup_blocks[0]->count = rd->dup_blocks[0]->count + e2->count ();
 	  gcc_assert (e == e2);
 	  flush_pending_stmts (e2);
 	}