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]

try_redirect_by_replacing_jump fix


Hi,
number of fixes to try_redirect_by_replacing_jump.  Some of them stolen
from tidy_fallthru_edge I am shooting to replace by this function.
It is amazing how dificult it is write such simple function.

Fixes the C i386 regression; bootstrapped/regtested i686
OK to re-install the reverted patch assuming that the regtesting will
still suceed (it does in my slightly outdated patch)?

Honza

Fri Jul  6 15:29:43 CEST 2001  Jan Hubicka  <jh@suse.cz>
	* flow.c (try_redirect_by_replacing_jump): Do not remove
	jumps with side effects, unlink chain on fallthru edge;
	set block for new jump instruction; avoid basic block to
	over by line number note.

*** flow.c.new	Mon Jul  2 13:20:22 2001
--- flow.c	Fri Jul  6 15:19:30 2001
*************** try_redirect_by_replacing_jump (e, targe
*** 1643,1655 ****
    edge tmp;
    rtx set;
    int fallthru = 0;
-   rtx barrier;
  
    /* Verify that all targets will be TARGET.  */
    for (tmp = src->succ; tmp; tmp = tmp->succ_next)
      if (tmp->dest != target && tmp != e)
        break;
!   if (tmp || GET_CODE (insn) != JUMP_INSN)
      return 0;
  
    /* Avoid removing branch with side effects.  */
--- 1626,1637 ----
    edge tmp;
    rtx set;
    int fallthru = 0;
  
    /* Verify that all targets will be TARGET.  */
    for (tmp = src->succ; tmp; tmp = tmp->succ_next)
      if (tmp->dest != target && tmp != e)
        break;
!   if (tmp || !onlyjump_p (insn))
      return 0;
  
    /* Avoid removing branch with side effects.  */
*************** try_redirect_by_replacing_jump (e, targe
*** 1665,1671 ****
  	fprintf (rtl_dump_file, "Removing jump %i.\n", INSN_UID (insn));
        flow_delete_insn (insn);
        fallthru = 1;
!       insn = src->end;
      }
    /* If this already is simplejump, redirect it.  */
    else if (simplejump_p (insn))
--- 1647,1657 ----
  	fprintf (rtl_dump_file, "Removing jump %i.\n", INSN_UID (insn));
        flow_delete_insn (insn);
        fallthru = 1;
! 
!       /* Selectivly unlink whole insn chain.  */
!       if (src->end != PREV_INSN (target->head))
! 	flow_delete_insn_chain (NEXT_INSN (src->end),
! 				PREV_INSN (target->head));
      }
    /* If this already is simplejump, redirect it.  */
    else if (simplejump_p (insn))
*************** try_redirect_by_replacing_jump (e, targe
*** 1681,1696 ****
    else
      {
        rtx target_label = block_label (target);
  
        src->end = PREV_INSN (insn);
        src->end = emit_jump_insn_after (gen_jump (target_label), src->end);
        JUMP_LABEL (src->end) = target_label;
        LABEL_NUSES (target_label)++;
        if (rtl_dump_file)
  	fprintf (rtl_dump_file, "Replacing insn %i by jump %i\n",
  		 INSN_UID (insn), INSN_UID (src->end));
        flow_delete_insn (insn);
!       insn = src->end;
      }
  
    /* Keep only one edge out and set proper flags.  */
--- 1667,1687 ----
    else
      {
        rtx target_label = block_label (target);
+       rtx barrier;
  
        src->end = PREV_INSN (insn);
        src->end = emit_jump_insn_after (gen_jump (target_label), src->end);
        JUMP_LABEL (src->end) = target_label;
        LABEL_NUSES (target_label)++;
+       if (basic_block_for_insn)
+ 	set_block_for_insn (src->end, src);
        if (rtl_dump_file)
  	fprintf (rtl_dump_file, "Replacing insn %i by jump %i\n",
  		 INSN_UID (insn), INSN_UID (src->end));
        flow_delete_insn (insn);
!       barrier = next_nonnote_insn (src->end);
!       if (!barrier || GET_CODE (barrier) != BARRIER)
! 	emit_barrier_after (src->end);
      }
  
    /* Keep only one edge out and set proper flags.  */
*************** try_redirect_by_replacing_jump (e, targe
*** 1704,1716 ****
    e->probability = REG_BR_PROB_BASE;
    e->count = src->count;
  
-   /* Fixup barriers.  */
-   barrier = next_nonnote_insn (insn);
-   if (fallthru && GET_CODE (barrier) == BARRIER)
-     flow_delete_insn (barrier), barrier = insn;
-   else if (!fallthru && GET_CODE (barrier) != BARRIER)
-     barrier = emit_barrier_after (insn);
- 
    /* In case we've zapped an conditional jump, we need to kill the cc0
       setter too if available.  */
  #ifdef HAVE_cc0
--- 1695,1700 ----
*************** try_redirect_by_replacing_jump (e, targe
*** 1725,1730 ****
--- 1709,1724 ----
      }
  #endif
  
+   /* We don't want a block to end on a line-number note since that has
+      the potential of changing the code between -g and not -g.  */
+   while (GET_CODE (e->src->end) == NOTE
+ 	 && NOTE_LINE_NUMBER (e->src->end) >= 0)
+     {
+       rtx prev = PREV_INSN (e->src->end);
+       flow_delete_insn (e->src->end);
+       e->src->end = prev;
+     }
+ 
    if (e->dest != target)
      redirect_edge_succ (e, target);
    return 1;


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