Patchwork RFA: MEP: Fix use of delete_insn.

login
register
mail settings
Submitter Nick Clifton
Date July 2, 2012, 7:20 a.m.
Message ID <4FF14BC5.9010003@redhat.com>
Download mbox | patch
Permalink /patch/168505/
State New
Headers show

Comments

Nick Clifton - July 2, 2012, 7:20 a.m.
Hi DJ,

> We have this at the top of the loop, so I don't think it matters:
>
> 	  next = NEXT_INSN (insn);
> 	  if (GET_CODE (insn) != INSN)
> 	    continue;

Good point.

> However, I think an insn will be skipped if we use NEXT.  Perhaps we
> want PREV?  Or the loop might need to be altered to account for this
> potential skipping.

Hmm, I think that just using the NEXT_INSN at the head of the loop 
should work.  As far as I can tell from looking at the code in 
mep_reorg_remove() we are never going to delete an insn that might 
involve removing more than one real insn, so we do not have to worry 
about side effects.  Hence I would suggest the following alternative patch.

OK to apply ?

Cheers
   Nick
DJ Delorie - July 2, 2012, 5:37 p.m.
My concern is more about calling NEXT_INSN on a deleted insn.  If
that's guaranteed to be "reliable", I'm OK with it.

Alternately, call NEXT_INSN at the top of the loop, but save the value
until the *next* iteration of the loop, so we can delete the insn and
not have to call NEXT_INSN on it after being deleted.

next_insn = get_insns ();
while (next_insn)
  {
    insn = next_insn;
    next_insn = NEXT_INSN (insn);
    . . .
  }

Of course, *that* assumes that we never delete more than just the one
"insn" we're processing.  In that case, though, we could still just
update next_insn so the next loop gets the right one.

So pick whichever solution is more future-proof and go for it :-)

Patch

Index: gcc/config/mep/mep.c
===================================================================
--- gcc/config/mep/mep.c	(revision 189108)
+++ gcc/config/mep/mep.c	(working copy)
@@ -5096,7 +5096,7 @@ 
  					       follow, where))
  		{
  		  count ++;
-		  next = delete_insn (insn);
+		  delete_insn (insn);
  		  if (dump_file)
  		    {
  		      fprintf (dump_file, "\n----- Success!  new insn:\n\n");