This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH: Check all insns in fallthru to see if label is mentioned


> > On Wed, Oct 03, 2001 at 03:08:12PM -0400, John David Anglin wrote:
> > > 	* cfgcleanup.c (label_mentioned_p): New function.
> > > 	(try_optimize_cfg): Use it.
> > 
> 
> Rather than search, this check ought to be

I reworked your comments into a patch for cfgcleanup.c.  The only change
is the addition of `static' to the declaration of label_is_jump_target_p.
I have tested with a complete bootstrap and check under hppa2.0w-hp-hpux11.11.
There might be two regressions:

FAIL: gcc.c-torture/execute/strct-pack-1.c execution,  -O2
FAIL: gcc.c-torture/execute/strct-pack-1.c execution,  -Os

These started failing in execution at some point after Dec. 1.  It will
be a few days before I can examine these in more detail.

Dave
-- 
J. David Anglin                                  dave.anglin@nrc.ca
National Research Council of Canada              (613) 990-0752 (FAX: 952-6605)

2001-12-08  Richard Henderson  <rth@redhat.com>

	* cfgcleanup.c (label_is_jump_target_p): New function.
	(try_optimize_cfg): Use label_is_jump_target_p to check if label is
	target of a JUMP_INSN from the preceding block.

--- cfgcleanup.c.orig	Thu Nov 15 14:55:33 2001
+++ cfgcleanup.c	Thu Dec  6 11:06:42 2001
@@ -69,6 +69,7 @@
 						 rtx *, rtx *));
 
 static bool delete_unreachable_blocks	PARAMS ((void));
+static bool label_is_jump_target_p	PARAMS ((rtx, rtx));
 static bool tail_recursion_label_p	PARAMS ((rtx));
 static void merge_blocks_move_predecessor_nojumps PARAMS ((basic_block,
 							  basic_block));
@@ -291,6 +292,38 @@
   return changed;
 }
 
+/* Return true if LABEL is a target of JUMP_INSN.  This applies only
+   to non-complex jumps.  That is, direct unconditional, conditional,
+   and tablejumps, but not computed jumps or returns.  It also does
+   not apply to the fallthru case of a conditional jump.  */
+
+static bool
+label_is_jump_target_p (label, jump_insn)
+     rtx label, jump_insn;
+{
+  rtx tmp = JUMP_LABEL (jump_insn);
+
+  if (label == tmp)
+    return true;
+
+  if (tmp != NULL_RTX
+      && (tmp = NEXT_INSN (tmp)) != NULL_RTX
+      && GET_CODE (tmp) == JUMP_INSN
+      && (tmp = PATTERN (tmp),
+	  GET_CODE (tmp) == ADDR_VEC
+	  || GET_CODE (tmp) == ADDR_DIFF_VEC))
+    {
+      rtvec vec = XVEC (tmp, GET_CODE (tmp) == ADDR_DIFF_VEC);
+      int i, veclen = GET_NUM_ELEM (vec);
+
+      for (i = 0; i < veclen; ++i)
+	if (XEXP (RTVEC_ELT (vec, i), 0) == label)
+	  return true;
+    }
+
+  return false;
+}
+
 /* Return true if LABEL is used for tail recursion.  */
 
 static bool
@@ -1162,10 +1195,14 @@
 	      && GET_CODE (b->head) == CODE_LABEL
 	      && (!(mode & CLEANUP_PRE_SIBCALL)
 		  || !tail_recursion_label_p (b->head))
-	      /* If previous block ends with condjump jumping to next BB,
-	         we can't delete the label.  */
+	      /* If the previous block ends with a branch to this block,
+		 we can't delete the label.  Normally this is a condjump
+		 that is yet to be simplified, but if CASE_DROPS_THRU,
+		 this can be a tablejump with some element going to the
+		 same place as the default (fallthru).  */
 	      && (b->pred->src == ENTRY_BLOCK_PTR
-		  || !reg_mentioned_p (b->head, b->pred->src->end)))
+		  || GET_CODE (b->pred->src->end) != JUMP_INSN
+		  || ! label_is_jump_target_p (b->head, b->pred->src->end)))
 	    {
 	      rtx label = b->head;
 	      b->head = NEXT_INSN (b->head);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]