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]
Other format: [Raw text]

PATCH: mis-preconditioning while unrolling


I have a problem unrolling loops of this form:
   for (i=198; i>=0; i--)
Since the iteration count is not divisible by 2,3,5 or 7 this
is UNROLL_NAIVE, and precondition_loop_p is called.  This sets its
return values in a way that pretends the loop goes from 0 to 198 with
a positive increment, which is not accurate.  Presumably at one
point this was harmless, but it isn't now; the calling code in
unroll_loop gets into the case where it's trying to allow for overflow:
   for (i=0; --i<6; )
and consequently miscomputes the number of copies to move outside
the loop.  This patch changes precondition_loop_p so its return
values indicate a loop from N to 0 with negative increment in this
case.
The bootstrap-and-test isn't done yet, but does this look like the
right approach?  (I know, I need a ChangeLog entry too.)


Index: unroll.c
===================================================================
RCS file: /cvs/Darwin/Commands/GNU/gcc/gcc/unroll.c,v
diff -u -d -b -w -c -3 -p -r1.10 unroll.c
*** unroll.c    2001/12/29 21:59:30     1.10
--- unroll.c    2002/01/02 23:45:21
*************** precondition_loop_p (loop, initial_value
*** 1392,1400 ****
--- 1392,1409 ----

     if (loop_info->n_iterations > 0)
       {
+       if ( INTVAL (loop_info->increment) > 0)
+       {
           *initial_value = const0_rtx;
           *increment = const1_rtx;
           *final_value = GEN_INT (loop_info->n_iterations);
+       }
+       else
+       {
+         *initial_value = GEN_INT (loop_info->n_iterations);
+         *increment = constm1_rtx;
+         *final_value = const0_rtx;
+       }
         *mode = word_mode;

         if (loop_dump_stream)


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