Patchwork Fix up -freorder-blocks-and-partition -fnon-call-exceptions (PR middle-end/45458)

login
register
mail settings
Submitter Jakub Jelinek
Date Sept. 1, 2010, 7:27 p.m.
Message ID <20100901192756.GQ1269@tyan-ft48-01.lab.bos.redhat.com>
Download mbox | patch
Permalink /patch/63411/
State New
Headers show

Comments

Jakub Jelinek - Sept. 1, 2010, 7:27 p.m.
Hi!

add_labels_and_missing_jumps doesn't expect to see bbs that don't end with
a call nor jump and have more than one edge, which is quite common with
-fnon-call-exceptions, where the bb ends with a possibly throwing insn
and has fallthru edge and EH edge.

Fixed by treating the throwing insns the same as calls. 
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2010-09-01  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/45458
	* bb-reorder.c (add_labels_and_missing_jumps): Treat
	bbs ending with throwing insns like blocks ending with a call.
	(fix_up_fall_thru_edges): Likewise.

	* g++.dg/tree-prof/partition2.C: New test.


	Jakub
Richard Henderson - Sept. 1, 2010, 7:37 p.m.
On 09/01/2010 12:27 PM, Jakub Jelinek wrote:
> 	PR middle-end/45458
> 	* bb-reorder.c (add_labels_and_missing_jumps): Treat
> 	bbs ending with throwing insns like blocks ending with a call.
> 	(fix_up_fall_thru_edges): Likewise.
> 
> 	* g++.dg/tree-prof/partition2.C: New test.

Ok.


r~

Patch

--- gcc/bb-reorder.c.jj	2010-07-13 00:10:16.000000000 +0200
+++ gcc/bb-reorder.c	2010-09-01 17:57:00.608377599 +0200
@@ -1299,7 +1299,9 @@  add_labels_and_missing_jumps (edge *cros
 
 	      if (src && (src != ENTRY_BLOCK_PTR))
 		{
-		  if (!JUMP_P (BB_END (src)) && !block_ends_with_call_p (src))
+		  if (!JUMP_P (BB_END (src))
+		      && !block_ends_with_call_p (src)
+		      && !can_throw_internal (BB_END (src)))
 		    /* bb just falls through.  */
 		    {
 		      /* make sure there's only one successor */
@@ -1316,9 +1318,9 @@  add_labels_and_missing_jumps (edge *cros
 		      src->il.rtl->footer = unlink_insn_chain (barrier, barrier);
 		      /* Mark edge as non-fallthru.  */
 		      crossing_edges[i]->flags &= ~EDGE_FALLTHRU;
-		    } /* end: 'if (GET_CODE ... '  */
-		} /* end: 'if (src && src->index...'  */
-	    } /* end: 'if (dest && dest->index...'  */
+		    } /* end: 'if (!JUMP_P ... '  */
+		} /* end: 'if (src && src !=...'  */
+	    } /* end: 'if (dest && dest !=...'  */
 	} /* end: 'if (crossing_edges[i]...'  */
     } /* end for loop  */
 }
@@ -1375,19 +1377,21 @@  fix_up_fall_thru_edges (void)
 	  fall_thru = succ2;
 	  cond_jump = succ1;
 	}
-      else if (!fall_thru && succ1 && block_ends_with_call_p (cur_bb))
-      {
-        edge e;
-        edge_iterator ei;
+      else if (succ1
+	       && (block_ends_with_call_p (cur_bb)
+		   || can_throw_internal (BB_END (cur_bb))))
+	{
+	  edge e;
+	  edge_iterator ei;
 
-        /* Find EDGE_CAN_FALLTHRU edge.  */
-        FOR_EACH_EDGE (e, ei, cur_bb->succs)
-          if (e->flags & EDGE_CAN_FALLTHRU)
-          {
-            fall_thru = e;
-            break;
-          }
-      }
+	  /* Find EDGE_CAN_FALLTHRU edge.  */
+	  FOR_EACH_EDGE (e, ei, cur_bb->succs)
+	    if (e->flags & EDGE_CAN_FALLTHRU)
+	      {
+		fall_thru = e;
+		break;
+	      }
+	}
 
       if (fall_thru && (fall_thru->dest != EXIT_BLOCK_PTR))
 	{
--- gcc/testsuite/g++.dg/tree-prof/partition2.C.jj	2010-09-01 18:56:55.223489198 +0200
+++ gcc/testsuite/g++.dg/tree-prof/partition2.C	2010-09-01 18:58:07.477752523 +0200
@@ -0,0 +1,15 @@ 
+// PR middle-end/45458
+// { dg-require-effective-target freorder }
+// { dg-options "-fnon-call-exceptions -freorder-blocks-and-partition" }
+
+int
+main ()
+{
+  try
+  {
+    throw 6;
+  }
+  catch (...)
+  {
+  }
+}