On 07/01/2015 03:04 AM, Chen Gang wrote:

For me, the more details are:

  - The insns have 2 loops which can be lsetup optimized.

  - After hwloop_optimize finishes 1st lsetup optimization, it generates
    new lsetup insn which appends to jump insn in the basic block (which
    causes the insns are not 'standard' but OK for code generation).

The problem is that you can't append anything to a basic block after a jump. You need to create a new one. This problem doesn't usually show up since nothing ever looks at the basic block again, unless both directions from the conditional branch happen to branch to lsetup candidate loops.

Below is a patch. Can you test this with anything you have beyond the testsuite?


Bernd

diff --git a/gcc/config/bfin/bfin.c b/gcc/config/bfin/bfin.c
index 8c1e18a..2c6f195 100644
--- a/gcc/config/bfin/bfin.c
+++ b/gcc/config/bfin/bfin.c
@@ -3796,8 +3796,19 @@ hwloop_optimize (hwloop_info loop)
 	{
 	  gcc_assert (JUMP_P (prev));
 	  prev = PREV_INSN (prev);
+	  emit_insn_after (seq, prev);
+	}
+      else
+	{
+	  emit_insn_after (seq, prev);
+	  BB_END (loop->incoming_src) = prev;
+	  basic_block new_bb = create_basic_block (seq, seq_end,
+						   loop->head->prev_bb);
+	  edge e = loop->incoming->last ();
+	  gcc_assert (e->flags & EDGE_FALLTHRU);
+	  redirect_edge_succ (e, new_bb);
+	  make_edge (new_bb, loop->head, 0);
 	}
-      emit_insn_after (seq, prev);
     }
   else
     {

Reply via email to