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]

PATCH: problem with basic block reorder and reorg


Hello,

I had a problem with the new basic block reorder pass combined with reorg.
When I compile the next program:

typedef struct {
         int fd;
         unsigned char* buf;
         unsigned char* pos;
         unsigned char* buff_stop;
         unsigned int flags;
         int index;
} FILE;
int
ungetc(int _c, register FILE *_fp)
{
   if(_fp->fd == -1) return ((-1));
   if(_c == (-1) || (_fp->pos < _fp->buf)) return ((-1));
   if((((_fp)->flags) & (0x0040)))
   {
      (((_fp)->flags) &= ~(0x0020));
      (((_fp)->flags) |= (0x0010));
   }
   if(_fp->buf == 0 && !(((_fp)->flags) & (0x0004)))
      if(setvbuf(_fp, 0, (((_fp)->flags) & (0x0001 | 0x0002 | 0x0004)), 256) == (-1)) return ((-1));
   *(--_fp->pos) = (unsigned char)_c;
   (((_fp)->flags) |= (0x0800));
   (((_fp)->flags) &= ~(0x0200));
   if(!_fp->buff_stop) _fp->buff_stop = _fp->buf;
   return ((unsigned char)_c);
}

on the c4x target. The return insn at the end is missing. This happens
in the reorg pass. Here we check if there is a return insn at the end
of the code in the function find_end_label. If we can not find one we
try to insert a new one. This inserting fails because the return insn
on the c4x can only be used when under certain conditions.
The real return insn is moved by the new basic block reorder pass and is
not present at the end of the code anymore. I modified the reorg code
to search for the new location of the return insn.
I did check if this could happen on other targets. The conditions that
trigger this are:
- HAVE_return must be present and it must be conditional
- HAVE_epilogue must be present
- define_delay must be present
If I did this correctly then the c4x, mips, pa and sh have the same
conditions present. The code above only triggers the bug on the c4x.
Other test programs are probably needed to trigger this bug on the
other targets. 

	Herman.

--- reorg.c.org	Sun Sep  3 18:13:03 2000
+++ reorg.c	Sun Sep  3 18:12:45 2000
@@ -390,6 +390,28 @@ find_end_label ()
           if (num_delay_slots (insn) > 0)
 	    obstack_ptr_grow (&unfilled_slots_obstack, insn);
 	}
+      else
+	{
+	  /* If the basic block reorder pass moves the return insn to
+	     some other place try to locate it again and put our
+	     end_of_function_label there.  */
+	  while (insn && ! (GET_CODE (insn) == JUMP_INSN
+		            && (GET_CODE (PATTERN (insn)) == RETURN)))
+	    insn = PREV_INSN (insn);
+	  if (insn)
+	    {
+	      insn = PREV_INSN (insn);
+      	      end_of_function_label = gen_label_rtx ();
+      	      LABEL_NUSES (end_of_function_label) = 0;
+
+      	      /* Put the label before an USE insns that may proceed the
+		 RETURN insn.  */
+      	      while (GET_CODE (insn) == USE)
+		insn = PREV_INSN (insn);
+
+      	      emit_label_after (end_of_function_label, insn);
+	    }
+	}
 #endif
     }
 

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