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 for loop bug



Here is the patch which fixes the following 'C' program. Please let me 
know if it is okay to apply.


while.c

int main()
{
    int i = 1;
    int j = 0;

    while (i != 1024 || j <= 0) {
        i *= 2;
        ++ j;
    }

    if (j != 10)
     abort ();
 
    exit (0);
}

I have added this testcase to gcc testsuite - gcc.c-torture/execute/20000711-1.c 

ChangeLog

	* loop.c (check_dbra_loop): Check if more than one condition
 	controls the loop.
	 

Index: loop.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/loop.c,v
retrieving revision 1.256
diff -p -r1.256 loop.c
*** loop.c      2000/06/14 07:41:57     1.256
--- loop.c      2000/07/11 19:01:41
*************** check_dbra_loop (loop, insn_count)
*** 7795,7800 ****
--- 7795,7811 ----
    else
      return 0;
  
+   {
+     /* If more than one condition is present to control the loop, then
+        do not procceed as the this function makes decision on the
+        condition (JUMP_INSN) present just before NOTE_INSN_LOOP_END. */
+ 
+     rtx jump1;
+     if ((jump1 = prev_nonnote_insn (jump)) != loop_continue)
+       if (GET_CODE (jump1) == JUMP_INSN))
+         return 0;
+   }
+ 
    /* Check all of the bivs to see if the compare uses one of them.
       Skip biv's set more than once because we can't guarantee that
       it will be zero on the last iteration.  Also skip if the biv is



Just to update you, the program while.c was failing because 
check_dbra_loop was only considering j <= 0 condition while 
making the decision to reverse the loop. 

I have added code to check if there are any other conditions (JUMP_INSN) in 
between 

(note 37 103 86 "" NOTE_INSN_LOOP_CONT)

and 


(note 43 109 112 "" NOTE_INSN_LOOP_END)

and if more than one jump insn is found then i don't do anything here, 
just return 0. 

Please let me know it is okay to apply.

Thanks
Chandra



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