This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[3.3 branch] Use tablejump_p in cfgcleanup.c/merge_blocks_move_successor_nojumps()
> > http://gcc.gnu.org/ml/gcc-patches/2003-07/msg00800.html
> > (Fix latent bug in cfgcleanup.c)
>
> Please rewrite this section of code to use tablejump_p.
This patch uses tablejump_p in merge_blocks_move_successor_nojumps.
For checking whether the jump table is directly after the block
I needed to know there the table is so I have added 2 more parameters
to tablejump_p as it has in mainline.
The patch still fixes an ICE when compiling the testcase in original
message using hammer branch.
Bootstrapped/regtested i686.
OK for 3.3 branch?
Josef
2003-07-20 Josef Zlomek <zlomekj@suse.cz>
* cfgcleanup.c (merge_blocks_move_successor_nojumps): Use tablejump_p.
* ifcvt.c (find_if_block): Added 2 arguments to tablejump_p.
* jump.c (tablejump_p): Added 2 arguments.
* rtl.h (tablejump_p): Likewise.
Index: cfgcleanup.c
===================================================================
RCS file: /cvs/gcc-cvs/gcc/gcc/cfgcleanup.c,v
retrieving revision 1.68.2.5
diff -c -3 -p -r1.68.2.5 cfgcleanup.c
*** cfgcleanup.c 3 Jul 2003 18:04:24 -0000 1.68.2.5
--- cfgcleanup.c 19 Jul 2003 16:52:20 -0000
*************** merge_blocks_move_successor_nojumps (a,
*** 739,763 ****
basic_block a, b;
{
rtx barrier, real_b_end;
real_b_end = b->end;
- barrier = NEXT_INSN (b->end);
! /* Recognize a jump table following block B. */
! if (barrier
! && GET_CODE (barrier) == CODE_LABEL
! && NEXT_INSN (barrier)
! && GET_CODE (NEXT_INSN (barrier)) == JUMP_INSN
! && (GET_CODE (PATTERN (NEXT_INSN (barrier))) == ADDR_VEC
! || GET_CODE (PATTERN (NEXT_INSN (barrier))) == ADDR_DIFF_VEC))
{
! /* Temporarily add the table jump insn to b, so that it will also
! be moved to the correct location. */
! b->end = NEXT_INSN (barrier);
! barrier = NEXT_INSN (b->end);
}
! /* There had better have been a barrier there. Delete it. */
if (barrier && GET_CODE (barrier) == BARRIER)
delete_insn (barrier);
--- 739,758 ----
basic_block a, b;
{
rtx barrier, real_b_end;
+ rtx label, table;
real_b_end = b->end;
! /* If there is a jump table following block B temporarily add the jump table
! to block B so that it will also be moved to the correct location. */
! if (tablejump_p (b->end, &label, &table)
! && prev_active_insn (label) == b->end)
{
! b->end = table;
}
! /* There had better have been a barrier there. Delete it. */
! barrier = NEXT_INSN (b->end);
if (barrier && GET_CODE (barrier) == BARRIER)
delete_insn (barrier);
Index: ifcvt.c
===================================================================
RCS file: /cvs/gcc-cvs/gcc/gcc/ifcvt.c,v
retrieving revision 1.105.4.8
diff -c -3 -p -r1.105.4.8 ifcvt.c
*** ifcvt.c 6 Jun 2003 17:26:45 -0000 1.105.4.8
--- ifcvt.c 19 Jul 2003 16:50:45 -0000
*************** find_if_block (ce_info)
*** 2352,2358 ****
if (then_succ != NULL_EDGE
&& (then_succ->succ_next != NULL_EDGE
|| (then_succ->flags & EDGE_COMPLEX)
! || (flow2_completed && tablejump_p (then_bb->end))))
return FALSE;
/* If the THEN block has no successors, conditional execution can still
--- 2352,2358 ----
if (then_succ != NULL_EDGE
&& (then_succ->succ_next != NULL_EDGE
|| (then_succ->flags & EDGE_COMPLEX)
! || (flow2_completed && tablejump_p (then_bb->end, NULL, NULL))))
return FALSE;
/* If the THEN block has no successors, conditional execution can still
*************** find_if_block (ce_info)
*** 2400,2406 ****
&& else_bb->pred->pred_next == NULL_EDGE
&& else_succ->succ_next == NULL_EDGE
&& ! (else_succ->flags & EDGE_COMPLEX)
! && ! (flow2_completed && tablejump_p (else_bb->end)))
join_bb = else_succ->dest;
/* Otherwise it is not an IF-THEN or IF-THEN-ELSE combination. */
--- 2400,2406 ----
&& else_bb->pred->pred_next == NULL_EDGE
&& else_succ->succ_next == NULL_EDGE
&& ! (else_succ->flags & EDGE_COMPLEX)
! && ! (flow2_completed && tablejump_p (else_bb->end, NULL, NULL)))
join_bb = else_succ->dest;
/* Otherwise it is not an IF-THEN or IF-THEN-ELSE combination. */
Index: jump.c
===================================================================
RCS file: /cvs/gcc-cvs/gcc/gcc/jump.c,v
retrieving revision 1.214.2.6
diff -c -3 -p -r1.214.2.6 jump.c
*** jump.c 29 Apr 2003 20:17:50 -0000 1.214.2.6
--- jump.c 19 Jul 2003 16:50:45 -0000
*************** simplejump_p (insn)
*** 1080,1099 ****
&& GET_CODE (SET_SRC (PATTERN (insn))) == LABEL_REF);
}
! /* Return 1 if INSN is an tablejump. */
int
! tablejump_p (insn)
rtx insn;
{
! rtx table;
! return (GET_CODE (insn) == JUMP_INSN
! && JUMP_LABEL (insn)
! && NEXT_INSN (JUMP_LABEL (insn))
! && (table = next_active_insn (JUMP_LABEL (insn)))
! && GET_CODE (table) == JUMP_INSN
! && (GET_CODE (PATTERN (table)) == ADDR_VEC
! || GET_CODE (PATTERN (table)) == ADDR_DIFF_VEC));
}
/* Return nonzero if INSN is a (possibly) conditional jump
--- 1080,1110 ----
&& GET_CODE (SET_SRC (PATTERN (insn))) == LABEL_REF);
}
! /* If INSN is a tablejump return 1 and store the label (before jump table) to
! *LABELP and the jump table to *TABLEP. LABELP and TABLEP may be NULL. */
int
! tablejump_p (insn, labelp, tablep)
rtx insn;
+ rtx *labelp;
+ rtx *tablep;
{
! rtx label, table;
!
! if (GET_CODE (insn) == JUMP_INSN
! && (label = JUMP_LABEL (insn)) != NULL_RTX
! && (table = next_active_insn (label)) != NULL_RTX
! && GET_CODE (table) == JUMP_INSN
! && (GET_CODE (PATTERN (table)) == ADDR_VEC
! || GET_CODE (PATTERN (table)) == ADDR_DIFF_VEC))
! {
! if (labelp)
! *labelp = label;
! if (tablep)
! *tablep = table;
! return 1;
! }
! return 0;
}
/* Return nonzero if INSN is a (possibly) conditional jump
Index: rtl.h
===================================================================
RCS file: /cvs/gcc-cvs/gcc/gcc/rtl.h,v
retrieving revision 1.375.2.6
diff -c -3 -p -r1.375.2.6 rtl.h
*** rtl.h 2 May 2003 01:21:07 -0000 1.375.2.6
--- rtl.h 19 Jul 2003 16:50:45 -0000
*************** extern int safe_to_remove_jump_p PARAMS
*** 1942,1948 ****
extern rtx pc_set PARAMS ((rtx));
extern rtx condjump_label PARAMS ((rtx));
extern int simplejump_p PARAMS ((rtx));
! extern int tablejump_p PARAMS ((rtx));
extern int returnjump_p PARAMS ((rtx));
extern int onlyjump_p PARAMS ((rtx));
extern int only_sets_cc0_p PARAMS ((rtx));
--- 1942,1948 ----
extern rtx pc_set PARAMS ((rtx));
extern rtx condjump_label PARAMS ((rtx));
extern int simplejump_p PARAMS ((rtx));
! extern int tablejump_p PARAMS ((rtx, rtx *, rtx *));
extern int returnjump_p PARAMS ((rtx));
extern int onlyjump_p PARAMS ((rtx));
extern int only_sets_cc0_p PARAMS ((rtx));