Bug in GCC 2.95.2

Bernd Schmidt bernds@balti.cygnus.co.uk
Tue Dec 14 05:07:00 GMT 1999


On Mon, 13 Dec 1999, Robert Ruehlmann wrote:

> When optimized with -O2 the following small sample program goes into an
> infinite loop.  Debugging with gdb shows strange behaviour like
> modifications of the 'size' variable.
> 
> <-- cut here -->
> static void bug(int size, int tries)
> {
>     int i;
>     int num = 0;
> 
>     while (num < size)
>     {
>         for (i = 1; i < tries; i++) num++;
>     }
> }
> 
> int main()
> {
>     bug(5, 10);
>     return 0;
> }
> <-- cut here -->

This is a bug in check_dbra_loop.  Both loops get reversed; this is OK for
the inner loop but not for the outer one, as we can't tell how often num
will be incremented (and thus we don't know whether the exit test, which is
an equality test against zero after reversing, will succeed).

There is already code in check_dbra_loop to verify that a biv that will be
reversed is only set once.  The patch below improves the test to also take
maybe_multiple into account.

Bernd

	* loop.c (check_dbra_loop): Can't reverse a biv for which
	maybe_multiple is set.

Index: loop.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/loop.c,v
retrieving revision 1.207
diff -c -p -r1.207 loop.c
*** loop.c	1999/12/12 18:38:14	1.207
--- loop.c	1999/12/14 13:01:14
*************** check_dbra_loop (loop_end, insn_count, l
*** 7937,7942 ****
--- 7953,7959 ----
    for (bl = loop_iv_list; bl; bl = bl->next)
      {
        if (bl->biv_count == 1
+ 	  && ! bl->biv->maybe_multiple
  	  && bl->biv->dest_reg == XEXP (comparison, 0)
  	  && ! reg_used_between_p (regno_reg_rtx[bl->regno], bl->biv->insn,
  				   first_compare))



More information about the Gcc-bugs mailing list