diff mbox

Enable crossjumping with bb-reorering

Message ID 20170720233805.GC7973@kam.mff.cuni.cz
State New
Headers show

Commit Message

Jan Hubicka July 20, 2017, 11:38 p.m. UTC
Hello,
Caroline disabled crossjumping with bb-reordering in initial patch implementing
this pass.  According to discussion with Rth it was only becuase she was unsure
how to prevent crossjumping to mix up crossing and non-crossing jumps. THis is
easy to do - we only need to avoid merging code across section as done by this
patch.

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

	* cfgcleanup.c (flow_find_cross_jump): Do not crossjump across
	hot/cold regions.
	(try_crossjump_to_edge): Do not punt on partitioned functions.

Comments

Kyrill Tkachov July 21, 2017, 8:21 a.m. UTC | #1
Hi Honza,

Just a couple of typo nits.

Cheers,
Kyrill

On 21/07/17 00:38, Jan Hubicka wrote:
> Hello,
> Caroline disabled crossjumping with bb-reordering in initial patch implementing
> this pass.  According to discussion with Rth it was only becuase she was unsure
> how to prevent crossjumping to mix up crossing and non-crossing jumps. THis is
> easy to do - we only need to avoid merging code across section as done by this
> patch.
>
> Bootstrapped/regtested x86_64-linux, will commit it tomorrow.
>
> 	* cfgcleanup.c (flow_find_cross_jump): Do not crossjump across
> 	hot/cold regions.
> 	(try_crossjump_to_edge): Do not punt on partitioned functions.
> Index: cfgcleanup.c
> ===================================================================
> --- cfgcleanup.c	(revision 250378)
> +++ cfgcleanup.c	(working copy)
> @@ -1435,6 +1435,13 @@ flow_find_cross_jump (basic_block bb1, b
>         if (i1 == BB_HEAD (bb1) || i2 == BB_HEAD (bb2))
>   	break;
>   
> +      /* Do not turn corssing edge to non-crossing or vice versa after

"crossing"

> +	 reload. */
> +      if (BB_PARTITION (BLOCK_FOR_INSN (i1))
> +	  != BB_PARTITION (BLOCK_FOR_INSN (i2))
> +	  && reload_completed)
> +	break;
> +
>         dir = merge_dir (dir, old_insns_match_p (0, i1, i2));
>         if (dir == dir_none || (!dir_p && dir != dir_both))
>   	break;
> @@ -1958,18 +1965,6 @@ try_crossjump_to_edge (int mode, edge e1
>   
>     newpos1 = newpos2 = NULL;
>   
> -  /* If we have partitioned hot/cold basic blocks, it is a bad idea
> -     to try this optimization.
> -
> -     Basic block partitioning may result in some jumps that appear to
> -     be optimizable (or blocks that appear to be mergeable), but which really
> -     must be left untouched (they are required to make it safely across
> -     partition boundaries).  See the comments at the top of
> -     bb-reorder.c:partition_hot_cold_basic_blocks for complete details.  */
> -
> -  if (crtl->has_bb_partition && reload_completed)
> -    return false;
> -
>     /* Search backward through forwarder blocks.  We don't need to worry
>        about multiple entry or chained forwarders, as they will be optimized
>        away.  We do this to look past the unconditional jump following a
> @@ -2003,6 +1998,11 @@ try_crossjump_to_edge (int mode, edge e1
>     if (EDGE_COUNT (src1->preds) == 0 || EDGE_COUNT (src2->preds) == 0)
>       return false;
>   
> +  /* Do not turn corssing edge to non-crossing or vice versa after reload.  */

Likewise.

> +  if (BB_PARTITION (src1) != BB_PARTITION (src2)
> +      && reload_completed)
> +    return false;
> +
>     /* Look for the common insn sequence, part the first ...  */
>     if (!outgoing_edges_match (mode, src1, src2))
>       return false;
> @@ -2024,12 +2024,10 @@ try_crossjump_to_edge (int mode, edge e1
>   
>     if (dir == dir_backward)
>       {
> -#define SWAP(T, X, Y) do { T tmp = (X); (X) = (Y); (Y) = tmp; } while (0)
> -      SWAP (basic_block, osrc1, osrc2);
> -      SWAP (basic_block, src1, src2);
> -      SWAP (edge, e1, e2);
> -      SWAP (rtx_insn *, newpos1, newpos2);
> -#undef SWAP
> +      std::swap (osrc1, osrc2);
> +      std::swap (src1, src2);
> +      std::swap (e1, e2);
> +      std::swap (newpos1, newpos2);
>       }
>   
>     /* Don't proceed with the crossjump unless we found a sufficient number
diff mbox

Patch

Index: cfgcleanup.c
===================================================================
--- cfgcleanup.c	(revision 250378)
+++ cfgcleanup.c	(working copy)
@@ -1435,6 +1435,13 @@  flow_find_cross_jump (basic_block bb1, b
       if (i1 == BB_HEAD (bb1) || i2 == BB_HEAD (bb2))
 	break;
 
+      /* Do not turn corssing edge to non-crossing or vice versa after
+	 reload. */
+      if (BB_PARTITION (BLOCK_FOR_INSN (i1))
+	  != BB_PARTITION (BLOCK_FOR_INSN (i2))
+	  && reload_completed)
+	break;
+
       dir = merge_dir (dir, old_insns_match_p (0, i1, i2));
       if (dir == dir_none || (!dir_p && dir != dir_both))
 	break;
@@ -1958,18 +1965,6 @@  try_crossjump_to_edge (int mode, edge e1
 
   newpos1 = newpos2 = NULL;
 
-  /* If we have partitioned hot/cold basic blocks, it is a bad idea
-     to try this optimization.
-
-     Basic block partitioning may result in some jumps that appear to
-     be optimizable (or blocks that appear to be mergeable), but which really
-     must be left untouched (they are required to make it safely across
-     partition boundaries).  See the comments at the top of
-     bb-reorder.c:partition_hot_cold_basic_blocks for complete details.  */
-
-  if (crtl->has_bb_partition && reload_completed)
-    return false;
-
   /* Search backward through forwarder blocks.  We don't need to worry
      about multiple entry or chained forwarders, as they will be optimized
      away.  We do this to look past the unconditional jump following a
@@ -2003,6 +1998,11 @@  try_crossjump_to_edge (int mode, edge e1
   if (EDGE_COUNT (src1->preds) == 0 || EDGE_COUNT (src2->preds) == 0)
     return false;
 
+  /* Do not turn corssing edge to non-crossing or vice versa after reload.  */
+  if (BB_PARTITION (src1) != BB_PARTITION (src2)
+      && reload_completed)
+    return false;
+
   /* Look for the common insn sequence, part the first ...  */
   if (!outgoing_edges_match (mode, src1, src2))
     return false;
@@ -2024,12 +2024,10 @@  try_crossjump_to_edge (int mode, edge e1
 
   if (dir == dir_backward)
     {
-#define SWAP(T, X, Y) do { T tmp = (X); (X) = (Y); (Y) = tmp; } while (0)
-      SWAP (basic_block, osrc1, osrc2);
-      SWAP (basic_block, src1, src2);
-      SWAP (edge, e1, e2);
-      SWAP (rtx_insn *, newpos1, newpos2);
-#undef SWAP
+      std::swap (osrc1, osrc2);
+      std::swap (src1, src2);
+      std::swap (e1, e2);
+      std::swap (newpos1, newpos2);
     }
 
   /* Don't proceed with the crossjump unless we found a sufficient number